Skip to content

Commit d36adf0

Browse files
authored
pygmt.grdclip: Use the new alias system for parameters above/below/between/replace (#4034)
1 parent cbae952 commit d36adf0

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

pygmt/src/grdclip.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
import xarray as xr
88
from pygmt._typing import PathLike
9+
from pygmt.alias import Alias, AliasSystem
910
from pygmt.clib import Session
1011
from pygmt.exceptions import GMTInvalidInput
1112
from pygmt.helpers import (
1213
build_arg_list,
1314
deprecate_parameter,
1415
fmt_docstring,
1516
kwargs_to_strings,
16-
sequence_join,
1717
use_alias,
1818
)
1919

@@ -23,9 +23,7 @@
2323
# TODO(PyGMT>=0.19.0): Remove the deprecated "new" parameter.
2424
@fmt_docstring
2525
@deprecate_parameter("new", "replace", "v0.15.0", remove_version="v0.19.0")
26-
@use_alias(
27-
R="region", Sa="above-", Sb="below-", Si="between-", Sr="replace-", V="verbose"
28-
)
26+
@use_alias(R="region", V="verbose")
2927
@kwargs_to_strings(R="sequence")
3028
def grdclip(
3129
grid: PathLike | xr.DataArray,
@@ -54,6 +52,10 @@ def grdclip(
5452
Full GMT docs at :gmt-docs:`grdclip.html`.
5553
5654
{aliases}
55+
- Sa=above
56+
- Sb=below
57+
- Si=between
58+
- Sr=replace
5759
5860
Parameters
5961
----------
@@ -113,19 +115,20 @@ def grdclip(
113115
)
114116
raise GMTInvalidInput(msg)
115117

116-
# Parse the -S option.
117-
kwargs["Sa"] = sequence_join(above, size=2, name="above")
118-
kwargs["Sb"] = sequence_join(below, size=2, name="below")
119-
kwargs["Si"] = sequence_join(between, size=3, ndim=2, name="between")
120-
kwargs["Sr"] = sequence_join(replace, size=2, ndim=2, name="replace")
118+
aliasdict = AliasSystem(
119+
Sa=Alias(above, name="above", sep="/", size=2),
120+
Sb=Alias(below, name="below", sep="/", size=2),
121+
Si=Alias(between, name="between", sep="/", size=3, ndim=2),
122+
Sr=Alias(replace, name="replace", sep="/", size=2, ndim=2),
123+
).merge(kwargs)
121124

122125
with Session() as lib:
123126
with (
124127
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,
125128
lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd,
126129
):
127-
kwargs["G"] = voutgrd
130+
aliasdict["G"] = voutgrd
128131
lib.call_module(
129-
module="grdclip", args=build_arg_list(kwargs, infile=vingrd)
132+
module="grdclip", args=build_arg_list(aliasdict, infile=vingrd)
130133
)
131134
return lib.virtualfile_to_raster(vfname=voutgrd, outgrid=outgrid)

0 commit comments

Comments
 (0)