Skip to content

Commit 01e25f2

Browse files
committed
Figure.coast: Make the 'resolution' parameter more Pythonic
1 parent 1b500da commit 01e25f2

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

pygmt/src/coast.py

+28-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
coast - Plot land and water.
33
"""
44

5+
from typing import Literal
6+
7+
from pygmt.alias import Alias, AliasSystem
58
from pygmt.clib import Session
69
from pygmt.exceptions import GMTInvalidInput
710
from pygmt.helpers import (
@@ -20,7 +23,6 @@
2023
A="area_thresh",
2124
B="frame",
2225
C="lakes",
23-
D="resolution",
2426
E="dcw",
2527
F="box",
2628
G="land",
@@ -37,7 +39,13 @@
3739
t="transparency",
3840
)
3941
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
40-
def coast(self, **kwargs):
42+
def coast(
43+
self,
44+
resolution: Literal[ # noqa: ARG001
45+
"auto", "full", "high", "intermediate", "low", "crude"
46+
] = "auto",
47+
**kwargs,
48+
):
4149
r"""
4250
Plot continents, shorelines, rivers, and borders on maps.
4351
@@ -75,11 +83,19 @@ def coast(self, **kwargs):
7583
parameter. Optionally, specify separate fills by appending
7684
**+l** for lakes or **+r** for river-lakes, and passing multiple
7785
strings in a list.
78-
resolution : str
79-
**f**\|\ **h**\|\ **i**\|\ **l**\|\ **c**.
80-
Select the resolution of the data set to: (**f**\ )ull,
81-
(**h**\ )igh, (**i**\ )ntermediate, (**l**\ )ow,
82-
and (**c**\ )rude.
86+
resolution
87+
Select the resolution of the GSHHG coastline data set to use. The available
88+
resolutions from highest to lowest are:
89+
90+
- ``"full"`` - Full resolution (may be very slow for large regions).
91+
- ``"high"`` - High resolution (may be slow for large regions).
92+
- ``"intermediate"`` - Intermediate resolution.
93+
- ``"low"`` - Low resolution.
94+
- ``"crude"`` - Crude resolution, for tasks that need crude continent outlines
95+
only.
96+
97+
The default is ``"auto"`` to automatically select the best resolution given the
98+
chosen map scale.
8399
land : str
84100
Select filling or clipping of "dry" areas.
85101
rivers : int, str, or list
@@ -220,11 +236,15 @@ def coast(self, **kwargs):
220236
>>> # Show the plot
221237
>>> fig.show()
222238
"""
239+
alias = AliasSystem(
240+
D=Alias("resolution", mapping=True),
241+
)
223242
kwargs = self._preprocess(**kwargs)
224243
if not args_in_kwargs(args=["C", "G", "S", "I", "N", "E", "Q", "W"], kwargs=kwargs):
225244
raise GMTInvalidInput(
226245
"""At least one of the following parameters must be specified:
227246
lakes, land, water, rivers, borders, dcw, Q, or shorelines"""
228247
)
248+
229249
with Session() as lib:
230-
lib.call_module(module="coast", args=build_arg_list(kwargs))
250+
lib.call_module(module="coast", args=build_arg_list(alias.kwdict))

pygmt/tests/test_coast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_coast_world_mercator():
2929
projection="M15c",
3030
frame="af",
3131
land="#aaaaaa",
32-
resolution="c",
32+
resolution="crude",
3333
water="white",
3434
)
3535
return fig

0 commit comments

Comments
 (0)