@@ -22,20 +22,20 @@ class GMTBackendEntrypoint(BackendEntrypoint):
22
22
and other raster formats.
23
23
24
24
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:
26
26
27
27
- ``"grid"`` - for reading single-band raster grids
28
28
- ``"image"`` - for reading multi-band raster images
29
29
30
30
Examples
31
31
--------
32
- Read a single-band NetCDF file using ``decode_kind ="grid"``
32
+ Read a single-band NetCDF file using ``raster_kind ="grid"``
33
33
34
34
>>> import pygmt
35
35
>>> import xarray as xr
36
36
>>>
37
37
>>> 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"
39
39
... )
40
40
>>> da_grid # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
41
41
<xarray.DataArray 'z' (lat: 14, lon: 8)>...
@@ -51,10 +51,10 @@ class GMTBackendEntrypoint(BackendEntrypoint):
51
51
actual_range: [190. 981.]
52
52
long_name: elevation (m)
53
53
54
- Read a multi-band GeoTIFF file using ``decode_kind ="image"``
54
+ Read a multi-band GeoTIFF file using ``raster_kind ="image"``
55
55
56
56
>>> da_image = xr.open_dataarray(
57
- ... "@earth_night_01d", engine="gmt", decode_kind ="image"
57
+ ... "@earth_night_01d", engine="gmt", raster_kind ="image"
58
58
... )
59
59
>>> da_image # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
60
60
<xarray.DataArray 'z' (band: 3, y: 180, x: 360)>...
@@ -68,35 +68,35 @@ class GMTBackendEntrypoint(BackendEntrypoint):
68
68
"""
69
69
70
70
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 " )
72
72
url = "https://github.com/GenericMappingTools/pygmt"
73
73
74
74
def open_dataset ( # type: ignore[override]
75
75
self ,
76
76
filename_or_obj : PathLike ,
77
77
* ,
78
78
drop_variables = None , # noqa: ARG002
79
- decode_kind : Literal ["grid" , "image" ],
79
+ raster_kind : Literal ["grid" , "image" ],
80
80
# other backend specific keyword arguments
81
81
# `chunks` and `cache` DO NOT go here, they are handled by xarray
82
82
) -> xr .Dataset :
83
83
"""
84
84
Backend open_dataset method used by Xarray in :py:func:`~xarray.open_dataset`.
85
85
"""
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'."
88
88
raise GMTInvalidInput (msg )
89
89
90
90
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 ]}
93
93
lib .call_module (
94
94
module = "read" ,
95
95
args = [filename_or_obj , voutfile , * build_arg_list (kwdict )],
96
96
)
97
97
98
98
raster : xr .DataArray = lib .virtualfile_to_raster (
99
- vfname = voutfile , kind = decode_kind
99
+ vfname = voutfile , kind = raster_kind
100
100
)
101
101
# Add "source" encoding
102
102
source = which (fname = filename_or_obj )
0 commit comments