22grdlandmask - Create a "wet-dry" mask grid from shoreline database.
33"""
44
5+ from typing import Literal
6+
57import xarray as xr
68from pygmt ._typing import PathLike
79from pygmt .clib import Session
810from pygmt .exceptions import GMTInvalidInput
911from pygmt .helpers import build_arg_list , fmt_docstring , kwargs_to_strings , use_alias
12+ from pygmt .src ._common import _parse_coastline_resolution
1013
1114__doctest_skip__ = ["grdlandmask" ]
1215
1316
1417@fmt_docstring
1518@use_alias (
1619 A = "area_thresh" ,
17- D = "resolution" ,
1820 E = "bordervalues" ,
1921 I = "spacing" ,
2022 N = "maskvalues" ,
2426 x = "cores" ,
2527)
2628@kwargs_to_strings (I = "sequence" , R = "sequence" , N = "sequence" , E = "sequence" )
27- def grdlandmask (outgrid : PathLike | None = None , ** kwargs ) -> xr .DataArray | None :
29+ def grdlandmask (
30+ outgrid : PathLike | None = None ,
31+ resolution : Literal [
32+ "auto" , "full" , "high" , "intermediate" , "low" , "crude" , None
33+ ] = None ,
34+ ** kwargs ,
35+ ) -> xr .DataArray | None :
2836 r"""
2937 Create a "wet-dry" mask grid from shoreline database.
3038
@@ -44,17 +52,15 @@ def grdlandmask(outgrid: PathLike | None = None, **kwargs) -> xr.DataArray | Non
4452 {spacing}
4553 {region}
4654 {area_thresh}
47- resolution : str
48- *res*\[\ **+f**\]. Select the resolution of the data set to use
49- ((**f**)ull, (**h**)igh, (**i**)ntermediate, (**l**)ow, or
50- (**c**)rude). The resolution drops off by ~80% between data sets.
51- [Default is **l**]. Append **+f** to automatically select a lower
52- resolution should the one requested not be available
53- [abort if not found]. Alternatively, choose (**a**)uto to automatically
54- select the best resolution given the chosen region. Note that because
55- the coastlines differ in details a node in a mask file using one
56- resolution is not guaranteed to remain inside [or outside] when a
57- different resolution is selected.
55+ resolution
56+ Select the resolution of the coastline dataset to use. The available resolutions
57+ from highest to lowest are: ``"full"``, ``"high"``, ``"intermediate"``,
58+ ``"low"``, and ``"crude"``, which drops by 80% between levels. Alternatively,
59+ choose ``"auto"`` to automatically select the most suitable resolution given the
60+ chosen region. Note that because the coastlines differ in details, a node in a
61+ mask file using one resolution is not guaranteed to remain inside [or outside]
62+ when a different resolution is selected. If ``None``, the low resolution is used
63+ by default.
5864 maskvalues : list
5965 Set the values that will be assigned to nodes, in the form of [*wet*, *dry*], or
6066 [*ocean*, *land*, *lake*, *island*, *pond*]. Default is ``[0, 1, 0, 1, 0]``
@@ -102,6 +108,8 @@ def grdlandmask(outgrid: PathLike | None = None, **kwargs) -> xr.DataArray | Non
102108 msg = "Both 'region' and 'spacing' must be specified."
103109 raise GMTInvalidInput (msg )
104110
111+ kwargs ["D" ] = kwargs .get ("D" , _parse_coastline_resolution (resolution ))
112+
105113 with Session () as lib :
106114 with lib .virtualfile_out (kind = "grid" , fname = outgrid ) as voutgrd :
107115 kwargs ["G" ] = voutgrd
0 commit comments