Skip to content

Commit 51e294e

Browse files
authored
Migrate the panel parameter to the new alias system (#4030)
1 parent 4c6a1f8 commit 51e294e

23 files changed

+220
-87
lines changed

pygmt/alias.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,10 @@ class AliasSystem(UserDict):
226226
... ],
227227
... B=Alias(frame, name="frame"),
228228
... D=Alias(repeat, name="repeat"),
229-
... c=Alias(panel, name="panel", sep=","),
230-
... ).merge(kwargs)
229+
... ).add_common(
230+
... c=panel,
231+
... )
232+
... aliasdict.merge(kwargs)
231233
... return build_arg_list(aliasdict)
232234
>>> func(
233235
... "infile",
@@ -268,6 +270,21 @@ def __init__(self, **kwargs):
268270
kwdict[option] = aliases._value
269271
super().__init__(kwdict)
270272

273+
def add_common(self, **kwargs):
274+
"""
275+
Add common parameters to the alias dictionary.
276+
"""
277+
for key, value in kwargs.items():
278+
match key:
279+
case "c":
280+
alias = Alias(value, name="panel", sep=",", size=2)
281+
case _:
282+
raise GMTValueError(key, description="common parameter")
283+
self.aliasdict[key] = alias
284+
if alias._value is not None:
285+
self[key] = alias._value
286+
return self
287+
271288
def merge(self, kwargs: Mapping[str, Any]):
272289
"""
273290
Update the dictionary with additional keyword arguments.

pygmt/helpers/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@
261261
:gmt-docs:`gmt.html#grd-inout-full` for the available modifiers.
262262
""",
263263
"panel": r"""
264-
panel : bool, int, or list
264+
panel
265265
Select a specific subplot panel. Only allowed when used in
266266
:meth:`Figure.subplot` mode.
267267

pygmt/src/basemap.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
Td="rose",
1919
Tm="compass",
2020
V="verbose",
21-
c="panel",
2221
f="coltypes",
2322
p="perspective",
2423
t="transparency",
2524
)
26-
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
27-
def basemap(self, projection=None, **kwargs):
25+
@kwargs_to_strings(R="sequence", p="sequence")
26+
def basemap(
27+
self, projection=None, panel: int | tuple[int, int] | bool = False, **kwargs
28+
):
2829
r"""
2930
Plot base maps and frames.
3031
@@ -40,6 +41,7 @@ def basemap(self, projection=None, **kwargs):
4041
4142
{aliases}
4243
- J = projection
44+
- c = panel
4345
4446
Parameters
4547
----------
@@ -84,8 +86,13 @@ def basemap(self, projection=None, **kwargs):
8486
{transparency}
8587
"""
8688
self._activate_figure()
89+
8790
aliasdict = AliasSystem(
8891
J=Alias(projection, name="projection"),
89-
).merge(kwargs)
92+
).add_common(
93+
c=panel,
94+
)
95+
aliasdict.merge(kwargs)
96+
9097
with Session() as lib:
9198
lib.call_module(module="basemap", args=build_arg_list(aliasdict))

pygmt/src/coast.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@
3333
S="water",
3434
V="verbose",
3535
W="shorelines",
36-
c="panel",
3736
p="perspective",
3837
t="transparency",
3938
)
40-
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
39+
@kwargs_to_strings(R="sequence", p="sequence")
4140
def coast(
4241
self,
4342
projection=None,
4443
resolution: Literal[
4544
"auto", "full", "high", "intermediate", "low", "crude", None
4645
] = None,
46+
panel: int | tuple[int, int] | bool = False,
4747
**kwargs,
4848
):
4949
r"""
@@ -68,6 +68,7 @@ def coast(
6868
{aliases}
6969
- D = resolution
7070
- J = projection
71+
- c = panel
7172
7273
Parameters
7374
----------
@@ -227,7 +228,10 @@ def coast(
227228
},
228229
),
229230
J=Alias(projection, name="projection"),
230-
).merge(kwargs)
231+
).add_common(
232+
c=panel,
233+
)
234+
aliasdict.merge(kwargs)
231235

