Skip to content

Commit 00d17f4

Browse files
committed
Improve the code structure
1 parent 3aaf44a commit 00d17f4

File tree

7 files changed

+99
-75
lines changed

7 files changed

+99
-75
lines changed

pygmt/src/basemap.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,14 @@ def basemap(self, frame=None, **kwargs):
8282
{perspective}
8383
{transparency}
8484
"""
85-
alias = AliasSystem(
86-
B=Alias(frame),
87-
)
8885
kwargs = self._preprocess(**kwargs)
86+
87+
kwdict = (
88+
AliasSystem(
89+
B=Alias(frame),
90+
).kwdict
91+
| kwargs
92+
)
93+
8994
with Session() as lib:
90-
lib.call_module(module="basemap", args=build_arg_list(alias.kwdict | kwargs))
95+
lib.call_module(module="basemap", args=build_arg_list(kwdict))

pygmt/src/binstats.py

+27-24
Original file line numberDiff line numberDiff line change
@@ -109,34 +109,37 @@ def binstats(
109109
- ``None`` if ``outgrid`` is set (grid output will be stored in the file set by
110110
``outgrid``)
111111
"""
112-
alias = AliasSystem(
113-
C=Alias(
114-
statistic,
115-
mapping={
116-
"mean": "a",
117-
"mad": "d",
118-
"full": "g",
119-
"interquartile": "i",
120-
"min": "l",
121-
"minpos": "L",
122-
"median": "m",
123-
"number": "n",
124-
"lms": "o",
125-
"mode": "p",
126-
"quantile": "q",
127-
"rms": "r",
128-
"stddev": "s",
129-
"max": "u",
130-
"maxneg": "U",
131-
"sum": "z",
132-
},
133-
),
134-
G=Alias(outgrid),
112+
kwdict = (
113+
AliasSystem(
114+
C=Alias(
115+
statistic,
116+
mapping={
117+
"mean": "a",
118+
"mad": "d",
119+
"full": "g",
120+
"interquartile": "i",
121+
"min": "l",
122+
"minpos": "L",
123+
"median": "m",
124+
"number": "n",
125+
"lms": "o",
126+
"mode": "p",
127+
"quantile": "q",
128+
"rms": "r",
129+
"stddev": "s",
130+
"max": "u",
131+
"maxneg": "U",
132+
"sum": "z",
133+
},
134+
),
135+
G=Alias(outgrid),
136+
).kwdict
137+
| kwargs
135138
)
139+
136140
if statistic == "quantile":
137141
statistic += str(quantile_value)
138142

139-
kwdict = alias.kwdict | kwargs
140143
with Session() as lib:
141144
with (
142145
lib.virtualfile_in(check_kind="vector", data=data) as vintbl,

pygmt/src/coast.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,20 @@ def coast(
210210
>>> # Show the plot
211211
>>> fig.show()
212212
"""
213-
alias = AliasSystem(
214-
D=Alias(resolution, mapping=True),
215-
)
216213
kwargs = self._preprocess(**kwargs)
217214
if not args_in_kwargs(args=["C", "G", "S", "I", "N", "E", "Q", "W"], kwargs=kwargs):
218215
msg = (
219216
"At least one of the following parameters must be specified: "
220217
"lakes, land, water, rivers, borders, dcw, Q, or shorelines."
221218
)
222219
raise GMTInvalidInput(msg)
220+
221+
kwdict = (
222+
AliasSystem(
223+
D=Alias(resolution, mapping=True),
224+
).kwdict
225+
| kwargs
226+
)
227+
223228
with Session() as lib:
224-
lib.call_module(module="coast", args=build_arg_list(alias.kwdict | kwargs))
229+
lib.call_module(module="coast", args=build_arg_list(kwdict))

pygmt/src/dimfilter.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,6 @@ def dimfilter(
134134
... region=[-55, -51, -24, -19],
135135
... )
136136
"""
137-
alias = AliasSystem(
138-
D=Alias(distance),
139-
G=Alias(outgrid),
140-
F=Alias(filter),
141-
I=Alias(spacing, separator="/"),
142-
N=Alias(sectors),
143-
R=Alias(region, separator="/"),
144-
V=Alias(verbose),
145-
)
146-
147137
if (
148138
not all(v is not None for v in [distance, filter, sectors])
149139
and "Q" not in kwargs
@@ -153,7 +143,20 @@ def dimfilter(
153143
"distance, filters, or sectors."
154144
)
155145
raise GMTInvalidInput(msg)
156-
kwdict = alias.kwdict | kwargs
146+
147+
kwdict = (
148+
AliasSystem(
149+
D=Alias(distance),
150+
G=Alias(outgrid),
151+
F=Alias(filter),
152+
I=Alias(spacing, separator="/"),
153+
N=Alias(sectors),
154+
R=Alias(region, separator="/"),
155+
V=Alias(verbose),
156+
).kwdict
157+
| kwargs
158+
)
159+
157160
with Session() as lib:
158161
with (
159162
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,

pygmt/src/image.py

+23-21
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,29 @@ def image( # noqa: PLR0913
7272
{perspective}
7373
{transparency}
7474
"""
75-
alias = AliasSystem(
76-
R=Alias(region, separator="/"),
77-
J=Alias(projection),
78-
D=[
79-
Alias(position, separator="/", prefix=position_type),
80-
Alias(dimension, prefix="+w", separator="/"),
81-
Alias(repeat, prefix="+n", separator="/"),
82-
Alias(offset, prefix="+o", separator="/"),
83-
Alias(dpi, prefix="+r"),
84-
],
85-
F=Alias(box),
86-
G=Alias(bitcolor),
87-
M=Alias(monochrome),
88-
V=Alias(verbose),
89-
c=Alias(panel, separator=","),
90-
p=Alias(perspective, separator="/"),
91-
t=Alias(transparency),
75+
kwargs = self._preprocess(**kwargs)
76+
77+
kwdict = (
78+
AliasSystem(
79+
R=Alias(region, separator="/"),
80+
J=Alias(projection),
81+
D=[
82+
Alias(position, separator="/", prefix=position_type),
83+
Alias(dimension, prefix="+w", separator="/"),
84+
Alias(repeat, prefix="+n", separator="/"),
85+
Alias(offset, prefix="+o", separator="/"),
86+
Alias(dpi, prefix="+r"),
87+
],
88+
F=Alias(box),
89+
G=Alias(bitcolor),
90+
M=Alias(monochrome),
91+
V=Alias(verbose),
92+
c=Alias(panel, separator=","),
93+
p=Alias(perspective, separator="/"),
94+
t=Alias(transparency),
95+
).kwdict
96+
| kwargs
9297
)
9398

94-
kwargs = self._preprocess(**kwargs)
9599
with Session() as lib:
96-
lib.call_module(
97-
module="image", args=build_arg_list(alias.kwdict | kwargs, infile=imagefile)
98-
)
100+
lib.call_module(module="image", args=build_arg_list(kwdict, infile=imagefile))

pygmt/src/logo.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,20 @@ def logo(
6363
{panel}
6464
{transparency}
6565
"""
66-
alias = AliasSystem(
67-
D=[
68-
Alias(position, separator="/", prefix=position_type),
69-
Alias(length, prefix="+w"),
70-
Alias(height, prefix="+h"),
71-
Alias(offset, prefix="+o", separator="/"),
72-
],
73-
F=Alias(box),
74-
)
7566
kwargs = self._preprocess(**kwargs)
67+
68+
kwdict = (
69+
AliasSystem(
70+
D=[
71+
Alias(position, separator="/", prefix=position_type),
72+
Alias(length, prefix="+w"),
73+
Alias(height, prefix="+h"),
74+
Alias(offset, prefix="+o", separator="/"),
75+
],
76+
F=Alias(box),
77+
).kwdict
78+
| kwargs
79+
)
80+
7681
with Session() as lib:
77-
lib.call_module(module="logo", args=build_arg_list(alias.kwdict | kwargs))
82+
lib.call_module(module="logo", args=build_arg_list(kwdict))

pygmt/src/scalebar.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def scalebar( # noqa: PLR0913
4949
... )
5050
>>> fig.show()
5151
"""
52+
self._preprocess()
53+
5254
kwdict = AliasSystem(
5355
L=[
5456
Alias(position, separator="/", prefix=position_type),
@@ -65,6 +67,5 @@ def scalebar( # noqa: PLR0913
6567
F=Alias(box),
6668
).kwdict
6769

68-
self._preprocess()
6970
with Session() as lib:
7071
lib.call_module(module="basemap", args=build_arg_list(kwdict))

0 commit comments

Comments
 (0)