leverage cf_xarray to get x_coords (lon) and y_coords (lat)?
See original GitHub issueCurrently - if the coordinates are not named "lat"
and "lon"
we need to pass them manually, e.g.:
import regionmask
import xarray as xr
rasm = xr.tutorial.load_dataset("rasm")
regionmask.defined_regions.srex.mask(rasm.xc, rasm.yc)
cf_xarray uses attrs
to determine cf compliant “coordinates” - irrespective of their name. We could use this to allow
import cf_xarray # require manual import?
regionmask.defined_regions.srex.mask(rasm)
by using
x_coords = data.cf["longitude"]
y_coords = data.cf["latitude"]
internally.
@jbusecke @aaronspring that may be of interest of you.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Introduction to cf_xarray - CF Xarray - Read the Docs
This synthetic dataset has multiple X and Y coords. An example would be model output on a staggered grid. from cf_xarray.datasets import multiple...
Read more >How to identify time, lon, and lat coordinates in xarray?
This is done internally by parsing the coordinate metadata according to the CF conventions. Here's a short example: import xarray as xr ...
Read more >xarray.Dataset.assign_coords
Assign new coordinates to this object. Returns a new object with all the original data in addition to the new coordinates. Parameters. coords...
Read more >cf-xarray: Scale your analysis across datasets with less data ...
Xarray (Hoyer et al, 2021) is a Python package that enables easy and convenient labelled data analytics by allowing users to leverage metadata...
Read more >Gridded Data — hvPlot 0.8.2 documentation
This user guide will cover how to leverage xarray and hvplot to visualize and ... <xarray.Dataset> Dimensions: (lat: 25, time: 2920, lon: 53)...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I like the general idea and the
mask(ds, use_cf=bool)
implementationI like this general idea a lot. I would always raise a warning in the case of potential ambiguity (this might be done by catching errors from cf_xarray or some logic in regionmask itself). This would mean that in simple cases “the magic just works” and if there are options to consider, the user is warned. To me that seems ideal.