232236
with Session() as lib:
233237
lib.call_module(module="coast", args=build_arg_list(aliasdict))

pygmt/src/colorbar.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323
V="verbose",
2424
W="scale",
2525
Z="zfile",
26-
c="panel",
2726
p="perspective",
2827
t="transparency",
2928
)
30-
@kwargs_to_strings(
31-
R="sequence", G="sequence", I="sequence", c="sequence_comma", p="sequence"
32-
)
33-
def colorbar(self, projection=None, **kwargs):
29+
@kwargs_to_strings(R="sequence", G="sequence", I="sequence", p="sequence")
30+
def colorbar(
31+
self, projection=None, panel: int | tuple[int, int] | bool = False, **kwargs
32+
):
3433
r"""
3534
Plot gray scale or color scale bar.
3635
@@ -46,6 +45,7 @@ def colorbar(self, projection=None, **kwargs):
4645
4746
{aliases}
4847
- J = projection
48+
- c = panel
4949
5050
Parameters
5151
----------
@@ -149,6 +149,10 @@ def colorbar(self, projection=None, **kwargs):
149149

150150
aliasdict = AliasSystem(
151151
J=Alias(projection, name="projection"),
152-
).merge(kwargs)
152+
).add_common(
153+
c=panel,
154+
)
155+
aliasdict.merge(kwargs)
156+
153157
with Session() as lib:
154158
lib.call_module(module="colorbar", args=build_arg_list(aliasdict))

pygmt/src/contour.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
V="verbose",
2828
W="pen",
2929
b="binary",
30-
c="panel",
3130
d="nodata",
3231
e="find",
3332
f="coltypes",
@@ -37,14 +36,15 @@
3736
p="perspective",
3837
t="transparency",
3938
)
40-
@kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence")
39+
@kwargs_to_strings(R="sequence", i="sequence_comma", p="sequence")
4140
def contour(
4241
self,
4342
data: PathLike | TableLike | None = None,
4443
x=None,
4544
y=None,
4645
z=None,
4746
projection=None,
47+
panel: int | tuple[int, int] | bool = False,
4848
**kwargs,
4949
):
5050
r"""
@@ -59,6 +59,7 @@ def contour(
5959
6060
{aliases}
6161
- J = projection
62+
- c = panel
6263
6364
Parameters
6465
----------
@@ -155,7 +156,10 @@ def contour(
155156

156157
aliasdict = AliasSystem(
157158
J=Alias(projection, name="projection"),
158-
).merge(kwargs)
159+
).add_common(
160+
c=panel,
161+
)
162+
aliasdict.merge(kwargs)
159163

160164
with Session() as lib:
161165
with lib.virtualfile_in(

pygmt/src/grdcontour.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,18 @@
3232
V="verbose",
3333
W="pen",
3434
l="label",
35-
c="panel",
3635
f="coltypes",
3736
p="perspective",
3837
t="transparency",
3938
)
40-
@kwargs_to_strings(R="sequence", L="sequence", c="sequence_comma", p="sequence")
41-
def grdcontour(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):
39+
@kwargs_to_strings(R="sequence", L="sequence", p="sequence")
40+
def grdcontour(
41+
self,
42+
grid: PathLike | xr.DataArray,
43+
projection=None,
44+
panel: int | tuple[int, int] | bool = False,
45+
**kwargs,
46+
):
4247
r"""
4348
Make contour map using a grid.
4449
@@ -48,6 +53,7 @@ def grdcontour(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):
4853
4954
{aliases}
5055
- J = projection
56+
- c = panel
5157
5258
Parameters
5359
----------
@@ -154,7 +160,10 @@ def grdcontour(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):
154160

155161
aliasdict = AliasSystem(
156162
J=Alias(projection, name="projection"),
157-
).merge(kwargs)
163+
).add_common(
164+
c=panel,
165+
)
166+
aliasdict.merge(kwargs)
158167

159168
with Session() as lib:
160169
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:

pygmt/src/grdimage.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,19 @@
3131
R="region",
3232
V="verbose",
3333
n="interpolation",
34-
c="panel",
3534
f="coltypes",
3635
p="perspective",
3736
t="transparency",
3837
x="cores",
3938
)
40-
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
41-
def grdimage(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):
39+
@kwargs_to_strings(R="sequence", p="sequence")
40+
def grdimage(
41+
self,
42+
grid: PathLike | xr.DataArray,
43+
projection=None,
44+
panel: int | tuple[int, int] | bool = False,
45+
**kwargs,
46+
):
4247
r"""
4348
Project and plot grids or images.
4449
@@ -74,6 +79,7 @@ def grdimage(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):
7479
7580
{aliases}
7681
- J = projection
82+
- c = panel
7783
7884
Parameters
7985
----------
@@ -169,7 +175,10 @@ def grdimage(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):
169175

170176
aliasdict = AliasSystem(
171177
J=Alias(projection, name="projection"),
172-
).merge(kwargs)
178+
).add_common(
179+
c=panel,
180+
)
181+
aliasdict.merge(kwargs)
173182

