question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mixed float32/float64 TriMesh data issues

See original GitHub issue

Hey,

first i want to thank you for your work!

Description

I currently trying to get a TriMesh project ready. My data is described in a different way, the mesh should look like but i get this working for now. My problem is, that for my data, the actual value of a cell (triangle) is the value of the cell and not of one node. I found, i could set the values in the array of the vertices but for me it depends on the triangle. Is this possible?

Data

My data is structured like follows:

<xarray.Dataset>
Dimensions:      (bnds: 2, height: 90, ncells: 327680, time: 1, vertices: 3)
Coordinates:
  * height       (height) float64 1.0 2.0 3.0 4.0 5.0 ... 87.0 88.0 89.0 90.0
  * time         (time) float64 2.016e+07
Dimensions without coordinates: bnds, ncells, vertices
Data variables:
    clon         (ncells) float64 1.257 0.877 1.257 ... 0.005273 0.003057
    clon_bnds    (ncells, vertices) float64 -2.708 0.6283 ... 0.007998 8.474e-15
    clat         (ncells) float64 1.566 1.559 1.563 ... -0.4698 -0.4701 -0.4674
    clat_bnds    (ncells, vertices) float64 1.571 1.563 1.563 ... -0.466 -0.4636
    height_bnds  (height, bnds) float64 ...
    TR_stn       (time, height, ncells) float32 ...
    TR_stt       (time, height, ncells) float32 ...
    TR_sts       (time, height, ncells) float32 ...
    TR_trn       (time, height, ncells) float32 ...
    TR_trt       (time, height, ncells) float32 ...
    pv           (time, height, ncells) float32 ...
Attributes:
    CDI:                  Climate Data Interface version 1.7.2 (http://mpimet...
    Conventions:          CF-1.4

Where 327680 is the number of cells.

Code

xrData = xr.open_dataset("/home/max/Downloads/2016033000-ART-passive_grid_pmn_DOM01_ML_0002.nc",decode_cf=False)

pts = np.column_stack((xrData.clon,xrData.clat,xrData.isel(height=0,time=0).TR_stn))
print(pts)

verts = np.column_stack((xrData.clon_bnds.stack(z=('vertices','ncells')),xrData.clat_bnds.stack(z=('vertices','ncells'))))
#verts = np.append(verts,[0,0])
print(verts.shape)
n1 = []
n2 = []
n3 = []

l = len(xrData.clon_bnds)
for i in range(0,l):
    n1.append([i])
    n2.append([i+l])
    n3.append([i+l+l])
    
n = np.column_stack((n1,n2,n3,xrData.isel(height=0,time=0).TR_stn))

verts = pd.DataFrame(verts,  columns=['x', 'y'])
tris  = pd.DataFrame(n, columns=['v0', 'v1', 'v2','TR_stn'])

print('vertices:', len(verts), 'triangles:', len(tris))

mesh = du.mesh(verts,tris)
cvs = ds.Canvas(plot_height=900, plot_width=900)
%time agg = cvs.trimesh(verts, tris, mesh=mesh)
#tf.Image(tf.shade(agg))
datashade(hv.TriMesh((tris,verts), vdims=["TR_stn"], label="Wireframe").options(filled=True))

Errors and warnings

I get the following output:

 [ 0.87695428  1.55913341  0.04311323]
 [ 1.25663706  1.5627978   0.04319941]
 ...
 [ 0.01106288 -0.46984588  0.00162048]
 [ 0.00527347 -0.47011298  0.00165073]
 [ 0.00305715 -0.46740222  0.00163877]]
(983040, 2)
vertices: 983040 triangles: 327680

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-61-90e80b7ef202> in <module>()
     22 print('vertices:', len(verts), 'triangles:', len(tris))
     23 
---> 24 mesh = du.mesh(verts,tris)
     25 cvs = ds.Canvas(plot_height=900, plot_width=900)
     26 get_ipython().run_line_magic('time', 'agg = cvs.trimesh(verts, tris, mesh=mesh)')

/usr/local/lib/python3.5/dist-packages/datashader/utils.py in mesh(vertices, simplices)
    462         lambda dt: np.issubdtype(dt, np.integer)
    463     ).all()
--> 464     assert simplices_all_ints, ('Simplices must be integral. You may '
    465                                 'consider casting simplices to integers '
    466                                 'with ".astype(int)"')

AssertionError: Simplices must be integral. You may consider casting simplices to integers with ".astype(int)"

Version Environment

max@sam ~/g/praktClimaAnalyse (master)> python3 --version
Python 3.5.2
max@sam ~/g/praktClimaAnalyse (master)> jupyter --version
4.4.0
max@sam ~/g/praktClimaAnalyse (master)> datashader --version
datashader 0.6.8
max@sam ~/g/praktClimaAnalyse (master)> firefox --version
Mozilla Firefox 64.0
max@sam ~/g/praktClimaAnalyse (master)> uname -a
Linux sam 4.15.0-42-generic #45~16.04.1-Ubuntu SMP Mon Nov 19 13:02:27 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
max@sam ~/g/praktClimaAnalyse (master)> 

Thanks! And best regards, Max

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
d70-tcommented, Jul 29, 2021

Thank you very much for the feedback! I just didn’t try the obvious. It is indeed possible to add the cell-values to the dataframe containing node indices and it seems to just do the right thing.

1reaction
jbednarcommented, Jul 28, 2021

PRs welcome! 😃 Just to be clear, here I think the issue is to deal with mixed float32/float64 datatypes properly, and in the meantime converting them all to float32 would presumably work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

trimesh 3.17.1 documentation
Copied objects will have emptied caches to avoid memory issues and so may be slow ... model in the scene, and raise a...
Read more >
trimesh.base — trimesh 3.17.1 documentation
A Trimesh object contains a triangular 3D mesh. Parameters. vertices ((n, 3) float) – Array of vertex locations. faces ((m, 3) ...
Read more >
trimesh.exchange.load — trimesh 3.17.1 documentation
trimesh.exchange.load · file_obj (open file-like object) – Containing compressed data · file_type (str) – Type of the archive file · mixed...
Read more >
trimesh.repair — trimesh 3.17.1 documentation
Fill holes and fix winding and normals of meshes. trimesh.repair.broken_faces(mesh, color=None) . Return the index of faces in the mesh which break...
Read more >
trimesh.geometry — trimesh 3.17.1 documentation
A data vector can be passed which is then used instead of booleans ... them as triangle faces, also handles pure triangles and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found