NOAA-ORR-ERD / gridded

A single API for accessing / working with gridded model results on multiple grid types
https://noaa-orr-erd.github.io/gridded/index.html
The Unlicense
66 stars 14 forks source link

Ugrid support for combined 3 and 4 vertices per face in single grid? #22

Closed mattijn closed 6 years ago

mattijn commented 6 years ago

We are using gridded to access the data, faces and nodes from unstructured grids.

This works very well for UGrids with 3 vertices per face and also for UGrids where the faces contain 4 vertices. Even for plotting (https://stackoverflow.com/a/49651967/2459096).

But now we have some netCDF files where the faces contains both 3 and 4 vertices in a single UGrid.

After reading the netCDF file, the ds.grid.info states that the UGrid has 4 vertices per face.

Before deeper investigation we were wondering if gridded (pyugrid) provide support for netCDF files where the faces in the UGrid contain a varying number of vertices?

jay-hennen commented 6 years ago

After reviewing the APIs quickly, your situation would likely have limited support:

Should be possible to: Directly construct and use a Grid_U object with nodes and faces as you specified. Use the 'Grid_U.locate_faces' function to compute cell index of specified points (caveat: your faces array must have a -1 in place at any missing vertices)

I wouldn't bet on much past that. If you're using Variable, interpolation, or the IO related features of gridded they will very likely not work at all, or the furthest you get will be object construction and direct attribute access.

Hope all that helped. -JAH

mattijn commented 6 years ago

Thanks for your prompt response. I was wondering what you mean with

caveat: your faces array must have a -1 in place at any missing vertices

For the quads faces it contains 4 vertices, and for the triangles it contains 3 vertices and a -1 value as the missing vertice so all faces has in total 4 vertices?

EDIT At ugrid-convention : 2D flexible mesh, I see the following line:

The use of _FillValue to indicate faces with less nodes than MaxNumNodesPerFace extends to the coordinate bounds variables; this is an extension of the current convention.

That would support what you mention as the caveat, where the _FillValue is then -1 (on the netCDF-convention page they use a _FillValue of 999999).

jay-hennen commented 6 years ago

Yes, that's correct.

mattijn commented 6 years ago

OK, thanks again! Will report back here if we succeed in accessing the information using gridded

mattijn commented 6 years ago

In our case it were -999 values. Filtering these, and we can at least visualize the flexible mesh, thats enough for now vh

ChrisBarker-NOAA commented 6 years ago

hmm, I think gridded should tranlate those -999 values to -1 when we read the file -- if the _FillValue attribute is set, anyway.

ChrisBarker-NOAA commented 6 years ago

made an issue to improve this: #23