174183
with Session() as lib:
175184
with (

pygmt/src/grdview.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,19 @@
2626
Wf="facadepen",
2727
I="shading",
2828
V="verbose",
29-
c="panel",
3029
f="coltypes",
3130
n="interpolation",
3231
p="perspective",
3332
t="transparency",
3433
)
35-
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
36-
def grdview(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):
34+
@kwargs_to_strings(R="sequence", p="sequence")
35+
def grdview(
36+
self,
37+
grid: PathLike | xr.DataArray,
38+
projection=None,
39+
panel: int | tuple[int, int] | bool = False,
40+
**kwargs,
41+
):
3742
r"""
3843
Create 3-D perspective image or surface mesh from a grid.
3944
@@ -47,6 +52,7 @@ def grdview(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):
4752
4853
{aliases}
4954
- J = projection
55+
- c = panel
5056
5157
Parameters
5258
----------
@@ -145,7 +151,10 @@ def grdview(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):
145151

146152
aliasdict = AliasSystem(
147153
J=Alias(projection, name="projection"),
148-
).merge(kwargs)
154+
).add_common(
155+
c=panel,
156+
)
157+
aliasdict.merge(kwargs)
149158

150159
with Session() as lib:
151160
with (

pygmt/src/histogram.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
W="pen",
2828
Z="histtype",
2929
b="binary",
30-
c="panel",
3130
d="nodata",
3231
e="find",
3332
h="header",
@@ -37,17 +36,22 @@
3736
t="transparency",
3837
w="wrap",
3938
)
40-
@kwargs_to_strings(
41-
R="sequence", T="sequence", c="sequence_comma", i="sequence_comma", p="sequence"
42-
)
43-
def histogram(self, data: PathLike | TableLike, projection=None, **kwargs):
39+
@kwargs_to_strings(R="sequence", T="sequence", i="sequence_comma", p="sequence")
40+
def histogram(
41+
self,
42+
data: PathLike | TableLike,
43+
projection=None,
44+
panel: int | tuple[int, int] | bool = False,
45+
**kwargs,
46+
):
4447
r"""
4548
Calculate and plot histograms.
4649
4750
Full GMT docs at :gmt-docs:`histogram.html`.
4851
4952
{aliases}
5053
- J = projection
54+
- c = panel
5155
5256
Parameters
5357
----------
@@ -140,7 +144,10 @@ def histogram(self, data: PathLike | TableLike, projection=None, **kwargs):
140144

141145
aliasdict = AliasSystem(
142146
J=Alias(projection, name="projection"),
143-
).merge(kwargs)
147+
).add_common(
148+
c=panel,
149+
)
150+
aliasdict.merge(kwargs)
144151

145152
with Session() as lib:
146153
with lib.virtualfile_in(check_kind="vector", data=data) as vintbl:

0 commit comments

Comments
 (0)