Skip to content

Commit 1ca7382

Browse files
committed
Revert "Improve the code structure"
This reverts commit 00d17f4.
1 parent fb916cf commit 1ca7382

File tree

7 files changed

+75
-99
lines changed

7 files changed

+75
-99
lines changed

pygmt/src/basemap.py

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

pygmt/src/binstats.py

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -109,37 +109,34 @@ def binstats(
109109
- ``None`` if ``outgrid`` is set (grid output will be stored in the file set by
110110
``outgrid``)
111111
"""
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
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),
138135
)
139-
140136
if statistic == "quantile":
141137
statistic += str(quantile_value)
142138

139+
kwdict = alias.kwdict | kwargs
143140
with Session() as lib:
144141
with (
145142
lib.virtualfile_in(check_kind="vector", data=data) as vintbl,

pygmt/src/coast.py

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

pygmt/src/dimfilter.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ 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+
137147
if (
138148
not all(v is not None for v in [distance, filter, sectors])
139149
and "Q" not in kwargs
@@ -143,20 +153,7 @@ def dimfilter(
143153
"distance, filters, or sectors."
144154
)
145155
raise GMTInvalidInput(msg)
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-
156+
kwdict = alias.kwdict | kwargs
160157
with Session() as lib:
161158
with (
162159
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,

pygmt/src/image.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,29 +72,27 @@ def image( # noqa: PLR0913
7272
{perspective}
7373
{transparency}
7474
"""
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
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),
9792
)
9893

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

pygmt/src/logo.py

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

pygmt/src/scalebar.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ def scalebar( # noqa: PLR0913
4949
... )
5050
>>> fig.show()
5151
"""
52-
self._preprocess()
53-
5452
kwdict = AliasSystem(
5553
L=[
5654
Alias(position, separator="/", prefix=position_type),
@@ -67,5 +65,6 @@ def scalebar( # noqa: PLR0913
6765
F=Alias(box),
6866
).kwdict
6967

68+
self._preprocess()
7069
with Session() as lib:
7170
lib.call_module(module="basemap", args=build_arg_list(kwdict))

0 commit comments

Comments
 (0)