Skip to content

Commit d998e7a

Browse files
authored
Migrate the 'projection' parameter to the new alias system (#4024)
1 parent 36cd86e commit d998e7a

26 files changed

+256
-76
lines changed

pygmt/src/basemap.py

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

5+
from pygmt.alias import Alias, AliasSystem
56
from pygmt.clib import Session
67
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
78

89

910
@fmt_docstring
1011
@use_alias(
1112
R="region",
12-
J="projection",
1313
Jz="zscale",
1414
JZ="zsize",
1515
B="frame",
@@ -24,7 +24,7 @@
2424
t="transparency",
2525
)
2626
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
27-
def basemap(self, **kwargs):
27+
def basemap(self, projection=None, **kwargs):
2828
r"""
2929
Plot base maps and frames.
3030
@@ -39,6 +39,7 @@ def basemap(self, **kwargs):
3939
Full GMT docs at :gmt-docs:`basemap.html`.
4040
4141
{aliases}
42+
- J=projection
4243
4344
Parameters
4445
----------
@@ -83,5 +84,8 @@ def basemap(self, **kwargs):
8384
{transparency}
8485
"""
8586
self._activate_figure()
87+
aliasdict = AliasSystem(
88+
J=Alias(projection, name="projection"),
89+
).merge(kwargs)
8690
with Session() as lib:
87-
lib.call_module(module="basemap", args=build_arg_list(kwargs))
91+
lib.call_module(module="basemap", args=build_arg_list(aliasdict))

pygmt/src/coast.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from typing import Literal
66

7+
from pygmt.alias import Alias, AliasSystem
78
from pygmt.clib import Session
89
from pygmt.exceptions import GMTInvalidInput
910
from pygmt.helpers import (
@@ -28,7 +29,6 @@
2829
F="box",
2930
G="land",
3031
I="rivers",
31-
J="projection",
3232
L="map_scale",
3333
N="borders",
3434
R="region",
@@ -42,6 +42,7 @@
4242
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
4343
def coast(
4444
self,
45+
projection=None,
4546
resolution: Literal[
4647
"auto", "full", "high", "intermediate", "low", "crude", None
4748
] = None,
@@ -67,6 +68,7 @@ def coast(
6768
Full GMT docs at :gmt-docs:`coast.html`.
6869
6970
{aliases}
71+
- J=projection
7072
7173
Parameters
7274
----------
@@ -214,5 +216,9 @@ def coast(
214216

215217
kwargs["D"] = kwargs.get("D", _parse_coastline_resolution(resolution))
216218

219+
aliasdict = AliasSystem(
220+
J=Alias(projection, name="projection"),
221+
).merge(kwargs)
222+
217223
with Session() as lib:
218-
lib.call_module(module="coast", args=build_arg_list(kwargs))
224+
lib.call_module(module="coast", args=build_arg_list(aliasdict))

pygmt/src/colorbar.py

Lines changed: 8 additions & 3 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 pygmt.alias import Alias, AliasSystem
56
from pygmt.clib import Session
67
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
78

@@ -16,7 +17,6 @@
1617
F="box",
1718
G="truncate",
1819
I="shading",
19-
J="projection",
2020
L="equalsize",
2121
Q="log",
2222
R="region",
@@ -30,7 +30,7 @@
3030
@kwargs_to_strings(
3131
R="sequence", G="sequence", I="sequence", c="sequence_comma", p="sequence"
3232
)
33-
def colorbar(self, **kwargs):
33+
def colorbar(self, projection=None, **kwargs):
3434
r"""
3535
Plot gray scale or color scale bar.
3636
@@ -45,6 +45,7 @@ def colorbar(self, **kwargs):
4545
Full GMT docs at :gmt-docs:`colorbar.html`.
4646
4747
{aliases}
48+
- J=projection
4849
4950
Parameters
5051
----------
@@ -145,5 +146,9 @@ def colorbar(self, **kwargs):
145146
>>> fig.show()
146147
"""
147148
self._activate_figure()
149+
150+
aliasdict = AliasSystem(
151+
J=Alias(projection, name="projection"),
152+
).merge(kwargs)
148153
with Session() as lib:
149-
lib.call_module(module="colorbar", args=build_arg_list(kwargs))
154+
lib.call_module(module="colorbar", args=build_arg_list(aliasdict))

pygmt/src/contour.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
from pygmt._typing import PathLike, TableLike
6+
from pygmt.alias import Alias, AliasSystem
67
from pygmt.clib import Session
78
from pygmt.helpers import (
89
build_arg_list,
@@ -19,7 +20,6 @@
1920
B="frame",
2021
C="levels",
2122
G="label_placement",
22-
J="projection",
2323
L="triangular_mesh_pen",
2424
N="no_clip",
2525
R="region",
@@ -39,7 +39,13 @@
3939
)
4040
@kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence")
4141
def contour(
42-
self, data: PathLike | TableLike | None = None, x=None, y=None, z=None, **kwargs
42+
self,
43+
data: PathLike | TableLike | None = None,
44+
x=None,
45+
y=None,
46+
z=None,
47+
projection=None,
48+
**kwargs,
4349
):
4450
r"""
4551
Contour table data by direct triangulation.
@@ -52,6 +58,7 @@ def contour(
5258
Full GMT docs at :gmt-docs:`contour.html`.
5359
5460
{aliases}
61+
- J=projection
5562
5663
Parameters
5764
----------
@@ -146,10 +153,14 @@ def contour(
146153
else: # Multiple levels
147154
kwargs[arg] = ",".join(f"{item}" for item in kwargs[arg])
148155

156+
aliasdict = AliasSystem(
157+
J=Alias(projection, name="projection"),
158+
).merge(kwargs)
159+
149160
with Session() as lib:
150161
with lib.virtualfile_in(
151162
check_kind="vector", data=data, x=x, y=y, z=z, mincols=3
152163
) as vintbl:
153164
lib.call_module(
154-
module="contour", args=build_arg_list(kwargs, infile=vintbl)
165+
module="contour", args=build_arg_list(aliasdict, infile=vintbl)
155166
)

pygmt/src/grdcontour.py

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

55
import xarray as xr
66
from pygmt._typing import PathLike
7+
from pygmt.alias import Alias, AliasSystem
78
from pygmt.clib import Session
89
from pygmt.helpers import (
910
build_arg_list,
@@ -24,7 +25,6 @@
2425
B="frame",
2526
C="levels",
2627
G="label_placement",
27-
J="projection",
2828
L="limit",
2929
Q="cut",
3030
R="region",
@@ -38,7 +38,7 @@
3838
t="transparency",
3939
)
4040
@kwargs_to_strings(R="sequence", L="sequence", c="sequence_comma", p="sequence")
41-
def grdcontour(self, grid: PathLike | xr.DataArray, **kwargs):
41+
def grdcontour(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):
4242
r"""
4343
Make contour map using a grid.
4444
@@ -47,6 +47,7 @@ def grdcontour(self, grid: PathLike | xr.DataArray, **kwargs):
4747
Full GMT docs at :gmt-docs:`grdcontour.html`.
4848
4949
{aliases}
50+
- J=projection
5051
5152
Parameters
5253
----------
@@ -151,8 +152,12 @@ def grdcontour(self, grid: PathLike | xr.DataArray, **kwargs):
151152
else: # Multiple levels
152153
kwargs[arg] = ",".join(f"{item}" for item in kwargs[arg])
153154

155+
aliasdict = AliasSystem(
156+
J=Alias(projection, name="projection"),
157+
).merge(kwargs)
158+
154159
with Session() as lib:
155160
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
156161
lib.call_module(
157-
module="grdcontour", args=build_arg_list(kwargs, infile=vingrd)
162+
module="grdcontour", args=build_arg_list(aliasdict, infile=vingrd)
158163
)

pygmt/src/grdcut.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import xarray as xr
88
from pygmt._typing import PathLike
9+
from pygmt.alias import Alias, AliasSystem
910
from pygmt.clib import Session
1011
from pygmt.exceptions import GMTTypeError, GMTValueError
1112
from pygmt.helpers import (
@@ -22,7 +23,6 @@
2223
@fmt_docstring
2324
@use_alias(
2425
R="region",
25-
J="projection",
2626
N="extend",
2727
S="circ_subregion",
2828
V="verbose",
@@ -34,6 +34,7 @@ def grdcut(
3434
grid: PathLike | xr.DataArray,
3535
kind: Literal["grid", "image"] = "grid",
3636
outgrid: PathLike | None = None,
37+
projection=None,
3738
**kwargs,
3839
) -> xr.DataArray | None:
3940
r"""
@@ -51,6 +52,7 @@ def grdcut(
5152
Full GMT docs at :gmt-docs:`grdcut.html`.
5253
5354
{aliases}
55+
- J=projection
5456
5557
Parameters
5658
----------
@@ -124,13 +126,19 @@ def grdcut(
124126
case _:
125127
raise GMTTypeError(type(grid))
126128

129+
aliasdict = AliasSystem(
130+
J=Alias(projection, name="projection"),
131+
).merge(kwargs)
132+
127133
with Session() as lib:
128134
with (
129135
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,
130136
lib.virtualfile_out(kind=outkind, fname=outgrid) as voutgrd,
131137
):
132-
kwargs["G"] = voutgrd
133-
lib.call_module(module="grdcut", args=build_arg_list(kwargs, infile=vingrd))
138+
aliasdict["G"] = voutgrd
139+
lib.call_module(
140+
module="grdcut", args=build_arg_list(aliasdict, infile=vingrd)
141+
)
134142
return lib.virtualfile_to_raster(
135143
vfname=voutgrd, kind=outkind, outgrid=outgrid
136144
)

pygmt/src/grdimage.py

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

55
import xarray as xr
66
from pygmt._typing import PathLike
7+
from pygmt.alias import Alias, AliasSystem
78
from pygmt.clib import Session
89
from pygmt.exceptions import GMTInvalidInput
910
from pygmt.helpers import (
@@ -24,7 +25,6 @@
2425
E="dpi",
2526
G="bitcolor",
2627
I="shading",
27-
J="projection",
2828
M="monochrome",
2929
N="no_clip",
3030
Q="nan_transparent",
@@ -38,7 +38,7 @@
3838
x="cores",
3939
)
4040
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
41-
def grdimage(self, grid: PathLike | xr.DataArray, **kwargs):
41+
def grdimage(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):
4242
r"""
4343
Project and plot grids or images.
4444
@@ -73,6 +73,7 @@ def grdimage(self, grid: PathLike | xr.DataArray, **kwargs):
7373
Full GMT docs at :gmt-docs:`grdimage.html`.
7474
7575
{aliases}
76+
- J=projection
7677
7778
Parameters
7879
----------
@@ -166,14 +167,18 @@ def grdimage(self, grid: PathLike | xr.DataArray, **kwargs):
166167
)
167168
raise GMTInvalidInput(msg)
168169

170+
aliasdict = AliasSystem(
171+
J=Alias(projection, name="projection"),
172+
).merge(kwargs)
173+
169174
with Session() as lib:
170175
with (
171176
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,
172177
lib.virtualfile_in(
173178
check_kind="raster", data=kwargs.get("I"), required=False
174179
) as vshadegrid,
175180
):
176-
kwargs["I"] = vshadegrid
181+
aliasdict["I"] = vshadegrid
177182
lib.call_module(
178-
module="grdimage", args=build_arg_list(kwargs, infile=vingrd)
183+
module="grdimage", args=build_arg_list(aliasdict, infile=vingrd)
179184
)

0 commit comments

Comments
 (0)