Skip to content

Commit bcad4c1

Browse files
authored
AliasSystem: Migrate the 'spacing' parameter to the new alias system (#4213)
1 parent 9b11099 commit bcad4c1

File tree

15 files changed

+121
-81
lines changed

15 files changed

+121
-81
lines changed

pygmt/src/binstats.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,23 @@
99
from pygmt._typing import PathLike, TableLike
1010
from pygmt.alias import Alias, AliasSystem
1111
from pygmt.clib import Session
12-
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
12+
from pygmt.helpers import build_arg_list, fmt_docstring, use_alias
1313

1414

1515
@fmt_docstring
1616
@use_alias(
1717
E="empty",
18-
I="spacing",
1918
N="normalize",
2019
S="search_radius",
2120
W="weight",
2221
a="aspatial",
2322
b="binary",
2423
h="header",
2524
)
26-
@kwargs_to_strings(I="sequence")
2725
def binstats(
2826
data: PathLike | TableLike,
2927
outgrid: PathLike | None = None,
28+
spacing: Sequence[float | str] | None = None,
3029
statistic: Literal[
3130
"mean",
3231
"mad",
@@ -68,6 +67,7 @@ def binstats(
6867
6968
{aliases}
7069
- C = statistic
70+
- I = spacing
7171
- R = region
7272
- V = verbose
7373
- i = incols
@@ -157,6 +157,7 @@ def binstats(
157157
"sum": "z",
158158
},
159159
),
160+
I=Alias(spacing, name="spacing", sep="/", size=2),
160161
).add_common(
161162
R=region,
162163
V=verbose,

pygmt/src/blockm.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import numpy as np
99
import pandas as pd
1010
from pygmt._typing import PathLike, TableLike
11-
from pygmt.alias import AliasSystem
11+
from pygmt.alias import Alias, AliasSystem
1212
from pygmt.clib import Session
1313
from pygmt.helpers import (
1414
build_arg_list,
@@ -73,7 +73,6 @@ def _blockm(
7373

7474
@fmt_docstring
7575
@use_alias(
76-
I="spacing",
7776
S="summary",
7877
a="aspatial",
7978
b="binary",
@@ -84,14 +83,15 @@ def _blockm(
8483
o="outcols",
8584
w="wrap",
8685
)
87-
@kwargs_to_strings(I="sequence", o="sequence_comma")
88-
def blockmean(
86+
@kwargs_to_strings(o="sequence_comma")
87+
def blockmean( # noqa: PLR0913
8988
data: PathLike | TableLike | None = None,
9089
x=None,
9190
y=None,
9291
z=None,
9392
output_type: Literal["pandas", "numpy", "file"] = "pandas",
9493
outfile: PathLike | None = None,
94+
spacing: Sequence[float | str] | None = None,
9595
region: Sequence[float | str] | str | None = None,
9696
registration: Literal["gridline", "pixel"] | bool = False,
9797
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
@@ -114,6 +114,7 @@ def blockmean(
114114
Full GMT docs at :gmt-docs:`blockmean.html`.
115115
116116
{aliases}
117+
- I = spacing
117118
- R = region
118119
- V = verbose
119120
- i = incols
@@ -169,7 +170,9 @@ def blockmean(
169170
>>> # Calculate block mean values within 5 by 5 arc-minute bins
170171
>>> data_bmean = pygmt.blockmean(data=data, region=[245, 255, 20, 30], spacing="5m")
171172
"""
172-
aliasdict = AliasSystem().add_common(
173+
aliasdict = AliasSystem(
174+
I=Alias(spacing, name="spacing", sep="/", size=2),
175+
).add_common(
173176
R=region,
174177
V=verbose,
175178
i=incols,
@@ -191,7 +194,6 @@ def blockmean(
191194

192195
@fmt_docstring
193196
@use_alias(
194-
I="spacing",
195197
a="aspatial",
196198
b="binary",
197199
d="nodata",
@@ -201,14 +203,15 @@ def blockmean(
201203
o="outcols",
202204
w="wrap",
203205
)
204-
@kwargs_to_strings(I="sequence", o="sequence_comma")
205-
def blockmedian(
206+
@kwargs_to_strings(o="sequence_comma")
207+
def blockmedian( # noqa: PLR0913
206208
data: PathLike | TableLike | None = None,
207209
x=None,
208210
y=None,
209211
z=None,
210212
output_type: Literal["pandas", "numpy", "file"] = "pandas",
211213
outfile: PathLike | None = None,
214+
spacing: Sequence[float | str] | None = None,
212215
region: Sequence[float | str] | str | None = None,
213216
registration: Literal["gridline", "pixel"] | bool = False,
214217
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
@@ -231,6 +234,7 @@ def blockmedian(
231234
Full GMT docs at :gmt-docs:`blockmedian.html`.
232235
233236
{aliases}
237+
- I = spacing
234238
- R = region
235239
- V = verbose
236240
- i = incols
@@ -280,7 +284,9 @@ def blockmedian(
280284
... data=data, region=[245, 255, 20, 30], spacing="5m"
281285
... )
282286
"""
283-
aliasdict = AliasSystem().add_common(
287+
aliasdict = AliasSystem(
288+
I=Alias(spacing, name="spacing", sep="/", size=2),
289+
).add_common(
284290
R=region,
285291
V=verbose,
286292
i=incols,
@@ -302,7 +308,6 @@ def blockmedian(
302308

303309
@fmt_docstring
304310
@use_alias(
305-
I="spacing",
306311
a="aspatial",
307312
b="binary",
308313
d="nodata",
@@ -312,14 +317,15 @@ def blockmedian(
312317
o="outcols",
313318
w="wrap",
314319
)
315-
@kwargs_to_strings(I="sequence", o="sequence_comma")
316-
def blockmode(
320+
@kwargs_to_strings(o="sequence_comma")
321+
def blockmode( # noqa: PLR0913
317322
data: PathLike | TableLike | None = None,
318323
x=None,
319324
y=None,
320325
z=None,
321326
output_type: Literal["pandas", "numpy", "file"] = "pandas",
322327
outfile: PathLike | None = None,
328+
spacing: Sequence[float | str] | None = None,
323329
region: Sequence[float | str] | str | None = None,
324330
registration: Literal["gridline", "pixel"] | bool = False,
325331
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
@@ -342,6 +348,7 @@ def blockmode(
342348
Full GMT docs at :gmt-docs:`blockmode.html`.
343349
344350
{aliases}
351+
- I = spacing
345352
- R = region
346353
- V = verbose
347354
- i = incols
@@ -389,7 +396,9 @@ def blockmode(
389396
>>> # Calculate block mode values within 5 by 5 arc-minute bins
390397
>>> data_bmode = pygmt.blockmode(data=data, region=[245, 255, 20, 30], spacing="5m")
391398
"""
392-
aliasdict = AliasSystem().add_common(
399+
aliasdict = AliasSystem(
400+
I=Alias(spacing, name="spacing", sep="/", size=2),
401+
).add_common(
393402
R=region,
394403
V=verbose,
395404
i=incols,

pygmt/src/dimfilter.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77

88
import xarray as xr
99
from pygmt._typing import PathLike
10-
from pygmt.alias import AliasSystem
10+
from pygmt.alias import Alias, AliasSystem
1111
from pygmt.clib import Session
1212
from pygmt.exceptions import GMTInvalidInput
13-
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
13+
from pygmt.helpers import build_arg_list, fmt_docstring, use_alias
1414

1515
__doctest_skip__ = ["dimfilter"]
1616

1717

1818
@fmt_docstring
19-
@use_alias(D="distance", F="filter", I="spacing", N="sectors")
20-
@kwargs_to_strings(I="sequence")
19+
@use_alias(D="distance", F="filter", N="sectors")
2120
def dimfilter(
2221
grid: PathLike | xr.DataArray,
2322
outgrid: PathLike | None = None,
23+
spacing: Sequence[float | str] | None = None,
2424
region: Sequence[float | str] | str | None = None,
2525
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
2626
| bool = False,
@@ -48,6 +48,7 @@ def dimfilter(
4848
Full GMT docs at :gmt-docs:`dimfilter.html`.
4949
5050
{aliases}
51+
- I = spacing
5152
- R = region
5253
- V = verbose
5354
@@ -102,7 +103,7 @@ def dimfilter(
102103
If more than one mode is found we return their average
103104
value. Append **+l** or **+h** to the sectors if you rather want to
104105
return the smallest or largest of the modal values.
105-
spacing : str or list
106+
spacing
106107
*x_inc* [and optionally *y_inc*] is the output increment. Append
107108
**m** to indicate minutes, or **c** to indicate seconds. If the new
108109
*x_inc*, *y_inc* are **not** integer multiples of the old ones (in the
@@ -148,7 +149,9 @@ def dimfilter(
148149
)
149150
raise GMTInvalidInput(msg)
150151

151-
aliasdict = AliasSystem().add_common(
152+
aliasdict = AliasSystem(
153+
I=Alias(spacing, name="spacing", sep="/", size=2),
154+
).add_common(
152155
R=region,
153156
V=verbose,
154157
)

pygmt/src/grdfilter.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
from pygmt._typing import PathLike
1010
from pygmt.alias import Alias, AliasSystem
1111
from pygmt.clib import Session
12-
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
12+
from pygmt.helpers import build_arg_list, fmt_docstring, use_alias
1313

1414

1515
@fmt_docstring
16-
@use_alias(D="distance", F="filter", I="spacing", N="nans", f="coltypes")
17-
@kwargs_to_strings(I="sequence")
16+
@use_alias(D="distance", F="filter", N="nans", f="coltypes")
1817
def grdfilter(
1918
grid: PathLike | xr.DataArray,
2019
outgrid: PathLike | None = None,
2120
toggle: bool = False,
21+
spacing: Sequence[float | str] | None = None,
2222
region: Sequence[float | str] | str | None = None,
2323
registration: Literal["gridline", "pixel"] | bool = False,
2424
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
@@ -42,6 +42,7 @@ def grdfilter(
4242
Full GMT docs at :gmt-docs:`grdfilter.html`.
4343
4444
{aliases}
45+
- I = spacing
4546
- R = region
4647
- T = toggle
4748
- V = verbose
@@ -136,6 +137,7 @@ def grdfilter(
136137
>>> smooth_field = pygmt.grdfilter(grid=grid, filter="g600", distance="4")
137138
"""
138139
aliasdict = AliasSystem(
140+
I=Alias(spacing, name="spacing", sep="/", size=2),
139141
T=Alias(toggle, name="toggle"),
140142
).add_common(
141143
R=region,

pygmt/src/grdinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def grdinfo(
7777
Report grid domain and x/y-increments in world mapping format.
7878
The default value is ``False``. This cannot be called if
7979
``per_column`` is also set.
80-
spacing : str or list
80+
spacing
8181
*dx*\ [/*dy*]\|\ **b**\|\ **i**\|\ **r**.
8282
Report the min/max of the region to the nearest multiple of dx and dy,
8383
and output this in the form w/e/s/n (unless ``per_column`` is set). To

pygmt/src/grdlandmask.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
from pygmt.alias import Alias, AliasSystem
1111
from pygmt.clib import Session
1212
from pygmt.exceptions import GMTInvalidInput
13-
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
13+
from pygmt.helpers import build_arg_list, fmt_docstring, use_alias
1414

1515
__doctest_skip__ = ["grdlandmask"]
1616

1717

1818
@fmt_docstring
19-
@use_alias(A="area_thresh", I="spacing")
20-
@kwargs_to_strings(I="sequence")
19+
@use_alias(A="area_thresh")
2120
def grdlandmask(
2221
outgrid: PathLike | None = None,
22+
spacing: Sequence[float | str] | None = None,
2323
maskvalues: Sequence[float] | None = None,
2424
bordervalues: bool | float | Sequence[float] | None = None,
2525
resolution: Literal[
@@ -46,6 +46,7 @@ def grdlandmask(
4646
{aliases}
4747
- D = resolution
4848
- E = bordervalues
49+
- I = spacing
4950
- N = maskvalues
5051
- R = region
5152
- V = verbose
@@ -110,7 +111,7 @@ def grdlandmask(
110111
>>> # latitude range of 30° N to 35° N, and a grid spacing of 1 arc-degree
111112
>>> landmask = pygmt.grdlandmask(spacing=1, region=[125, 130, 30, 35])
112113
"""
113-
if kwargs.get("I") is None or kwargs.get("R", region) is None:
114+
if kwargs.get("I", spacing) is None or kwargs.get("R", region) is None:
114115
msg = "Both 'region' and 'spacing' must be specified."
115116
raise GMTInvalidInput(msg)
116117

@@ -127,6 +128,7 @@ def grdlandmask(
127128
"crude": "c",
128129
},
129130
),
131+
I=Alias(spacing, name="spacing", sep="/", size=2),
130132
N=Alias(maskvalues, name="maskvalues", sep="/", size=(2, 5)),
131133
E=Alias(bordervalues, name="bordervalues", sep="/", size=4),
132134
).add_common(

pygmt/src/grdsample.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
build_arg_list,
1515
deprecate_parameter,
1616
fmt_docstring,
17-
kwargs_to_strings,
1817
use_alias,
1918
)
2019

@@ -24,12 +23,12 @@
2423
# TODO(PyGMT>=0.21.0): Remove the deprecated "translate" parameter.
2524
@fmt_docstring
2625
@deprecate_parameter("translate", "toggle", "v0.18.0", remove_version="v0.21.0")
27-
@use_alias(I="spacing", f="coltypes", n="interpolation")
28-
@kwargs_to_strings(I="sequence")
26+
@use_alias(f="coltypes", n="interpolation")
2927
def grdsample(
3028
grid: PathLike | xr.DataArray,
3129
outgrid: PathLike | None = None,
3230
toggle: bool = False,
31+
spacing: Sequence[float | str] | None = None,
3332
region: Sequence[float | str] | str | None = None,
3433
registration: Literal["gridline", "pixel"] | bool = False,
3534
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
@@ -56,6 +55,7 @@ def grdsample(
5655
Full GMT docs at :gmt-docs:`grdsample.html`.
5756
5857
{aliases}
58+
- I = spacing
5959
- R = region
6060
- V = verbose
6161
- r = registration
@@ -105,6 +105,7 @@ def grdsample(
105105
raise GMTInvalidInput(msg)
106106

107107
aliasdict = AliasSystem(
108+
I=Alias(spacing, name="spacing", sep="/", size=2),
108109
T=Alias(toggle, name="toggle"),
109110
).add_common(
110111
R=region,

0 commit comments

Comments
 (0)