Skip to content

Migrate the panel parameter to the new alias system #4030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions pygmt/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ class AliasSystem(UserDict):
... ],
... B=Alias(frame, name="frame"),
... D=Alias(repeat, name="repeat"),
... c=Alias(panel, name="panel", sep=","),
... ).merge(kwargs)
... ).add_common(
... c=panel,
... )
... aliasdict.merge(kwargs)
... return build_arg_list(aliasdict)
>>> func(
... "infile",
Expand Down Expand Up @@ -268,6 +270,21 @@ def __init__(self, **kwargs):
kwdict[option] = aliases._value
super().__init__(kwdict)

def add_common(self, **kwargs):
"""
Add common parameters to the alias dictionary.
"""
for key, value in kwargs.items():
match key:
case "c":
alias = Alias(value, name="panel", sep=",", size=2)
case _:
raise GMTValueError(key, description="common parameter")
self.aliasdict[key] = alias
if alias._value is not None:
self[key] = alias._value
return self

def merge(self, kwargs: Mapping[str, Any]):
"""
Update the dictionary with additional keyword arguments.
Expand Down
2 changes: 1 addition & 1 deletion pygmt/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
:gmt-docs:`gmt.html#grd-inout-full` for the available modifiers.
""",
"panel": r"""
panel : bool, int, or list
panel
Select a specific subplot panel. Only allowed when used in
:meth:`Figure.subplot` mode.

Expand Down
15 changes: 11 additions & 4 deletions pygmt/src/basemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
Td="rose",
Tm="compass",
V="verbose",
c="panel",
f="coltypes",
p="perspective",
t="transparency",
)
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
def basemap(self, projection=None, **kwargs):
@kwargs_to_strings(R="sequence", p="sequence")
def basemap(
self, projection=None, panel: int | tuple[int, int] | bool = False, **kwargs
):
r"""
Plot base maps and frames.

Expand All @@ -40,6 +41,7 @@ def basemap(self, projection=None, **kwargs):

{aliases}
- J = projection
- c = panel

Parameters
----------
Expand Down Expand Up @@ -84,8 +86,13 @@ def basemap(self, projection=None, **kwargs):
{transparency}
"""
self._activate_figure()

aliasdict = AliasSystem(
J=Alias(projection, name="projection"),
).merge(kwargs)
).add_common(
c=panel,
)
aliasdict.merge(kwargs)

with Session() as lib:
lib.call_module(module="basemap", args=build_arg_list(aliasdict))
10 changes: 7 additions & 3 deletions pygmt/src/coast.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
S="water",
V="verbose",
W="shorelines",
c="panel",
p="perspective",
t="transparency",
)
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
@kwargs_to_strings(R="sequence", p="sequence")
def coast(
self,
projection=None,
resolution: Literal[
"auto", "full", "high", "intermediate", "low", "crude", None
] = None,
panel: int | tuple[int, int] | bool = False,
**kwargs,
):
r"""
Expand All @@ -68,6 +68,7 @@ def coast(
{aliases}
- D = resolution
- J = projection
- c = panel

Parameters
----------
Expand Down Expand Up @@ -227,7 +228,10 @@ def coast(
},
),
J=Alias(projection, name="projection"),
).merge(kwargs)
).add_common(
c=panel,
)
aliasdict.merge(kwargs)

