Skip to content

Commit 6a4e1a4

Browse files
committed
Rename decode_kind to raster_kind
1 parent 31d1999 commit 6a4e1a4

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

pygmt/tests/test_xarray_backend.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_xarray_backend_gmt_open_nc_grid():
1818
grids.
1919
"""
2020
with xr.open_dataarray(
21-
"@static_earth_relief.nc", engine="gmt", decode_kind="grid"
21+
"@static_earth_relief.nc", engine="gmt", raster_kind="grid"
2222
) as da:
2323
assert da.sizes == {"lat": 14, "lon": 8}
2424
assert da.dtype == "float32"
@@ -31,7 +31,7 @@ def test_xarray_backend_gmt_open_tif_image():
3131
Ensure that passing engine='gmt' to xarray.open_dataarray works for opening GeoTIFF
3232
images.
3333
"""
34-
with xr.open_dataarray("@earth_day_01d", engine="gmt", decode_kind="image") as da:
34+
with xr.open_dataarray("@earth_day_01d", engine="gmt", raster_kind="image") as da:
3535
assert da.sizes == {"band": 3, "y": 180, "x": 360}
3636
assert da.dtype == "uint8"
3737
assert da.gmt.registration == GridRegistration.PIXEL
@@ -44,7 +44,7 @@ def test_xarray_backend_gmt_load_grd_grid():
4444
grids.
4545
"""
4646
da = xr.load_dataarray(
47-
"@earth_relief_20m_holes.grd", engine="gmt", decode_kind="grid"
47+
"@earth_relief_20m_holes.grd", engine="gmt", raster_kind="grid"
4848
)
4949
# Ensure data is in memory.
5050
assert isinstance(da.data, np.ndarray)
@@ -58,17 +58,17 @@ def test_xarray_backend_gmt_load_grd_grid():
5858
def test_xarray_backend_gmt_read_invalid_kind():
5959
"""
6060
Check that xarray.open_dataarray(..., engine="gmt") fails with missing or incorrect
61-
'decode_kind'.
61+
'raster_kind'.
6262
"""
6363
with pytest.raises(
6464
TypeError,
6565
match=re.escape(
66-
"GMTBackendEntrypoint.open_dataset() missing 1 required keyword-only argument: 'decode_kind'"
66+
"GMTBackendEntrypoint.open_dataset() missing 1 required keyword-only argument: 'raster_kind'"
6767
),
6868
):
6969
xr.open_dataarray("nokind.nc", engine="gmt")
7070

7171
with pytest.raises(GMTInvalidInput):
7272
xr.open_dataarray(
73-
filename_or_obj="invalid.tif", engine="gmt", decode_kind="invalid"
73+
filename_or_obj="invalid.tif", engine="gmt", raster_kind="invalid"
7474
)

pygmt/xarray_backend.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ class GMTBackendEntrypoint(BackendEntrypoint):
2222
and other raster formats.
2323
2424
When using :py:func:`xarray.open_dataarray` or :py:func:`xarray.load_dataarray` with
25-
``engine="gmt"``, pass the ``decode_kind`` parameter that can be either:
25+
``engine="gmt"``, pass the ``raster_kind`` parameter that can be either:
2626
2727
- ``"grid"`` - for reading single-band raster grids
2828
- ``"image"`` - for reading multi-band raster images
2929
3030
Examples
3131
--------
32-
Read a single-band NetCDF file using ``decode_kind="grid"``
32+
Read a single-band NetCDF file using ``raster_kind="grid"``
3333
3434
>>> import pygmt
3535
>>> import xarray as xr
3636
>>>
3737
>>> da_grid = xr.open_dataarray(
38-
... "@static_earth_relief.nc", engine="gmt", decode_kind="grid"
38+
... "@static_earth_relief.nc", engine="gmt", raster_kind="grid"
3939
... )
4040
>>> da_grid # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
4141
<xarray.DataArray 'z' (lat: 14, lon: 8)>...
@@ -51,10 +51,10 @@ class GMTBackendEntrypoint(BackendEntrypoint):
5151
actual_range: [190. 981.]
5252
long_name: elevation (m)
5353
54-
Read a multi-band GeoTIFF file using ``decode_kind="image"``
54+
Read a multi-band GeoTIFF file using ``raster_kind="image"``
5555
5656
>>> da_image = xr.open_dataarray(
57-
... "@earth_night_01d", engine="gmt", decode_kind="image"
57+
... "@earth_night_01d", engine="gmt", raster_kind="image"
5858
... )
5959
>>> da_image # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
6060
<xarray.DataArray 'z' (band: 3, y: 180, x: 360)>...
@@ -68,35 +68,35 @@ class GMTBackendEntrypoint(BackendEntrypoint):
6868
"""
6969

7070
description = "Open raster (.grd, .nc or .tif) files in Xarray via GMT."
71-
open_dataset_parameters = ("filename_or_obj", "decode_kind")
71+
open_dataset_parameters = ("filename_or_obj", "raster_kind")
7272
url = "https://github.com/GenericMappingTools/pygmt"
7373

7474
def open_dataset( # type: ignore[override]
7575
self,
7676
filename_or_obj: PathLike,
7777
*,
7878
drop_variables=None, # noqa: ARG002
79-
decode_kind: Literal["grid", "image"],
79+
raster_kind: Literal["grid", "image"],
8080
# other backend specific keyword arguments
8181
# `chunks` and `cache` DO NOT go here, they are handled by xarray
8282
) -> xr.Dataset:
8383
"""
8484
Backend open_dataset method used by Xarray in :py:func:`~xarray.open_dataset`.
8585
"""
86-
if decode_kind not in {"grid", "image"}:
87-
msg = f"Invalid raster kind: '{decode_kind}'. Valid values are 'grid' or 'image'."
86+
if raster_kind not in {"grid", "image"}:
87+
msg = f"Invalid raster kind: '{raster_kind}'. Valid values are 'grid' or 'image'."
8888
raise GMTInvalidInput(msg)
8989

9090
with Session() as lib:
91-
with lib.virtualfile_out(kind=decode_kind) as voutfile:
92-
kwdict = {"T": {"grid": "g", "image": "i"}[decode_kind]}
91+
with lib.virtualfile_out(kind=raster_kind) as voutfile:
92+
kwdict = {"T": {"grid": "g", "image": "i"}[raster_kind]}
9393
lib.call_module(
9494
module="read",
9595
args=[filename_or_obj, voutfile, *build_arg_list(kwdict)],
9696
)
9797

9898
raster: xr.DataArray = lib.virtualfile_to_raster(
99-
vfname=voutfile, kind=decode_kind
99+
vfname=voutfile, kind=raster_kind
100100
)
101101
# Add "source" encoding
102102
source = which(fname=filename_or_obj)

0 commit comments

Comments
 (0)