-
Notifications
You must be signed in to change notification settings - Fork 234
load_tile_map: Register the rio accessor by importing rioxarray so the returned raster has CRS #3323
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
Conversation
…e returned raster has CRS
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.
Have manually triggered the doctests CI for this branch (which has rioxarray installed) at https://github.com/GenericMappingTools/pygmt/actions/runs/9867651036/job/27248357251, looks ok, but a couple of suggestions.
Co-authored-by: Wei Ji <[email protected]>
Co-authored-by: Wei Ji <[email protected]>
41a660b to
9ecc39d
Compare
Co-authored-by: Wei Ji <[email protected]>
| spatial_ref int64 ... 0 | ||
| >>> # CRS is set only if rioxarray is available | ||
| >>> if hasattr(raster, "rio"): | ||
| ... raster.rio.crs |
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.
To be honest, we probably don't need the if hasattr(raster, "rio") check, because the spatial_ref int64 ... 0 line above (added in #3321) already means that rioxarray is used (the doctests CI run with rioxarray installed). But I guess it'll be good to mention rioxarray somewhere in the docstring, albeit indirectly.
Description of proposed changes
The
rioaccessor is only registered when rioxarray is imported. Currently, we import rioxarray inFigure.tilemap(pygmt/pygmt/src/tilemap.py
Line 12 in 3a32169
load_tile_map. Thus, the raster returned byload_tile_mapalone may have CRS set or not, depending on if a script importsrioxarrayor not elsewhere.This PR fixes the issue by importing the rioxarray package in
pygmt/datasets/tile_map.pyso that therioaccessor is always registered when rioxarray is installed.