-
Notifications
You must be signed in to change notification settings - Fork 224
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
load_tile_map: Register the rio accessor by importing rioxarray so the returned raster has CRS #3323
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 <23487320+weiji14@users.noreply.github.com>
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
41a660b
to
9ecc39d
Compare
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
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
rio
accessor 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_map
alone may have CRS set or not, depending on if a script importsrioxarray
or not elsewhere.This PR fixes the issue by importing the rioxarray package in
pygmt/datasets/tile_map.py
so that therio
accessor is always registered when rioxarray is installed.