Skip to content

Commit 195347d

Browse files
authored
AliasSystem: Migrate the 'registration' parameter to the new alias system and support descriptive arguments (#4182)
1 parent 4219ebe commit 195347d

File tree

15 files changed

+61
-31
lines changed

15 files changed

+61
-31
lines changed

pygmt/alias.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ def add_common(self, **kwargs):
320320
)
321321
case "c":
322322
alias = Alias(value, name="panel", sep=",", size=2)
323+
case "r":
324+
alias = Alias(
325+
value,
326+
name="registration",
327+
mapping={"gridline": "g", "pixel": "p"},
328+
)
323329
case "t":
324330
alias = Alias(value, name="transparency")
325331
case "x":

pygmt/helpers/decorators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,10 @@
277277
*xmin/xmax/ymin/ymax*\ [**+r**][**+u**\ *unit*].
278278
Specify the :doc:`region </tutorials/basics/regions>` of interest.""",
279279
"registration": r"""
280-
registration : str
281-
**g**\|\ **p**.
282-
Force gridline (**g**) or pixel (**p**) node registration
283-
[Default is **g**\ (ridline)].""",
280+
registration
281+
Select gridline or pixel node registration. Valid values are ``"gridline"``,
282+
``"pixel"``, and bool. GMT default is gridline registration. If
283+
``True``, select pixel registration.""",
284284
"skiprows": r"""
285285
skiprows : bool or str
286286
[*cols*][**+a**][**+r**].

pygmt/src/binstats.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
b="binary",
2424
h="header",
2525
i="incols",
26-
r="registration",
2726
)
2827
@kwargs_to_strings(I="sequence", i="sequence_comma")
2928
def binstats(
@@ -49,6 +48,7 @@ def binstats(
4948
] = "number",
5049
quantile_value: float = 50,
5150
region: Sequence[float | str] | str | None = None,
51+
registration: Literal["gridline", "pixel"] | bool = False,
5252
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
5353
| bool = False,
5454
**kwargs,
@@ -70,6 +70,7 @@ def binstats(
7070
- C = statistic
7171
- R = region
7272
- V = verbose
73+
- r = registration
7374
7475
Parameters
7576
----------
@@ -158,6 +159,7 @@ def binstats(
158159
).add_common(
159160
R=region,
160161
V=verbose,
162+
r=registration,
161163
)
162164
aliasdict.merge(kwargs)
163165
if statistic == "quantile":

pygmt/src/blockm.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def _blockm(
8383
h="header",
8484
i="incols",
8585
o="outcols",
86-
r="registration",
8786
w="wrap",
8887
)
8988
@kwargs_to_strings(I="sequence", i="sequence_comma", o="sequence_comma")
@@ -95,6 +94,7 @@ def blockmean(
9594
output_type: Literal["pandas", "numpy", "file"] = "pandas",
9695
outfile: PathLike | None = None,
9796
region: Sequence[float | str] | str | None = None,
97+
registration: Literal["gridline", "pixel"] | bool = False,
9898
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
9999
| bool = False,
100100
**kwargs,
@@ -116,6 +116,7 @@ def blockmean(
116116
{aliases}
117117
- R = region
118118
- V = verbose
119+
- r = registration
119120
120121
Parameters
121122
----------
@@ -170,6 +171,7 @@ def blockmean(
170171
aliasdict = AliasSystem().add_common(
171172
R=region,
172173
V=verbose,
174+
r=registration,
173175
)
174176
aliasdict.merge(kwargs)
175177

@@ -196,7 +198,6 @@ def blockmean(
196198
h="header",
197199
i="incols",
198200
o="outcols",
199-
r="registration",
200201
w="wrap",
201202
)
202203
@kwargs_to_strings(I="sequence", i="sequence_comma", o="sequence_comma")
@@ -208,6 +209,7 @@ def blockmedian(
208209
output_type: Literal["pandas", "numpy", "file"] = "pandas",
209210
outfile: PathLike | None = None,
210211
region: Sequence[float | str] | str | None = None,
212+
registration: Literal["gridline", "pixel"] | bool = False,
211213
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
212214
| bool = False,
213215
**kwargs,
@@ -229,6 +231,7 @@ def blockmedian(
229231
{aliases}
230232
- R = region
231233
- V = verbose
234+
- r = registration
232235
233236
Parameters
234237
----------
@@ -277,6 +280,7 @@ def blockmedian(
277280
aliasdict = AliasSystem().add_common(
278281
R=region,
279282
V=verbose,
283+
r=registration,
280284
)
281285
aliasdict.merge(kwargs)
282286

@@ -303,7 +307,6 @@ def blockmedian(
303307
h="header",
304308
i="incols",
305309
o="outcols",
306-
r="registration",
307310
w="wrap",
308311
)
309312
@kwargs_to_strings(I="sequence", i="sequence_comma", o="sequence_comma")
@@ -315,6 +318,7 @@ def blockmode(
315318
output_type: Literal["pandas", "numpy", "file"] = "pandas",
316319
outfile: PathLike | None = None,
317320
region: Sequence[float | str] | str | None = None,
321+
registration: Literal["gridline", "pixel"] | bool = False,
318322
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
319323
| bool = False,
320324
**kwargs,
@@ -336,6 +340,7 @@ def blockmode(
336340
{aliases}
337341
- R = region
338342
- V = verbose
343+
- r = registration
339344
340345
Parameters
341346
----------
@@ -382,6 +387,7 @@ def blockmode(
382387
aliasdict = AliasSystem().add_common(
383388
R=region,
384389
V=verbose,
390+
r=registration,
385391
)
386392
aliasdict.merge(kwargs)
387393

pygmt/src/grdfilter.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313

1414

1515
@fmt_docstring
16-
@use_alias(
17-
D="distance", F="filter", I="spacing", N="nans", f="coltypes", r="registration"
18-
)
16+
@use_alias(D="distance", F="filter", I="spacing", N="nans", f="coltypes")
1917
@kwargs_to_strings(I="sequence")
2018
def grdfilter(
2119
grid: PathLike | xr.DataArray,
2220
outgrid: PathLike | None = None,
2321
toggle: bool = False,
2422
region: Sequence[float | str] | str | None = None,
23+
registration: Literal["gridline", "pixel"] | bool = False,
2524
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
2625
| bool = False,
2726
cores: int | bool = False,
@@ -46,6 +45,7 @@ def grdfilter(
4645
- R = region
4746
- T = toggle
4847
- V = verbose
48+
- r = registration
4949
- x = cores
5050
5151
Parameters
@@ -140,6 +140,7 @@ def grdfilter(
140140
).add_common(
141141
R=region,
142142
V=verbose,
143+
r=registration,
143144
x=cores,
144145
)
145146
aliasdict.merge(kwargs)

pygmt/src/grdlandmask.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
@fmt_docstring
19-
@use_alias(A="area_thresh", I="spacing", r="registration")
19+
@use_alias(A="area_thresh", I="spacing")
2020
@kwargs_to_strings(I="sequence")
2121
def grdlandmask(
2222
outgrid: PathLike | None = None,
@@ -26,6 +26,7 @@ def grdlandmask(
2626
"auto", "full", "high", "intermediate", "low", "crude", None
2727
] = None,
2828
region: Sequence[float | str] | str | None = None,
29+
registration: Literal["gridline", "pixel"] | bool = False,
2930
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
3031
| bool = False,
3132
cores: int | bool = False,
@@ -48,6 +49,7 @@ def grdlandmask(
4849
- N = maskvalues
4950
- R = region
5051
- V = verbose
52+
- r = registration
5153
- x = cores
5254
5355
Parameters
@@ -130,6 +132,7 @@ def grdlandmask(
130132
).add_common(
131133
R=region,
132134
V=verbose,
135+
r=registration,
133136
x=cores,
134137
)
135138
aliasdict.merge(kwargs)

pygmt/src/grdproject.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
I="inverse",
2525
M="unit",
2626
n="interpolation",
27-
r="registration",
2827
)
2928
@kwargs_to_strings(C="sequence", D="sequence")
3029
def grdproject(
3130
grid: PathLike | xr.DataArray,
3231
outgrid: PathLike | None = None,
3332
projection: str | None = None,
3433
region: Sequence[float | str] | str | None = None,
34+
registration: Literal["gridline", "pixel"] | bool = False,
3535
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
3636
| bool = False,
3737
**kwargs,
@@ -60,6 +60,7 @@ def grdproject(
6060
- J = projection
6161
- R = region
6262
- V = verbose
63+
- r = registration
6364
6465
Parameters
6566
----------
@@ -123,6 +124,7 @@ def grdproject(
123124
J=projection,
124125
R=region,
125126
V=verbose,
127+
r=registration,
126128
)
127129
aliasdict.merge(kwargs)
128130

pygmt/src/grdsample.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
# TODO(PyGMT>=0.21.0): Remove the deprecated "translate" parameter.
2424
@fmt_docstring
2525
@deprecate_parameter("translate", "toggle", "v0.18.0", remove_version="v0.21.0")
26-
@use_alias(I="spacing", f="coltypes", n="interpolation", r="registration")
26+
@use_alias(I="spacing", f="coltypes", n="interpolation")
2727
@kwargs_to_strings(I="sequence")
2828
def grdsample(
2929
grid: PathLike | xr.DataArray,
3030
outgrid: PathLike | None = None,
3131
toggle: bool = False,
3232
region: Sequence[float | str] | str | None = None,
33+
registration: Literal["gridline", "pixel"] | bool = False,
3334
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
3435
| bool = False,
3536
cores: int | bool = False,
@@ -56,6 +57,7 @@ def grdsample(
5657
{aliases}
5758
- R = region
5859
- V = verbose
60+
- r = registration
5961
- x = cores
6062
6163
Parameters
@@ -68,12 +70,10 @@ def grdsample(
6870
Toggle between grid and pixel registration; if the input is grid-registered, the
6971
output will be pixel-registered and vice-versa. This is a *destructive* grid
7072
change; see :gmt-docs:`reference/options.html#switch-registrations`.
71-
registration : str or bool
72-
[**g**\|\ **p**\ ].
73-
Set registration to **g**\ ridline or **p**\ ixel.
7473
{verbose}
7574
{coltypes}
7675
{interpolation}
76+
{registration}
7777
{cores}
7878
7979
Returns
@@ -102,6 +102,7 @@ def grdsample(
102102
).add_common(
103103
R=region,
104104
V=verbose,
105+
r=registration,
105106
x=cores,
106107
)
107108
aliasdict.merge(kwargs)

pygmt/src/info.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
a="aspatial",
2626
f="coltypes",
2727
i="incols",
28-
r="registration",
2928
)
3029
@kwargs_to_strings(I="sequence", i="sequence_comma")
3130
def info(
3231
data: PathLike | TableLike,
32+
registration: Literal["gridline", "pixel"] | bool = False,
3333
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
3434
| bool = False,
3535
**kwargs,
@@ -54,6 +54,7 @@ def info(
5454
5555
{aliases}
5656
- V = verbose
57+
- r = registration
5758
5859
Parameters
5960
----------
@@ -91,6 +92,7 @@ def info(
9192
"""
9293
aliasdict = AliasSystem().add_common(
9394
V=verbose,
95+
r=registration,
9496
)
9597
aliasdict.merge(kwargs)
9698

pygmt/src/nearneighbor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
g="gap",
2929
h="header",
3030
i="incols",
31-
r="registration",
3231
w="wrap",
3332
)
3433
@kwargs_to_strings(I="sequence", i="sequence_comma")
@@ -39,6 +38,7 @@ def nearneighbor(
3938
z=None,
4039
outgrid: PathLike | None = None,
4140
region: Sequence[float | str] | str | None = None,
41+
registration: Literal["gridline", "pixel"] | bool = False,
4242
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
4343
| bool = False,
4444
**kwargs,
@@ -82,6 +82,7 @@ def nearneighbor(
8282
{aliases}
8383
- R = region
8484
- V = verbose
85+
- r = registration
8586
8687
Parameters
8788
----------
@@ -154,6 +155,7 @@ def nearneighbor(
154155
aliasdict = AliasSystem().add_common(
155156
R=region,
156157
V=verbose,
158+
r=registration,
157159
)
158160
aliasdict.merge(kwargs)
159161

0 commit comments

Comments
 (0)