Skip to content

Commit 2e7339d

Browse files
committed
Improve code structure
1 parent 1ca7382 commit 2e7339d

File tree

7 files changed

+35
-24
lines changed

7 files changed

+35
-24
lines changed

pygmt/src/basemap.py

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

pygmt/src/binstats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ def binstats(
135135
)
136136
if statistic == "quantile":
137137
statistic += str(quantile_value)
138-
139138
kwdict = alias.kwdict | kwargs
139+
140140
with Session() as lib:
141141
with (
142142
lib.virtualfile_in(check_kind="vector", data=data) as vintbl,

pygmt/src/coast.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,18 @@ 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+
alias = AliasSystem(
222+
D=Alias(resolution, mapping=True),
223+
)
224+
kwdict = alias.kwdict | kwargs
225+
223226
with Session() as lib:
224-
lib.call_module(module="coast", args=build_arg_list(alias.kwdict | kwargs))
227+
lib.call_module(module="coast", args=build_arg_list(kwdict))

pygmt/src/dimfilter.py

Lines changed: 11 additions & 10 deletions
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,18 @@ def dimfilter(
153143
"distance, filters, or sectors."
154144
)
155145
raise GMTInvalidInput(msg)
146+
147+
alias = AliasSystem(
148+
D=Alias(distance),
149+
G=Alias(outgrid),
150+
F=Alias(filter),
151+
I=Alias(spacing, separator="/"),
152+
N=Alias(sectors),
153+
R=Alias(region, separator="/"),
154+
V=Alias(verbose),
155+
)
156156
kwdict = alias.kwdict | kwargs
157+
157158
with Session() as lib:
158159
with (
159160
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,

pygmt/src/image.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def image( # noqa: PLR0913
7272
{perspective}
7373
{transparency}
7474
"""
75+
kwargs = self._preprocess(**kwargs)
76+
7577
alias = AliasSystem(
7678
R=Alias(region, separator="/"),
7779
J=Alias(projection),
@@ -90,9 +92,7 @@ def image( # noqa: PLR0913
9092
p=Alias(perspective, separator="/"),
9193
t=Alias(transparency),
9294
)
95+
kwdict = alias.kwdict | kwargs
9396

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

pygmt/src/logo.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def logo(
6464
{panel}
6565
{transparency}
6666
"""
67+
kwargs = self._preprocess(**kwargs)
68+
6769
alias = AliasSystem(
6870
D=[
6971
Alias(position, separator="/", prefix=position_type),
@@ -73,6 +75,7 @@ def logo(
7375
],
7476
F=Alias(box),
7577
)
76-
kwargs = self._preprocess(**kwargs)
78+
kwdict = alias.kwdict | kwargs
79+
7780
with Session() as lib:
78-
lib.call_module(module="logo", args=build_arg_list(alias.kwdict | kwargs))
81+
lib.call_module(module="logo", args=build_arg_list(kwdict))

pygmt/src/scalebar.py

Lines changed: 2 additions & 1 deletion
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)