Skip to content

Commit 25becb2

Browse files
committed
AliasSystem: Migrate the region parameter to the new alias system (#4099)
1 parent 2dd4391 commit 25becb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+285
-168
lines changed

pygmt/alias.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ def add_common(self, **kwargs):
300300
"""
301301
for key, value in kwargs.items():
302302
match key:
303+
case "J":
304+
alias = Alias(value, name="projection")
305+
case "R":
306+
alias = Alias(value, name="region", sep="/", size=(4, 6))
303307
case "V":
304308
alias = Alias(
305309
value,
@@ -314,8 +318,6 @@ def add_common(self, **kwargs):
314318
"debug": "d",
315319
},
316320
)
317-
case "J":
318-
alias = Alias(value, name="projection")
319321
case "c":
320322
alias = Alias(value, name="panel", sep=",", size=2)
321323
case "t":

pygmt/src/basemap.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
basemap - Plot base maps and frames.
33
"""
44

5+
from collections.abc import Sequence
56
from typing import Literal
67

78
from pygmt.alias import AliasSystem
@@ -11,7 +12,6 @@
1112

1213
@fmt_docstring
1314
@use_alias(
14-
R="region",
1515
Jz="zscale",
1616
JZ="zsize",
1717
B="frame",
@@ -22,10 +22,11 @@
2222
f="coltypes",
2323
p="perspective",
2424
)
25-
@kwargs_to_strings(R="sequence", p="sequence")
25+
@kwargs_to_strings(p="sequence")
2626
def basemap(
2727
self,
2828
projection: str | None = None,
29+
region: Sequence[float | str] | str | None = None,
2930
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
3031
| bool = False,
3132
panel: int | tuple[int, int] | bool = False,
@@ -47,6 +48,7 @@ def basemap(
4748
4849
{aliases}
4950
- J = projection
51+
- R = region
5052
- V = verbose
5153
- c = panel
5254
- t = transparency
@@ -97,6 +99,7 @@ def basemap(
9799

98100
aliasdict = AliasSystem().add_common(
99101
J=projection,
102+
R=region,
100103
V=verbose,
101104
c=panel,
102105
t=transparency,

pygmt/src/binstats.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
binstats - Bin spatial data and determine statistics per bin.
33
"""
44

5+
from collections.abc import Sequence
56
from typing import Literal
67

78
import xarray as xr
@@ -16,7 +17,6 @@
1617
E="empty",
1718
I="spacing",
1819
N="normalize",
19-
R="region",
2020
S="search_radius",
2121
W="weight",
2222
a="aspatial",
@@ -25,7 +25,7 @@
2525
i="incols",
2626
r="registration",
2727
)
28-
@kwargs_to_strings(I="sequence", R="sequence", i="sequence_comma")
28+
@kwargs_to_strings(I="sequence", i="sequence_comma")
2929
def binstats(
3030
data: PathLike | TableLike,
3131
outgrid: PathLike | None = None,
@@ -48,6 +48,7 @@ def binstats(
4848
"sum",
4949
] = "number",
5050
quantile_value: float = 50,
51+
region: Sequence[float | str] | str | None = None,
5152
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
5253
| bool = False,
5354
**kwargs,
@@ -67,6 +68,7 @@ def binstats(
6768
6869
{aliases}
6970
- C = statistic
71+
- R = region
7072
- V = verbose
7173
7274
Parameters
@@ -154,6 +156,7 @@ def binstats(
154156
},
155157
),
156158
).add_common(
159+
R=region,
157160
V=verbose,
158161
)
159162
aliasdict.merge(kwargs)

pygmt/src/blockm.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
blockm - Block average (x, y, z) data tables by mean, median, or mode estimation.
33
"""
44

5+
from collections.abc import Sequence
56
from typing import Literal
67

78
import numpy as np
@@ -73,7 +74,6 @@ def _blockm(
7374
@fmt_docstring
7475
@use_alias(
7576
I="spacing",
76-
R="region",
7777
S="summary",
7878
a="aspatial",
7979
b="binary",
@@ -86,14 +86,15 @@ def _blockm(
8686
r="registration",
8787
w="wrap",
8888
)
89-
@kwargs_to_strings(I="sequence", R="sequence", i="sequence_comma", o="sequence_comma")
89+
@kwargs_to_strings(I="sequence", i="sequence_comma", o="sequence_comma")
9090
def blockmean(
9191
data: PathLike | TableLike | None = None,
9292
x=None,
9393
y=None,
9494
z=None,
9595
output_type: Literal["pandas", "numpy", "file"] = "pandas",
9696
outfile: PathLike | None = None,
97+
region: Sequence[float | str] | str | None = None,
9798
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
9899
| bool = False,
99100
**kwargs,
@@ -113,6 +114,7 @@ def blockmean(
113114
Full GMT docs at :gmt-docs:`blockmean.html`.
114115
115116
{aliases}
117+
- R = region
116118
- V = verbose
117119
118120
Parameters
@@ -166,6 +168,7 @@ def blockmean(
166168
>>> data_bmean = pygmt.blockmean(data=data, region=[245, 255, 20, 30], spacing="5m")
167169
"""
168170
aliasdict = AliasSystem().add_common(
171+
R=region,
169172
V=verbose,
170173
)
171174
aliasdict.merge(kwargs)
@@ -185,7 +188,6 @@ def blockmean(
185188
@fmt_docstring
186189
@use_alias(
187190
I="spacing",
188-
R="region",
189191
a="aspatial",
190192
b="binary",
191193
d="nodata",
@@ -197,14 +199,15 @@ def blockmean(
197199
r="registration",
198200
w="wrap",
199201
)
200-
@kwargs_to_strings(I="sequence", R="sequence", i="sequence_comma", o="sequence_comma")
202+
@kwargs_to_strings(I="sequence", i="sequence_comma", o="sequence_comma")
201203
def blockmedian(
202204
data: PathLike | TableLike | None = None,
203205
x=None,
204206
y=None,
205207
z=None,
206208
output_type: Literal["pandas", "numpy", "file"] = "pandas",
207209
outfile: PathLike | None = None,
210+
region: Sequence[float | str] | str | None = None,
208211
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
209212
| bool = False,
210213
**kwargs,
@@ -224,6 +227,7 @@ def blockmedian(
224227
Full GMT docs at :gmt-docs:`blockmedian.html`.
225228
226229
{aliases}
230+
- R = region
227231
- V = verbose
228232
229233
Parameters
@@ -271,6 +275,7 @@ def blockmedian(
271275
... )
272276
"""
273277
aliasdict = AliasSystem().add_common(
278+
R=region,
274279
V=verbose,
275280
)
276281
aliasdict.merge(kwargs)
@@ -290,7 +295,6 @@ def blockmedian(
290295
@fmt_docstring
291296
@use_alias(
292297
I="spacing",
293-
R="region",
294298
a="aspatial",
295299
b="binary",
296300
d="nodata",
@@ -302,14 +306,15 @@ def blockmedian(
302306
r="registration",
303307
w="wrap",
304308
)
305-
@kwargs_to_strings(I="sequence", R="sequence", i="sequence_comma", o="sequence_comma")
309+
@kwargs_to_strings(I="sequence", i="sequence_comma", o="sequence_comma")
306310
def blockmode(
307311
data: PathLike | TableLike | None = None,
308312
x=None,
309313
y=None,
310314
z=None,
311315
output_type: Literal["pandas", "numpy", "file"] = "pandas",
312316
outfile: PathLike | None = None,
317+
region: Sequence[float | str] | str | None = None,
313318
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
314319
| bool = False,
315320
**kwargs,
@@ -329,6 +334,7 @@ def blockmode(
329334
Full GMT docs at :gmt-docs:`blockmode.html`.
330335
331336
{aliases}
337+
- R = region
332338
- V = verbose
333339
334340
Parameters
@@ -374,6 +380,7 @@ def blockmode(
374380
>>> data_bmode = pygmt.blockmode(data=data, region=[245, 255, 20, 30], spacing="5m")
375381
"""
376382
aliasdict = AliasSystem().add_common(
383+
R=region,
377384
V=verbose,
378385
)
379386
aliasdict.merge(kwargs)

pygmt/src/coast.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
coast - Plot continents, countries, shorelines, rivers, and borders.
33
"""
44

5+
from collections.abc import Sequence
56
from typing import Literal
67

78
from pygmt.alias import Alias, AliasSystem
@@ -29,19 +30,19 @@
2930
I="rivers",
3031
L="map_scale",
3132
N="borders",
32-
R="region",
3333
S="water",
3434
W="shorelines",
3535
p="perspective",
3636
)
37-
@kwargs_to_strings(R="sequence", p="sequence")
37+
@kwargs_to_strings(p="sequence")
3838
def coast(
3939
self,
4040
projection: str | None = None,
4141
resolution: Literal[
4242
"auto", "full", "high", "intermediate", "low", "crude", None
4343
] = None,
4444
box: Box | bool = False,
45+
region: Sequence[float | str] | str | None = None,
4546
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
4647
| bool = False,
4748
panel: int | tuple[int, int] | bool = False,
@@ -71,6 +72,7 @@ def coast(
7172
- D = resolution
7273
- F = box
7374
- J = projection
75+
- R = region
7476
- V = verbose
7577
- c = panel
7678
- t = transparency
@@ -222,6 +224,7 @@ def coast(
222224
F=Alias(box, name="box"),
223225
).add_common(
224226
J=projection,
227+
R=region,
225228
V=verbose,
226229
c=panel,
227230
t=transparency,

pygmt/src/colorbar.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
colorbar - Plot gray scale or color scale bar.
33
"""
44

5+
from collections.abc import Sequence
56
from typing import Literal
67

78
from pygmt.alias import Alias, AliasSystem
@@ -21,16 +22,16 @@
2122
I="shading",
2223
L="equalsize",
2324
Q="log",
24-
R="region",
2525
W="scale",
2626
Z="zfile",
2727
p="perspective",
2828
)
29-
@kwargs_to_strings(R="sequence", G="sequence", I="sequence", p="sequence")
29+
@kwargs_to_strings(G="sequence", I="sequence", p="sequence")
3030
def colorbar(
3131
self,
3232
projection: str | None = None,
3333
box: Box | bool = False,
34+
region: Sequence[float | str] | str | None = None,
3435
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
3536
| bool = False,
3637
panel: int | tuple[int, int] | bool = False,
@@ -53,6 +54,7 @@ def colorbar(
5354
{aliases}
5455
- F = box
5556
- J = projection
57+
- R = region
5658
- V = verbose
5759
- c = panel
5860
- t = transparency
@@ -151,6 +153,7 @@ def colorbar(
151153
F=Alias(box, name="box"),
152154
).add_common(
153155
J=projection,
156+
R=region,
154157
V=verbose,
155158
c=panel,
156159
t=transparency,

pygmt/src/contour.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
contour - Contour table data by direct triangulation.
33
"""
44

5+
from collections.abc import Sequence
56
from typing import Literal
67

78
from pygmt._typing import PathLike, TableLike
@@ -23,7 +24,6 @@
2324
C="levels",
2425
G="label_placement",
2526
L="triangular_mesh_pen",
26-
R="region",
2727
S="skip",
2828
W="pen",
2929
b="binary",
@@ -35,15 +35,16 @@
3535
l="label",
3636
p="perspective",
3737
)
38-
@kwargs_to_strings(R="sequence", i="sequence_comma", p="sequence")
39-
def contour(
38+
@kwargs_to_strings(i="sequence_comma", p="sequence")
39+
def contour( # noqa: PLR0913
4040
self,
4141
data: PathLike | TableLike | None = None,
4242
x=None,
4343
y=None,
4444
z=None,
4545
no_clip: bool = False,
4646
projection: str | None = None,
47+
region: Sequence[float | str] | str | None = None,
4748
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
4849
| bool = False,
4950
panel: int | tuple[int, int] | bool = False,
@@ -63,6 +64,7 @@ def contour(
6364
{aliases}
6465
- J = projection
6566
- N = no_clip
67+
- R = region
6668
- V = verbose
6769
- c = panel
6870
- t = transparency
@@ -164,6 +166,7 @@ def contour(
164166
N=Alias(no_clip, name="no_clip"),
165167
).add_common(
166168
J=projection,
169+
R=region,
167170
V=verbose,
168171
c=panel,
169172
t=transparency,

0 commit comments

Comments
 (0)