Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading UGRID-compliant NetCDF files #326

Open
rsignell-usgs opened this issue Nov 14, 2020 · 12 comments
Open

Reading UGRID-compliant NetCDF files #326

rsignell-usgs opened this issue Nov 14, 2020 · 12 comments

Comments

@rsignell-usgs
Copy link

rsignell-usgs commented Nov 14, 2020

It would be great if the earthsim.io module could read UGRID-compliant NetCDF files. UGRID adds onto the CF-Conventions to provide an unambiguous way of reading topology and variable locations on the mesh from an unstructured mesh NetCDF file.

An example triangular mesh dataset is here:

import xarray as xr
url = 'http://www.smast.umassd.edu:8080/thredds/dodsC/FVCOM/NECOFS/Forecasts/NECOFS_GOM3_FORECAST.nc'
ds = xr.open_dataset(url,drop_variables='siglay')
@jbednar
Copy link
Contributor

jbednar commented Nov 14, 2020

To make sure it's clear, EarthSim shouldn't include any code for reading files or pretty much anything else; it's almost entirely a collection of examples. It originally did have lots of code, but nearly all of that code has migrated into generic OSS libraries as planned, with the remainder expected to migrate out whenever we get a chance to do so. We try our hardest not to write anything deeply domain specific except for examples!

Here, we'd be happy for EarthSim to include examples of reading UGRID NetCDF files via xarray, but are you asking for something beyond an example? E.g. extracting more of the metadata and making use of it better? If so I'd expect such changes to go into xarray or maybe GeoViews, not EarthSim.

@rsignell-usgs
Copy link
Author

@jbednar, I was looking at the visualizing meshes notebook and saw that it contains:

from earthsim.io import read_3dm_mesh, read_mesh2d

@jbednar
Copy link
Contributor

jbednar commented Nov 14, 2020

D'oh! Any suggestions on where that code and any UGRID-supporting reading code should go in the long term?

@rsignell-usgs
Copy link
Author

Maybe in https://github.com/xarray-contrib, where we already have https://github.com/xarray-contrib/cf-xarray?
What thinkest thou, @dcherian?

@dcherian
Copy link

tris, verts = read_3dm_mesh(fpath)

IIUC, you want to replace this line with a function that would parse the UGRID metadata and generate tris, verts? If so, we could add that to cf-xarray. It would mirror the helper functions for converting edges to vertices that were merged recently (xarray-contrib/cf-xarray#108)

@rsignell-usgs
Copy link
Author

rsignell-usgs commented Nov 16, 2020

@ocefpaf, we already have something simple that will return tris, verts from a CF-compliant UGRID, don't we?
The goal would be to simplify (and standardize) notebooks like: https://gallery.pangeo.io/repos/rsignell-usgs/esip-gallery/01_hurricane_ike_water_levels.html

@ocefpaf
Copy link

ocefpaf commented Nov 16, 2020

@dcherian I agree that this would be an awesome addition to cf-xarray. This is what I wrote some time ago, it is virtually the UGRID spec as code. I think you can adapt that to cf-xarray without many problems, either using the same variable search "get_var_by" or a more modern approach. (I do not recommend depending on that code though! It was not meant to be a library.)

@jbednar
Copy link
Contributor

jbednar commented Nov 16, 2020

Sounds great! Just to be clear, by "not depending on that code", do you just mean not importing from its current location in pyoceans/gridgeo/blob/master/gridgeo/ugrid.py? It sounds like you don't think it's in bad shape otherwise, and that once it's been moved to cf-xarray and cleaned up slightly it would be fine to depend on?

@ocefpaf
Copy link

ocefpaf commented Nov 16, 2020

Sounds great! Just to be clear, by "not depending on that code", do you just mean not importing from its current location in pyoceans/gridgeo/blob/master/gridgeo/ugrid.py? It sounds like you don't think it's in bad shape otherwise, and that once it's been moved to cf-xarray and cleaned up slightly it would be fine to depend on?

Yep. Don't import that code from that library. The UGRID implementation/logic in there is solid.

@jbednar
Copy link
Contributor

jbednar commented Nov 16, 2020

Sounds great! I'd love for there to be an example at EarthSim using such an implementation, imported from somewhere appropriate. Rich, if the code does get published properly in that way, then I'd be happy to help adapt one of our current examples to use it or to take a new example and add it to EarthSim.

Do you think this UGRID support should replace the 3dm stuff, or should I keep looking for a place to put the earthsim.io readers in the long term?

@ocefpaf
Copy link

ocefpaf commented Nov 16, 2020

Do you think this UGRID support should replace the 3dm stuff, or should I keep looking for a place to put the earthsim.io readers in the long term?

Not really replace but the 3DM output should ideally be UGRID compliant so standard tools can easily read it. That is the AdH model output, right? I recall helping some folks reading that as UGRID some years ago. Not sure if that effort evolved into code somewhere.


Edit: found it! See cell [5] in https://nbviewer.jupyter.org/gist/ocefpaf/933da65c3e3faa0a2ff9c0838f60a3b0

@dcherian
Copy link

Also see pydata/xarray#4222

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants