Uh oh!
There was an error while loading. Please reload this page.
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.
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
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.