Skip to content

Commit dc6fd38

Browse files
seismanyvonnefroehlichweiji14
authored
AliasSystem: Migrate the 'perspective' parameter to the new alias system (#4206)
Co-authored-by: Yvonne Fröhlich <[email protected]> Co-authored-by: Wei Ji <[email protected]>
1 parent 0c8f194 commit dc6fd38

23 files changed

+114
-76
lines changed

pygmt/alias.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ def add_common(self, **kwargs):
335335
name="registration",
336336
mapping={"gridline": "g", "pixel": "p"},
337337
)
338+
case "p":
339+
alias = Alias(value, name="perspective", sep="/", size={2, 3})
338340
case "t":
339341
alias = Alias(value, name="transparency")
340342
case "x":

pygmt/helpers/decorators.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,25 @@
262262
pen : str
263263
Set pen attributes for lines or the outline of symbols.""",
264264
"perspective": r"""
265-
perspective : list or str
266-
[**x**\|\ **y**\|\ **z**]\ *azim*\[/*elev*\[/*zlevel*]]\
267-
[**+w**\ *lon0*/*lat0*\[/*z0*]][**+v**\ *x0*/*y0*].
268-
Select perspective view and set the azimuth and elevation angle of
269-
the viewpoint [Default is ``[180, 90]``]. Full documentation is at
270-
:gmt-docs:`gmt.html#perspective-full`.""",
265+
perspective
266+
Select perspective view and set the azimuth and elevation of the viewpoint.
267+
268+
Accepts a single value or a sequence of two or three values: *azimuth*,
269+
(*azimuth*, *elevation*), or (*azimuth*, *elevation*, *zlevel*).
270+
271+
- *azimuth*: Azimuth angle of the viewpoint in degrees [Default is 180,
272+
i.e., looking from south to north].
273+
- *elevation*: Elevation angle of the viewpoint above the horizon [Default
274+
is 90, i.e., looking straight down at nadir].
275+
- *zlevel*: Z-level at which 2-D elements (e.g., the map frame) are drawn.
276+
Only applied when used together with ``zsize`` or ``zscale``. [Default is
277+
at the bottom of the z-axis].
278+
279+
Alternatively, set ``perspective=True`` to reuse the perspective setting
280+
from the previous plotting method, or pass a string following the full
281+
GMT syntax for finer control (e.g., adding ``+w`` or ``+v`` modifiers to
282+
select an axis location other than the plot origin). See
283+
:gmt-docs:`gmt.html#perspective-full` for details.""",
271284
"projection": r"""
272285
projection
273286
*projcode*\[*projparams*/]\ *width*\|\ *scale*.

pygmt/src/basemap.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pygmt.alias import Alias, AliasSystem
99
from pygmt.clib import Session
10-
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
10+
from pygmt.helpers import build_arg_list, fmt_docstring, use_alias
1111

1212

1313
@fmt_docstring
@@ -17,9 +17,7 @@
1717
Td="rose",
1818
Tm="compass",
1919
f="coltypes",
20-
p="perspective",
2120
)
22-
@kwargs_to_strings(p="sequence")
2321
def basemap(
2422
self,
2523
projection: str | None = None,
@@ -31,6 +29,7 @@ def basemap(
3129
| bool = False,
3230
panel: int | Sequence[int] | bool = False,
3331
transparency: float | None = None,
32+
perspective: float | Sequence[float] | str | bool = False,
3433
**kwargs,
3534
):
3635
r"""
@@ -54,6 +53,7 @@ def basemap(
5453
- R = region
5554
- V = verbose
5655
- c = panel
56+
- p = perspective
5757
- t = transparency
5858
5959
Parameters
@@ -109,6 +109,7 @@ def basemap(
109109
R=region,
110110
V=verbose,
111111
c=panel,
112+
p=perspective,
112113
t=transparency,
113114
)
114115
aliasdict.merge(kwargs)

pygmt/src/coast.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
args_in_kwargs,
1313
build_arg_list,
1414
fmt_docstring,
15-
kwargs_to_strings,
1615
use_alias,
1716
)
1817
from pygmt.params import Box
@@ -31,9 +30,7 @@
3130
N="borders",
3231
S="water",
3332
W="shorelines",
34-
p="perspective",
3533
)
36-
@kwargs_to_strings(p="sequence")
3734
def coast(
3835
self,
3936
resolution: Literal[
@@ -47,6 +44,7 @@ def coast(
4744
| bool = False,
4845
panel: int | Sequence[int] | bool = False,
4946
transparency: float | None = None,
47+
perspective: float | Sequence[float] | str | bool = False,
5048
**kwargs,
5149
):
5250
r"""
@@ -76,6 +74,7 @@ def coast(
7674
- R = region
7775
- V = verbose
7876
- c = panel
77+
- p = perspective
7978
- t = transparency
8079
8180
Parameters
@@ -229,6 +228,7 @@ def coast(
229228
R=region,
230229
V=verbose,
231230
c=panel,
231+
p=perspective,
232232
t=transparency,
233233
)
234234
aliasdict.merge(kwargs)

pygmt/src/colorbar.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,9 @@
1515

1616
@fmt_docstring
1717
@use_alias(
18-
C="cmap",
19-
D="position",
20-
G="truncate",
21-
L="equalsize",
22-
Q="log",
23-
W="scale",
24-
Z="zfile",
25-
p="perspective",
18+
C="cmap", D="position", G="truncate", L="equalsize", Q="log", W="scale", Z="zfile"
2619
)
27-
@kwargs_to_strings(G="sequence", I="sequence", p="sequence")
20+
@kwargs_to_strings(G="sequence", I="sequence")
2821
def colorbar(
2922
self,
3023
shading: float | Sequence[float] | bool = False,
@@ -36,6 +29,7 @@ def colorbar(
3629
| bool = False,
3730
panel: int | Sequence[int] | bool = False,
3831
transparency: float | None = None,
32+
perspective: float | Sequence[float] | str | bool = False,
3933
**kwargs,
4034
):
4135
r"""
@@ -70,6 +64,7 @@ def colorbar(
7064
- R = region
7165
- V = verbose
7266
- c = panel
67+
- p = perspective
7368
- t = transparency
7469
7570
Parameters
@@ -173,6 +168,7 @@ def colorbar(
173168
R=region,
174169
V=verbose,
175170
c=panel,
171+
p=perspective,
176172
t=transparency,
177173
)
178174
aliasdict.merge(kwargs)

pygmt/src/contour.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@
3232
h="header",
3333
i="incols",
3434
l="label",
35-
p="perspective",
3635
)
37-
@kwargs_to_strings(i="sequence_comma", p="sequence")
36+
@kwargs_to_strings(i="sequence_comma")
3837
def contour( # noqa: PLR0913
3938
self,
4039
data: PathLike | TableLike | None = None,
@@ -49,6 +48,7 @@ def contour( # noqa: PLR0913
4948
| bool = False,
5049
panel: int | Sequence[int] | bool = False,
5150
transparency: float | None = None,
51+
perspective: float | Sequence[float] | str | bool = False,
5252
**kwargs,
5353
):
5454
r"""
@@ -68,6 +68,7 @@ def contour( # noqa: PLR0913
6868
- R = region
6969
- V = verbose
7070
- c = panel
71+
- p = perspective
7172
- t = transparency
7273
7374
Parameters
@@ -171,6 +172,7 @@ def contour( # noqa: PLR0913
171172
R=region,
172173
V=verbose,
173174
c=panel,
175+
p=perspective,
174176
t=transparency,
175177
)
176178
aliasdict.merge(kwargs)

pygmt/src/grdcontour.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@
3333
W="pen",
3434
l="label",
3535
f="coltypes",
36-
p="perspective",
3736
)
38-
@kwargs_to_strings(L="sequence", p="sequence")
37+
@kwargs_to_strings(L="sequence")
3938
def grdcontour(
4039
self,
4140
grid: PathLike | xr.DataArray,
@@ -46,6 +45,7 @@ def grdcontour(
4645
| bool = False,
4746
panel: int | Sequence[int] | bool = False,
4847
transparency: float | None = None,
48+
perspective: float | Sequence[float] | str | bool = False,
4949
**kwargs,
5050
):
5151
r"""
@@ -61,6 +61,7 @@ def grdcontour(
6161
- R = region
6262
- V = verbose
6363
- c = panel
64+
- p = perspective
6465
- t = transparency
6566
6667
Parameters
@@ -172,6 +173,7 @@ def grdcontour(
172173
R=region,
173174
V=verbose,
174175
c=panel,
176+
p=perspective,
175177
t=transparency,
176178
)
177179
aliasdict.merge(kwargs)

pygmt/src/grdimage.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
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
__doctest_skip__ = ["grdimage"]
1515

@@ -24,9 +24,7 @@
2424
Q="nan_transparent",
2525
n="interpolation",
2626
f="coltypes",
27-
p="perspective",
2827
)
29-
@kwargs_to_strings(p="sequence")
3028
def grdimage( # noqa: PLR0913
3129
self,
3230
grid: PathLike | xr.DataArray,
@@ -39,6 +37,7 @@ def grdimage( # noqa: PLR0913
3937
| bool = False,
4038
panel: int | Sequence[int] | bool = False,
4139
transparency: float | None = None,
40+
perspective: float | Sequence[float] | str | bool = False,
4241
cores: int | bool = False,
4342
**kwargs,
4443
):
@@ -83,6 +82,7 @@ def grdimage( # noqa: PLR0913
8382
- R = region
8483
- V = verbose
8584
- c = panel
85+
- p = perspective
8686
- t = transparency
8787
- x = cores
8888
@@ -187,6 +187,7 @@ def grdimage( # noqa: PLR0913
187187
R=region,
188188
V=verbose,
189189
c=panel,
190+
p=perspective,
190191
t=transparency,
191192
x=cores,
192193
)

pygmt/src/grdview.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
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
__doctest_skip__ = ["grdview"]
1515

@@ -26,10 +26,8 @@
2626
I="shading",
2727
f="coltypes",
2828
n="interpolation",
29-
p="perspective",
3029
)
31-
@kwargs_to_strings(p="sequence")
32-
def grdview(
30+
def grdview( # noqa: PLR0913
3331
self,
3432
grid: PathLike | xr.DataArray,
3533
projection: str | None = None,
@@ -41,6 +39,7 @@ def grdview(
4139
| bool = False,
4240
panel: int | Sequence[int] | bool = False,
4341
transparency: float | None = None,
42+
perspective: float | Sequence[float] | str | bool = False,
4443
**kwargs,
4544
):
4645
r"""
@@ -62,6 +61,7 @@ def grdview(
6261
- R = region
6362
- V = verbose
6463
- c = panel
64+
- p = perspective
6565
- t = transparency
6666
6767
Parameters
@@ -168,6 +168,7 @@ def grdview(
168168
R=region,
169169
V=verbose,
170170
c=panel,
171+
p=perspective,
171172
t=transparency,
172173
)
173174
aliasdict.merge(kwargs)

pygmt/src/histogram.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@
3232
h="header",
3333
i="incols",
3434
l="label",
35-
p="perspective",
3635
w="wrap",
3736
)
38-
@kwargs_to_strings(T="sequence", i="sequence_comma", p="sequence")
37+
@kwargs_to_strings(T="sequence", i="sequence_comma")
3938
def histogram(
4039
self,
4140
data: PathLike | TableLike,
@@ -46,6 +45,7 @@ def histogram(
4645
| bool = False,
4746
panel: int | Sequence[int] | bool = False,
4847
transparency: float | None = None,
48+
perspective: float | Sequence[float] | str | bool = False,
4949
**kwargs,
5050
):
5151
r"""
@@ -59,6 +59,7 @@ def histogram(
5959
- R = region
6060
- V = verbose
6161
- c = panel
62+
- p = perspective
6263
- t = transparency
6364
6465
Parameters
@@ -156,6 +157,7 @@ def histogram(
156157
R=region,
157158
V=verbose,
158159
c=panel,
160+
p=perspective,
159161
t=transparency,
160162
)
161163
aliasdict.merge(kwargs)

0 commit comments

Comments
 (0)