Skip to content

Commit 88be372

Browse files
committed
Figure.coast: Use long names ("crude"/"low"/"intermediate"/"high"/"full") for the 'resolution' parameter
1 parent 1136be3 commit 88be372

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

examples/tutorials/basics/coastlines.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
# 3. island-in-lake shore
2828
# 4. lake-in-island-in-lake shore
2929
#
30-
# You can specify which level you want to plot by passing the level number and
31-
# a GMT pen configuration. For example, to plot just the coastlines with 0.5p
32-
# thickness and black lines:
30+
# You can specify which level you want to plot by passing the level number and a GMT
31+
# pen configuration. For example, to plot just the coastlines with 0.5p thickness and
32+
# black lines:
3333

3434
fig = pygmt.Figure()
3535
fig.basemap(region="g", projection="W15c", frame=True)
@@ -50,18 +50,14 @@
5050
# Resolutions
5151
# -----------
5252
#
53-
# The coastline database comes with 5 resolutions. The resolution drops by 80%
54-
# between levels:
55-
#
56-
# 1. ``"c"``: crude
57-
# 2. ``"l"``: low (default)
58-
# 3. ``"i"``: intermediate
59-
# 4. ``"h"``: high
60-
# 5. ``"f"``: full
53+
# The coastline database comes with 5 resolutions: ``"full"``, ``"high"``,
54+
# ``"intermediate"``, ``"low"``, and ``"crude"``. The resolution drops by 80% between
55+
# levels. The ``resolution`` parameter defaults to ``"auto"`` to automatically select
56+
# the best resolution given the chosen map scale.
6157

6258
oahu = [-158.3, -157.6, 21.2, 21.8]
6359
fig = pygmt.Figure()
64-
for res in ["c", "l", "i", "h", "f"]:
60+
for res in ["crude", "low", "intermediate", "high", "full"]:
6561
fig.coast(resolution=res, shorelines="1p", region=oahu, projection="M5c")
6662
fig.shift_origin(xshift="5c")
6763
fig.show()
@@ -71,9 +67,9 @@
7167
# Land and water
7268
# --------------
7369
#
74-
# Use the ``land`` and ``water`` parameters to specify a fill color for land
75-
# and water bodies. The colors can be given by name or hex codes (like the ones
76-
# used in HTML and CSS):
70+
# Use the ``land`` and ``water`` parameters to specify a fill color for land and water
71+
# bodies. The colors can be given by name or hex codes (like the ones used in HTML and
72+
# CSS):
7773

7874
fig = pygmt.Figure()
7975
fig.basemap(region="g", projection="W15c", frame=True)

pygmt/src/coast.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
coast - Plot land and water.
33
"""
44

5+
from typing import Literal
6+
57
from pygmt.clib import Session
68
from pygmt.exceptions import GMTInvalidInput
79
from pygmt.helpers import (
@@ -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
@@ -73,10 +81,11 @@ def coast(self, **kwargs):
7381
parameter. Optionally, specify separate fills by appending
7482
**+l** for lakes or **+r** for river-lakes, and passing multiple
7583
strings in a list.
76-
resolution : str
77-
**f**\|\ **h**\|\ **i**\|\ **l**\|\ **c**.
78-
Select the resolution of the data set to: (**f**\ )ull, (**h**\ )igh,
79-
(**i**\ )ntermediate, (**l**\ )ow, and (**c**\ )rude.
84+
resolution
85+
Select the resolution of the coastline dataset to use. The available resolutions
86+
from highest to lowest are: ``"full"``, ``"high"``, ``"intermediate"``,
87+
``"low"``, and ``"crude"``. Default is ``"auto"`` to automatically select the
88+
most suitable resolution given the chosen map scale.
8089
land : str
8190
Select filling of "dry" areas.
8291
rivers : int, str, or list
@@ -199,5 +208,9 @@ def coast(self, **kwargs):
199208
"""At least one of the following parameters must be specified:
200209
lakes, land, water, rivers, borders, dcw, Q, or shorelines"""
201210
)
211+
# resolution
212+
if kwargs.get("D") is not None:
213+
kwargs["D"] = kwargs["D"][0]
214+
202215
with Session() as lib:
203216
lib.call_module(module="coast", args=build_arg_list(kwargs))

pygmt/tests/test_coast.py

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