Skip to content

Commit f963123

Browse files
committed
Figure.image: Refactor to use the new alias system
1 parent 4ed02dd commit f963123

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

pygmt/src/image.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,12 @@
22
image - Plot an image.
33
"""
44

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

89

910
@fmt_docstring
10-
@use_alias(
11-
D="position",
12-
F="box",
13-
G="bitcolor",
14-
J="projection",
15-
M="monochrome",
16-
R="region",
17-
V="verbose",
18-
c="panel",
19-
p="perspective",
20-
t="transparency",
21-
)
22-
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
2311
def image(self, imagefile, **kwargs):
2412
r"""
2513
Place images or EPS files on maps.
@@ -29,8 +17,6 @@ def image(self, imagefile, **kwargs):
2917
3018
Full option list at :gmt-docs:`image.html`
3119
32-
{aliases}
33-
3420
Parameters
3521
----------
3622
imagefile : str
@@ -67,6 +53,21 @@ def image(self, imagefile, **kwargs):
6753
{perspective}
6854
{transparency}
6955
"""
56+
alias = AliasSystem(
57+
R=Alias("region", separator="/"),
58+
J="projection",
59+
D="position",
60+
F="box",
61+
G="bitcolor",
62+
M="monochrome",
63+
V="verbose",
64+
c=Alias("panel", separator=","),
65+
p=Alias("perspective", separator="/"),
66+
t="transparency",
67+
)
68+
7069
kwargs = self._preprocess(**kwargs)
7170
with Session() as lib:
72-
lib.call_module(module="image", args=build_arg_list(kwargs, infile=imagefile))
71+
lib.call_module(
72+
module="image", args=build_arg_list(alias.kwdict, infile=imagefile)
73+
)

pygmt/tests/test_image.py

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

55
import pytest
66
from pygmt import Figure
7+
from pygmt.params import Box
78

89

910
@pytest.mark.mpl_image_compare
@@ -12,5 +13,5 @@ def test_image():
1213
Place images on map.
1314
"""
1415
fig = Figure()
15-
fig.image(imagefile="@circuit.png", position="x0/0+w2c", box="+pthin,blue")
16+
fig.image(imagefile="@circuit.png", position="x0/0+w2c", box=Box(pen="thin,blue"))
1617
return fig

0 commit comments

Comments
 (0)