7
7
import numpy as np
8
8
import xarray as xr
9
9
from pygmt ._typing import PathLike
10
+ from pygmt .alias import Alias , AliasSystem
10
11
from pygmt .clib import Session
11
12
from pygmt .exceptions import GMTInvalidInput
12
13
from pygmt .helpers import (
@@ -71,52 +72,11 @@ def _validate_params(
71
72
raise GMTInvalidInput (msg )
72
73
73
74
74
- def _parse_fill_mode (
75
- constantfill = None , gridfill = None , neighborfill = None , splinefill = None
76
- ) -> str | None :
77
- """
78
- Parse the fill parameters and return the appropriate string for the -A option.
79
-
80
- >>> import numpy as np
81
- >>> import xarray as xr
82
- >>> _parse_fill_mode(constantfill=20.0)
83
- 'c20.0'
84
- >>> _parse_fill_mode(gridfill="bggrid.nc")
85
- 'g'
86
- >>> _parse_fill_mode(gridfill=xr.DataArray(np.zeros((10, 10))))
87
- 'g'
88
- >>> _parse_fill_mode(neighborfill=20)
89
- 'n20'
90
- >>> _parse_fill_mode(neighborfill=True)
91
- 'n'
92
- >>> _parse_fill_mode(splinefill=0.5)
93
- 's0.5'
94
- >>> _parse_fill_mode(splinefill=True)
95
- 's'
96
- """
97
- if constantfill is not None :
98
- return f"c{ constantfill } "
99
- if gridfill is not None :
100
- return "g" # Append grid file name later to support xarray.DataArray.
101
- if neighborfill is not None and neighborfill is not False :
102
- return "n" if neighborfill is True else f"n{ neighborfill } "
103
- if splinefill is not None and splinefill is not False :
104
- return "s" if splinefill is True else f"s{ splinefill } "
105
- return None
106
-
107
-
108
75
@fmt_docstring
109
76
# TODO(PyGMT>=0.19.0): Remove the deprecated 'no_data' parameter.
110
77
# TODO(PyGMT>=0.19.0): Remove the deprecated 'mode' parameter.
111
78
@deprecate_parameter ("no_data" , "hole" , "v0.15.0" , remove_version = "v0.19.0" )
112
- @use_alias (
113
- A = "constantfill/gridfill/neighborfill/splinefill/mode-" ,
114
- L = "inquire-" ,
115
- N = "hole" ,
116
- R = "region" ,
117
- V = "verbose" ,
118
- f = "coltypes" ,
119
- )
79
+ @use_alias (N = "hole" , R = "region" , V = "verbose" , f = "coltypes" )
120
80
@kwargs_to_strings (R = "sequence" )
121
81
def grdfill (
122
82
grid : PathLike | xr .DataArray ,
@@ -141,6 +101,11 @@ def grdfill(
141
101
Full GMT docs at :gmt-docs:`grdfill.html`.
142
102
143
103
{aliases}
104
+ - Ac=constantfill
105
+ - Ag=gridfill
106
+ - An=neighborfill
107
+ - As=splinefill
108
+ - L=inquire
144
109
145
110
Parameters
146
111
----------
@@ -209,21 +174,24 @@ def grdfill(
209
174
# Validate the fill/inquire parameters.
210
175
_validate_params (constantfill , gridfill , neighborfill , splinefill , inquire , mode )
211
176
212
- # Parse the fill parameters and return the appropriate string for the -A option.
213
- kwargs ["A" ] = (
214
- _parse_fill_mode (constantfill , gridfill , neighborfill , splinefill )
215
- if mode is None
216
- else mode
217
- )
177
+ # _validate_params has already ensured that only one of the parameters is set.
178
+ aliasdict = AliasSystem (
179
+ A = Alias (mode , name = "mode" ),
180
+ Ac = Alias (constantfill , name = "constantfill" ),
181
+ # For grdfill, append the actual or virtual grid file name later.
182
+ Ag = Alias (gridfill is not None , name = "gridfill" ),
183
+ An = Alias (neighborfill , name = "neighborfill" ),
184
+ As = Alias (splinefill , name = "splinefill" ),
185
+ L = Alias (inquire , name = "inquire" ),
186
+ ).merge (kwargs )
218
187
219
188
with Session () as lib :
220
189
with lib .virtualfile_in (check_kind = "raster" , data = grid ) as vingrd :
221
190
if inquire : # Inquire mode.
222
- kwargs ["L" ] = True
223
191
with lib .virtualfile_out (kind = "dataset" ) as vouttbl :
224
192
lib .call_module (
225
193
module = "grdfill" ,
226
- args = build_arg_list (kwargs , infile = vingrd , outfile = vouttbl ),
194
+ args = build_arg_list (aliasdict , infile = vingrd , outfile = vouttbl ),
227
195
)
228
196
return lib .virtualfile_to_dataset (
229
197
vfname = vouttbl , output_type = "numpy"
@@ -238,9 +206,9 @@ def grdfill(
238
206
):
239
207
if gridfill is not None :
240
208
# Fill by a grid. Append the actual or virtual grid file name.
241
- kwargs [ "A " ] = f"g { vbggrd } "
242
- kwargs ["G" ] = voutgrd
209
+ aliasdict [ "Ag " ] = vbggrd
210
+ aliasdict ["G" ] = voutgrd
243
211
lib .call_module (
244
- module = "grdfill" , args = build_arg_list (kwargs , infile = vingrd )
212
+ module = "grdfill" , args = build_arg_list (aliasdict , infile = vingrd )
245
213
)
246
214
return lib .virtualfile_to_raster (vfname = voutgrd , outgrid = outgrid )
0 commit comments