-
Notifications
You must be signed in to change notification settings - Fork 391
Create projections from CF attributes #2548
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
base: main
Are you sure you want to change the base?
Conversation
<!-- Please ensure the PR fulfills the following requirements! -->
<!-- If this is your first PR, make sure to add your details to the
AUTHORS.rst! -->
### Pull Request Checklist:
- [ ] This PR addresses an already opened issue (for bug fixes /
features)
- This PR fixes #xyz
- [x] (If applicable) Documentation has been added / updated (for bug
fixes / features).
- [x] (If applicable) Tests have been added.
- [x] This PR does not seem to break the templates.
- [x] CHANGELOG.rst has been updated (with summary of main changes).
- [x] Link to issue (:issue:`number`) and pull request (:pull:`number`)
has been added.
### What kind of change does this PR introduce?
Two new functions in `xs.spatial`
* `rotate_vectors` to rotate vectors from their native grid axes to
actual S-N W-E axes. Mostly useful for wind that comes out of some
models. Can also do the opposite rotation.
* `get_crs` to get a cartopy crs from a grid mapping variable. This is
only temporary, waiting for my PR in cartopy: SciTools/cartopy#2548.
### Does this PR introduce a breaking change?
No.
### Other information:
@aslibese fyi
|
Hi all. I don't know who to tag. @dopplershift a while ago, you answered to my issue (#2099) that we should look towards I used the CF conventions and associated document to implement this, sometimes looking a |
This fixes #2099.
Rationale
As detailed in #2099, the
from_cfclass method inherited frompyprojdoes not work with cartopy as it creates apyprojclass, and not the cartopy class it was called from.The following was the closest I could get:
However, as
p.bounds is Nonehere, plotting with matplotlib fails if you pass this as the projection of the axes.Thus, I thought it would be useful to be able to create the exact cartopy projection needed from a set of CF convention attributes.
Implications
The only "breaking" change here is that calling
from_cfon a projection that does not map to a CF grid mapping will fail with aNotImplementedErrorinstead of returning apyprojobject. But that behaviour was already broken I would say.This PR exposes
cartopy.crs.from_cfthat takes in all attributes of the grid mapping variable. It uses a lookup dict to map from the CFgrid_mapping_nameto cartopy's Projection and calls that projection'sfrom_cfconstructor.The PR does not try to validate CF attributes, except that it will raise a
KeyErrorif an attribute that the conventions does not flag as optional is missing. The mappings of grid mapping names and attributes is based on the description from the conventions themselves and on this (old) note from the CF conventions wiki.Checklist
Tests added (minimal)
I did sign the CLA.