-
Notifications
You must be signed in to change notification settings - Fork 229
Allow passing region to GMTBackendEntrypoint.open_dataset #3932
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
base: main
Are you sure you want to change the base?
Conversation
Support passing in a region as a Sequence [xmin, xmax, ymin, ymax] or ISO country code to `xarray.open_dataset` when using `engine="gmt"`.
Remove duplicated code calling GMT read, since `xr.load_dataarray(engine="gmt")` now works with region argument.
Ensure that passing engine='gmt' to xarray.open_dataarray works for opening GeoTIFF | ||
images. | ||
Ensure that passing engine='gmt' to xarray.open_dataarray works to open a GeoTIFF | ||
image. | ||
""" | ||
with xr.open_dataarray("@earth_day_01d", engine="gmt", raster_kind="image") as da: | ||
assert da.sizes == {"band": 3, "y": 180, "x": 360} |
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.
Coordinate names are y
/x
when region=None
, but lat
/lon
when region is not None
at L90 below. Need to fix this inconsistency.
# The source grid file is undefined for tiled grids. | ||
assert grid.encoding.get("source") is None |
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.
Should we keep grid.encoding["source"]
as undefined/None for tiled grids (xref #3673 (comment))? Or select the first tile (e.g. S90E000.earth_relief_05m_p.nc
)? May need to update this test depending on what we decide.
source: str | list = which(fname=filename_or_obj) | ||
raster.encoding["source"] = ( | ||
source[0] if isinstance(source, list) else source | ||
) |
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.
Do we actually need the _ = raster.gmt
line at L124 to load GMTDataArray accessor info, since lib.virtualfile_to_raster
already calls self.read_virtualfile(vfname, kind=kind).contents.to_xarray()
which sets the registration and gtype based on the header?
Lines 197 to 201 in 74de7d8
# Set GMT accessors. | |
# Must put at the end, otherwise info gets lost after certain grid operations. | |
grid.gmt.registration = header.registration | |
grid.gmt.gtype = header.gtype | |
return grid |
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.
that's a good point. please try remove it and see if everything works fine.
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.
There is one extra test failure at https://github.com/GenericMappingTools/pygmt/actions/runs/14743641047/job/41386753150#step:10:1049:
_____________ [doctest] pygmt.xarray.accessor.GMTDataArrayAccessor _____________
026 Examples
027 --------
028 For GMT's built-in remote datasets, these GMT-specific properties are automatically
029 determined and you can access them as follows:
030
031 >>> from pygmt.datasets import load_earth_relief
032 >>> # Use the global Earth relief grid with 1 degree spacing
033 >>> grid = load_earth_relief(resolution="01d", registration="pixel")
034 >>> # See if grid uses Gridline or Pixel registration
035 >>> grid.gmt.registration
Expected:
<GridRegistration.PIXEL: 1>
Got:
1
I think this might be because the _GMT_GRID_HEADER.registration property returns an int
instead of an enum?
pygmt/pygmt/datatypes/header.py
Lines 81 to 82 in d29303b
# Grid registration, 0 for gridline and 1 for pixel | |
("registration", ctp.c_uint32), |
and we overrode grid.gmt.registration
with 1
instead of <GridRegistration.PIXEL: 1>
. Should be a quick fix we can do in a separate PR. Edit: no, the GMTDataArrayAccessor registration property should always return an enum, not an int, something else in this PR seems to be affecting this doctest...
GMTDataArrayAccessor info should already be loaded by calling`virtualfile_to_raster` which calls `self.read_virtualfile(vfname, kind=kind).contents.to_xarray()` that sets registration and gtype from the header.
Description of proposed changes
Support passing in a region as a Sequence [xmin, xmax, ymin, ymax] or ISO country code to
xarray.open_dataset
when usingengine="gmt"
.Usage:
This PR also refactors the internals of
_load_remote_dataset
to usexr.load_dataarray(engine="gmt", ...)
instead of low-level calls to clib functions.Extends #3919, adapted from #3673
Preview:
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.Slash Commands
You can write slash commands (
/command
) in the first line of a comment to performspecific operations. Supported slash command is:
/format
: automatically format and lint the code