77
88from pygmt .alias import Alias , AliasSystem
99from pygmt .clib import Session
10- from pygmt .exceptions import GMTParameterError
11- from pygmt .helpers import args_in_kwargs , build_arg_list , fmt_docstring , use_alias
10+ from pygmt .exceptions import GMTInvalidInput , GMTParameterError
11+ from pygmt .helpers import (
12+ args_in_kwargs ,
13+ build_arg_list ,
14+ fmt_docstring ,
15+ is_nonstr_iter ,
16+ use_alias ,
17+ )
1218from pygmt .params import Box
1319
1420__doctest_skip__ = ["coast" ]
1521
1622
23+ def _alias_option_C (lakes = None , river_lakes = None ): # noqa: N802
24+ """
25+ Helper function to create the alias list for the -C option.
26+
27+ Example
28+ -------
29+ >>> def parse(**kwargs):
30+ ... return AliasSystem(C=_alias_option_C(**kwargs)).get("C")
31+ >>> parse()
32+ >>> parse(lakes="blue")
33+ 'blue'
34+ >>> parse(river_lakes="cyan")
35+ 'cyan+r'
36+ >>> parse(lakes="blue", river_lakes="cyan")
37+ ['blue+l', 'cyan+r']
38+
39+ >>> # Check for backward compatibility
40+ >>> parse(lakes="blue+l")
41+ 'blue+l'
42+ >>> parse(lakes="cyan+r")
43+ 'cyan+r'
44+ >>> parse(lakes=["blue+l", "cyan+r"])
45+ ['blue+l', 'cyan+r']
46+
47+ >>> # Check for mixed usage error
48+ >>> parse(lakes=["blue+l", "cyan+r"], river_lakes="cyan")
49+ Traceback (most recent call last):
50+ ...
51+ pygmt.exceptions.GMTInvalidInput: Parameter 'lakes' is given with a list; ...
52+ """
53+ # Check for backward compatibility.
54+ if is_nonstr_iter (lakes ): # Old syntax: lakes is a list of strings.
55+ if river_lakes is not None :
56+ msg = "Parameter 'lakes' is given with a list; 'river_lakes' must be None."
57+ raise GMTInvalidInput (msg )
58+ return Alias (lakes , name = "lakes" ) # Return as is.
59+
60+ # If only 'lakes' is specified, no suffix is needed.
61+ return [
62+ Alias (lakes , name = "lakes" , suffix = "+l" if river_lakes is not None else "" ),
63+ Alias (river_lakes , name = "river_lakes" , suffix = "+r" ),
64+ ]
65+
66+
1767@fmt_docstring
18- @use_alias (A = "area_thresh" , C = "lakes" , E = "dcw" )
68+ @use_alias (A = "area_thresh" , E = "dcw" )
1969def coast ( # noqa: PLR0913
2070 self ,
2171 resolution : Literal [
@@ -26,6 +76,8 @@ def coast( # noqa: PLR0913
2676 rivers : int | str | Sequence [int | str ] | None = None ,
2777 borders : int | str | Sequence [int | str ] | None = None ,
2878 shorelines : bool | str | Sequence [int | str ] = False ,
79+ lakes : str | None = None ,
80+ river_lakes : str | None = None ,
2981 map_scale : str | None = None ,
3082 box : Box | bool = False ,
3183 projection : str | None = None ,
@@ -59,6 +111,7 @@ def coast( # noqa: PLR0913
59111
60112 $aliases
61113 - B = frame
114+ - C = lakes, river_lakes
62115 - D = resolution
63116 - F = box
64117 - G = land
@@ -75,13 +128,6 @@ def coast( # noqa: PLR0913
75128 Parameters
76129 ----------
77130 $area_thresh
78- lakes : str or list
79- *fill*\ [**+l**\|\ **+r**].
80- Set the shade, color, or pattern for lakes and river-lakes. The
81- default is the fill chosen for "wet" areas set by the ``water``
82- parameter. Optionally, specify separate fills by appending
83- **+l** for lakes or **+r** for river-lakes, and passing multiple
84- strings in a list.
85131 resolution
86132 Select the resolution of the coastline dataset to use. The available resolutions
87133 from highest to lowest are: ``"full"``, ``"high"``, ``"intermediate"``,
@@ -92,6 +138,11 @@ def coast( # noqa: PLR0913
92138 Select filling of "dry" areas.
93139 water
94140 Select filling of "wet" areas.
141+ lakes
142+ river_lakes
143+ Select filling of lakes and river-lakes. If not specified, will use the fill for
144+ "wet" areas set by the ``water`` parameter. If ``lakes`` is specified but
145+ ``river_lakes`` isn't, ``river_lakes`` will use the same fill as ``lakes``.
95146 rivers
96147 Draw rivers. Specify the type of rivers to draw, and optionally append a pen
97148 attribute, in the format *river*\ /*pen* [Default pen is
@@ -239,7 +290,8 @@ def coast( # noqa: PLR0913
239290 and kwargs .get ("I" , rivers ) is None
240291 and kwargs .get ("N" , borders ) is None
241292 and kwargs .get ("W" , shorelines ) is False
242- and not args_in_kwargs (args = ["C" , "E" , "Q" ], kwargs = kwargs )
293+ and kwargs .get ("C" , lakes or river_lakes ) is None
294+ and not args_in_kwargs (args = ["E" , "Q" ], kwargs = kwargs )
243295 ):
244296 raise GMTParameterError (
245297 at_least_one = [
@@ -249,12 +301,14 @@ def coast( # noqa: PLR0913
249301 "borders" ,
250302 "shorelines" ,
251303 "lakes" ,
304+ "river_lakes" ,
252305 "dcw" ,
253306 "Q" ,
254307 ]
255308 )
256309
257310 aliasdict = AliasSystem (
311+ C = _alias_option_C (lakes = lakes , river_lakes = river_lakes ),
258312 D = Alias (
259313 resolution ,
260314 name = "resolution" ,
0 commit comments