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.

leverage cf_xarray to get x_coords (lon) and y_coords (lat)?

See original GitHub issue

Currently - 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:open
  • Created a year ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
aaronspringcommented, Aug 9, 2022

I like the general idea and the mask(ds, use_cf=bool) implementation

0reactions
jbuseckecommented, Aug 23, 2022

I 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.

Read more comments on GitHub >

github_iconTop 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 >

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