Skip to content

load_tile_map: Register the rio accessor by importing rioxarray so the returned raster has CRS - #3323

Merged
seisman merged 8 commits into
mainfrom
tilemap/rioxarray
Jul 10, 2024
Merged

load_tile_map: Register the rio accessor by importing rioxarray so the returned raster has CRS#3323
seisman merged 8 commits into
mainfrom
tilemap/rioxarray

Conversation

@seisman

Copy link
Copy Markdown
Member

Description of proposed changes

The rio accessor is only registered when rioxarray is imported. Currently, we import rioxarray in Figure.tilemap (

importrioxarray# noqa: F401
) but don't do it in load_tile_map. Thus, the raster returned by load_tile_map alone may have CRS set or not, depending on if a script imports rioxarray or not elsewhere.

This PR fixes the issue by importing the rioxarray package in pygmt/datasets/tile_map.py so that the rio accessor is always registered when rioxarray is installed.

@seismanseisman added bug Something isn't working needs review This PR has higher priority and needs review. labels Jul 10, 2024
@seismanseisman added this to the 0.13.0 milestone Jul 10, 2024

@weiji14weiji14 left a comment

Copy link
Copy Markdown
Member

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.

Comment threadpygmt/datasets/tile_map.py Outdated
Comment threadpygmt/datasets/tile_map.py Outdated
seismanand others added 4 commits July 10, 2024 11:25
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
Comment threadpygmt/datasets/tile_map.py Outdated
Comment threadpygmt/datasets/tile_map.py Outdated
seismanand others added 2 commits July 10, 2024 12:16
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
Comment on lines 124 to +127
spatial_ref int64 ... 0
>>> # CRS is set only if rioxarray is available
>>> if hasattr(raster, "rio"):
... raster.rio.crs

Copy link
Copy Markdown
Member

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.

@seisman
seisman merged commit 97a6f30 into mainJul 10, 2024
@seisman
seisman deleted the tilemap/rioxarray branch July 10, 2024 06:06
@seismanseisman removed the needs review This PR has higher priority and needs review. label Jul 10, 2024
weiji14 added a commit that referenced this pull request Sep 30, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@seisman@weiji14