Skip to content

Commit fbdd936

Browse files
committed
Also improve select and grdlandmask
1 parent 9c24ad1 commit fbdd936

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

pygmt/src/coast.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ def coast(
8484
resolution
8585
Select the resolution of the coastline dataset to use. The available resolutions
8686
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.
87+
``"low"``, and ``"crude"``, which drops by 80% between levels. Default is
88+
``"auto"`` to automatically select the most suitable resolution given the chosen
89+
map scale.
8990
land : str
9091
Select filling of "dry" areas.
9192
rivers : int, str, or list
@@ -208,7 +209,8 @@ def coast(
208209
"""At least one of the following parameters must be specified:
209210
lakes, land, water, rivers, borders, dcw, Q, or shorelines"""
210211
)
211-
# resolution
212+
213+
# Resolution
212214
if kwargs.get("D") is not None:
213215
kwargs["D"] = kwargs["D"][0]
214216

pygmt/src/grdlandmask.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
grdlandmask - Create a "wet-dry" mask grid from shoreline data base
33
"""
44

5+
from typing import Literal
6+
57
import xarray as xr
68
from pygmt.clib import Session
79
from pygmt.exceptions import GMTInvalidInput
@@ -23,7 +25,11 @@
2325
x="cores",
2426
)
2527
@kwargs_to_strings(I="sequence", R="sequence", N="sequence", E="sequence")
26-
def grdlandmask(outgrid: str | None = None, **kwargs) -> xr.DataArray | None:
28+
def grdlandmask(
29+
outgrid: str | None = None,
30+
resolution: Literal["full", "high", "intermediate", "low", "crude"] = "low", # noqa: ARG001
31+
**kwargs,
32+
) -> xr.DataArray | None:
2733
r"""
2834
Create a grid file with set values for land and water.
2935
@@ -44,17 +50,13 @@ def grdlandmask(outgrid: str | None = None, **kwargs) -> xr.DataArray | None:
4450
{spacing}
4551
{region}
4652
{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.
53+
resolution
54+
Ignored unless ``mask`` is set. Select the resolution of the coastline dataset
55+
to use. The available resolutions from highest to lowest are: ``"full"``,
56+
``"high"``, ``"intermediate"``, ``"low"``, and ``"crude"``, which drops by 80%
57+
between levels. Note that because the coastlines differ in details it is not
58+
guaranteed that a point will remain inside [or outside] when a different
59+
resolution is selected.
5860
bordervalues : bool, str, float, or list
5961
Nodes that fall exactly on a polygon boundary should be
6062
considered to be outside the polygon [Default considers them to be
@@ -98,6 +100,10 @@ def grdlandmask(outgrid: str | None = None, **kwargs) -> xr.DataArray | None:
98100
if kwargs.get("I") is None or kwargs.get("R") is None:
99101
raise GMTInvalidInput("Both 'region' and 'spacing' must be specified.")
100102

103+
# Resolution
104+
if kwargs.get("D") is not None:
105+
kwargs["D"] = kwargs["D"][0]
106+
101107
with Session() as lib:
102108
with lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd:
103109
kwargs["G"] = voutgrd

pygmt/src/select.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def select(
4848
data=None,
4949
output_type: Literal["pandas", "numpy", "file"] = "pandas",
5050
outfile: str | None = None,
51+
resolution: Literal["full", "high", "intermediate", "low", "crude"] = "low", # noqa: ARG001
5152
**kwargs,
5253
) -> pd.DataFrame | np.ndarray | None:
5354
r"""
@@ -116,16 +117,13 @@ def select(
116117
<reference/file-formats.html#optional-segment-header-records>`
117118
*polygonfile*. For spherical polygons (lon, lat), make sure no
118119
consecutive points are separated by 180 degrees or more in longitude.
119-
resolution : str
120-
*resolution*\ [**+f**].
121-
Ignored unless ``mask`` is set. Selects the resolution of the coastline
122-
data set to use ((**f**)ull, (**h**)igh, (**i**)ntermediate, (**l**)ow,
123-
or (**c**)rude). The resolution drops off by ~80% between data sets.
124-
[Default is **l**]. Append (**+f**) to automatically select a lower
125-
resolution should the one requested not be available [Default is abort
126-
if not found]. Note that because the coastlines differ in details
127-
it is not guaranteed that a point will remain inside [or outside] when
128-
a different resolution is selected.
120+
resolution
121+
Ignored unless ``mask`` is set. Select the resolution of the coastline dataset
122+
to use. The available resolutions from highest to lowest are: ``"full"``,
123+
``"high"``, ``"intermediate"``, ``"low"``, and ``"crude"``, which drops by 80%
124+
between levels. Note that because the coastlines differ in details it is not
125+
guaranteed that a point will remain inside [or outside] when a different
126+
resolution is selected.
129127
gridmask : str
130128
Pass all locations that are inside the valid data area of the grid
131129
*gridmask*. Nodes that are outside are either NaN or zero.
@@ -205,6 +203,10 @@ def select(
205203
>>> # longitudes 246 and 247 and latitudes 20 and 21
206204
>>> out = pygmt.select(data=ship_data, region=[246, 247, 20, 21])
207205
"""
206+
# Resolution
207+
if kwargs.get("D") is not None:
208+
kwargs["D"] = kwargs["D"][0]
209+
208210
output_type = validate_output_table_type(output_type, outfile=outfile)
209211

210212
column_names = None

0 commit comments

Comments
 (0)