-
Notifications
You must be signed in to change notification settings - Fork 41
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
add cf.grid_mapping_names
#391
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing @larsbuntemeyer
This is looking good to me. I have a few requests:
- Please add a new page to the docs titled "Grid Mappings"
- Please add to
api.rst
- Please add tests
- Should we add a specific
DataArray
property that's more narrow? It seems like it could work since Xarray propagates scalars with all DataArrays when extracted. - That reminds me, we should update
get_associated_variables
too and check thatgrid_mapping
information is propagated withds.cf["temp"]
(3), (4) could happen in a separate PR if you prefer.
The tests failues can be fixed by updating the "expected" repr
@jthielen do you have any thoughts on this API, and/or suggestions for API additions that would be useful. |
Great, thanks! I'll start polishing!
Yes, that would be great. I saw that in
I'll add tests here... |
Seems like we should add |
Yes, that would be nice!
Should i add them in this PR? |
Sure. I think @jthielen may have commented earlier about not adding these, but I can't find it now. |
maybe #23 is related. |
Thanks that's right. I think adding to This is quite minor though, |
I just recognized that this would clutter the repr a little bit, e.g.,
should this be done in another PR and maybe with an html repr that deals with it? |
I changed it so that:
I enabled the In the future, we might think about adding a custom Please try it out with your code and see if you like it. |
Thanks a lot, that's really awesome and makes sense to me, will be really useful for working with CORDEX data! I did some minor updates for the docs! |
I guess, the error is caused by the CF tables being updated just yesterday! |
Thanks @larsbuntemeyer this is great!
If you ever write a demo notebook showcasing this, it would be good to link to it in our docs. That would be a valuable community contribution! |
* upstream/main: add `cf.grid_mapping_names` (xarray-contrib#391) Update CF standard name table v80 (xarray-contrib#423)
Absolutely! Thanks for the support! |
* main: Add rich repr (xarray-contrib#409) add `cf.grid_mapping_names` (xarray-contrib#391) Update CF standard name table v80 (xarray-contrib#423)
* main: (33 commits) Update README.rst Update README.rst v0.8.0 release (xarray-contrib#424) Add sgrid axes parsing (xarray-contrib#421) Add rich repr (xarray-contrib#409) add `cf.grid_mapping_names` (xarray-contrib#391) Update CF standard name table v80 (xarray-contrib#423) Support grid_topology, mesh_topology CF roles. (xarray-contrib#420) added degrees units (xarray-contrib#390) Test and support 3.11 (xarray-contrib#417) Update link to COSIMA tutorial (xarray-contrib#419) Bump mamba-org/provision-with-micromamba from 14 to 15 (xarray-contrib#418) Update whats-new.rst (xarray-contrib#414) [skip-ci] Include data folder (xarray-contrib#416) Update changelog URL updated whats new for release (xarray-contrib#413) Using regex package for match (xarray-contrib#408) Try pytest-pretty (xarray-contrib#410) Update CITATION.cff (xarray-contrib#399) Fix upstream-dev CI (xarray-contrib#406) ...
I wanted to pick up the discussion from #370 of making
cf-xarray
understand thegrid_mapping
attribute. This alone (without the further interpretation bypyproj
) would be really useful to RCM datasets (you never know if the mapping is calledrotated_pole
,rotated_latitude_longitude
or whatever...).The implementation is straight forward, the logic in the CF conventions mainly follows the bounds logic. A data variable can have a
grid_mapping
attribute that points to another data variable containing thegrid_mapping_name
attribute. As far as i know, the name of the variable holding thegrid_mapping_name
attribute might be arbitrary. Actually, it's a lot of code copied from thebounds
logic, which i should optimize, sorry... Just wanted to throw this in quickly, let me know if it's useful...cf.grid_mappings
update _COORD_NAMES and _AXIS_NAMESHere's an example:
and...
access it:
get name of the mapping (might be different to the data variable name):