with Session() as lib:
lib.call_module(module="coast", args=build_arg_list(aliasdict))
16 changes: 10 additions & 6 deletions pygmt/src/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
V="verbose",
W="scale",
Z="zfile",
c="panel",
p="perspective",
t="transparency",
)
@kwargs_to_strings(
R="sequence", G="sequence", I="sequence", c="sequence_comma", p="sequence"
)
def colorbar(self, projection=None, **kwargs):
@kwargs_to_strings(R="sequence", G="sequence", I="sequence", p="sequence")
def colorbar(
self, projection=None, panel: int | tuple[int, int] | bool = False, **kwargs
):
r"""
Plot gray scale or color scale bar.

Expand All @@ -46,6 +45,7 @@ def colorbar(self, projection=None, **kwargs):

{aliases}
- J = projection
- c = panel

Parameters
----------
Expand Down Expand Up @@ -149,6 +149,10 @@ def colorbar(self, projection=None, **kwargs):

aliasdict = AliasSystem(
J=Alias(projection, name="projection"),
).merge(kwargs)
).add_common(
c=panel,
)
aliasdict.merge(kwargs)

with Session() as lib:
lib.call_module(module="colorbar", args=build_arg_list(aliasdict))
10 changes: 7 additions & 3 deletions pygmt/src/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
V="verbose",
W="pen",
b="binary",
c="panel",
d="nodata",
e="find",
f="coltypes",
Expand All @@ -37,14 +36,15 @@
p="perspective",
t="transparency",
)
@kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence")
@kwargs_to_strings(R="sequence", i="sequence_comma", p="sequence")
def contour(
self,
data: PathLike | TableLike | None = None,
x=None,
y=None,
z=None,
projection=None,
panel: int | tuple[int, int] | bool = False,
**kwargs,
):
r"""
Expand All @@ -59,6 +59,7 @@ def contour(

{aliases}
- J = projection
- c = panel

Parameters
----------
Expand Down Expand Up @@ -155,7 +156,10 @@ def contour(

aliasdict = AliasSystem(
J=Alias(projection, name="projection"),
).merge(kwargs)
).add_common(
c=panel,
)
aliasdict.merge(kwargs)

with Session() as lib:
with lib.virtualfile_in(
Expand Down
17 changes: 13 additions & 4 deletions pygmt/src/grdcontour.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@
V="verbose",
W="pen",
l="label",
c="panel",
f="coltypes",
p="perspective",
t="transparency",
)
@kwargs_to_strings(R="sequence", L="sequence", c="sequence_comma", p="sequence")
def grdcontour(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):
@kwargs_to_strings(R="sequence", L="sequence", p="sequence")
def grdcontour(
self,
grid: PathLike | xr.DataArray,
projection=None,
panel: int | tuple[int, int] | bool = False,
**kwargs,
):
r"""
Make contour map using a grid.

Expand All @@ -48,6 +53,7 @@ def grdcontour(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):

{aliases}
- J = projection
- c = panel

Parameters
----------
Expand Down Expand Up @@ -154,7 +160,10 @@ def grdcontour(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):

aliasdict = AliasSystem(
J=Alias(projection, name="projection"),
).merge(kwargs)
).add_common(
c=panel,
)
aliasdict.merge(kwargs)

with Session() as lib:
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
Expand Down
17 changes: 13 additions & 4 deletions pygmt/src/grdimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@
R="region",
V="verbose",
n="interpolation",
c="panel",
f="coltypes",
p="perspective",
t="transparency",
x="cores",
)
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
def grdimage(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):
@kwargs_to_strings(R="sequence", p="sequence")
def grdimage(
self,
grid: PathLike | xr.DataArray,
projection=None,
panel: int | tuple[int, int] | bool = False,
**kwargs,
):
r"""
Project and plot grids or images.

Expand Down Expand Up @@ -74,6 +79,7 @@ def grdimage(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):

{aliases}
- J = projection
- c = panel

Parameters
----------
Expand Down Expand Up @@ -169,7 +175,10 @@ def grdimage(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):

aliasdict = AliasSystem(
J=Alias(projection, name="projection"),
).merge(kwargs)
).add_common(
c=panel,
)
aliasdict.merge(kwargs)

with Session() as lib:
with (
Expand Down
17 changes: 13 additions & 4 deletions pygmt/src/grdview.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@
Wf="facadepen",
I="shading",
V="verbose",
c="panel",
f="coltypes",
n="interpolation",
p="perspective",
t="transparency",
)
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
def grdview(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):
@kwargs_to_strings(R="sequence", p="sequence")
def grdview(
self,
grid: PathLike | xr.DataArray,
projection=None,
panel: int | tuple[int, int] | bool = False,
**kwargs,
):
r"""
Create 3-D perspective image or surface mesh from a grid.

Expand All @@ -47,6 +52,7 @@ def grdview(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):

{aliases}
- J = projection
- c = panel

Parameters
----------
Expand Down Expand Up @@ -145,7 +151,10 @@ def grdview(self, grid: PathLike | xr.DataArray, projection=None, **kwargs):

aliasdict = AliasSystem(
J=Alias(projection, name="projection"),
).merge(kwargs)
).add_common(
c=panel,
)
aliasdict.merge(kwargs)

with Session() as lib:
with (
Expand Down
19 changes: 13 additions & 6 deletions pygmt/src/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
W="pen",
Z="histtype",
b="binary",
c="panel",
d="nodata",
e="find",
h="header",
Expand All @@ -37,17 +36,22 @@
t="transparency",
w="wrap",
)
@kwargs_to_strings(
R="sequence", T="sequence", c="sequence_comma", i="sequence_comma", p="sequence"
)
def histogram(self, data: PathLike | TableLike, projection=None, **kwargs):
@kwargs_to_strings(R="sequence", T="sequence", i="sequence_comma", p="sequence")
def histogram(
self,
data: PathLike | TableLike,
projection=None,
panel: int | tuple[int, int] | bool = False,
**kwargs,
):
r"""
Calculate and plot histograms.

Full GMT docs at :gmt-docs:`histogram.html`.

{aliases}
- J = projection
- c = panel

Parameters
----------
Expand Down Expand Up @@ -140,7 +144,10 @@ def histogram(self, data: PathLike | TableLike, projection=None, **kwargs):

aliasdict = AliasSystem(
J=Alias(projection, name="projection"),
).merge(kwargs)
).add_common(
c=panel,
)
aliasdict.merge(kwargs)

with Session() as lib:
with lib.virtualfile_in(check_kind="vector", data=data) as vintbl:
Expand Down
Loading
Loading