Skip to content
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

Merged
merged 8 commits into from
Jul 10, 2024

Conversation

seisman
Copy link
Member

@seisman seisman commented Jul 10, 2024

Description of proposed changes

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

import rioxarray # 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.

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

@weiji14 weiji14 left a 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.

pygmt/datasets/tile_map.py Outdated Show resolved Hide resolved
pygmt/datasets/tile_map.py Outdated Show resolved Hide resolved
seisman and 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>
@seisman seisman force-pushed the tilemap/rioxarray branch from 41a660b to 9ecc39d Compare July 10, 2024 03:32
pygmt/datasets/tile_map.py Outdated Show resolved Hide resolved
pygmt/datasets/tile_map.py Outdated Show resolved Hide resolved
seisman and 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
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 main Jul 10, 2024
19 checks passed
@seisman seisman deleted the tilemap/rioxarray branch July 10, 2024 06:06
@seisman seisman 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 free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants