Skip to content

Commit 93f74df

Browse files
authored
pygmt.grdlandmask: Improve the checking of parameters 'maskvalues'/'bordervalues' (#3963)
1 parent 651a7c5 commit 93f74df

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

pygmt/src/grdlandmask.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
grdlandmask - Create a "wet-dry" mask grid from shoreline database.
33
"""
44

5+
from collections.abc import Sequence
56
from typing import Literal
67

78
import xarray as xr
89
from pygmt._typing import PathLike
910
from pygmt.clib import Session
1011
from pygmt.exceptions import GMTInvalidInput
11-
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
12+
from pygmt.helpers import (
13+
build_arg_list,
14+
fmt_docstring,
15+
kwargs_to_strings,
16+
sequence_join,
17+
use_alias,
18+
)
1219
from pygmt.src._common import _parse_coastline_resolution
1320

1421
__doctest_skip__ = ["grdlandmask"]
@@ -18,17 +25,19 @@
1825
@use_alias(
1926
A="area_thresh",
2027
D="resolution-",
21-
E="bordervalues",
28+
E="bordervalues-",
2229
I="spacing",
23-
N="maskvalues",
30+
N="maskvalues-",
2431
R="region",
2532
V="verbose",
2633
r="registration",
2734
x="cores",
2835
)
29-
@kwargs_to_strings(I="sequence", R="sequence", N="sequence", E="sequence")
36+
@kwargs_to_strings(I="sequence", R="sequence")
3037
def grdlandmask(
3138
outgrid: PathLike | None = None,
39+
maskvalues: Sequence[float] | None = None,
40+
bordervalues: bool | float | Sequence[float] | None = None,
3241
resolution: Literal[
3342
"auto", "full", "high", "intermediate", "low", "crude", None
3443
] = None,
@@ -62,15 +71,15 @@ def grdlandmask(
6271
mask file using one resolution is not guaranteed to remain inside [or outside]
6372
when a different resolution is selected. If ``None``, the low resolution is used
6473
by default.
65-
maskvalues : list
74+
maskvalues
6675
Set the values that will be assigned to nodes, in the form of [*wet*, *dry*], or
6776
[*ocean*, *land*, *lake*, *island*, *pond*]. Default is ``[0, 1, 0, 1, 0]``
6877
(i.e., ``[0, 1]``), meaning that all "wet" nodes will be assigned a value of 0
6978
and all "dry" nodes will be assigned a value of 1. Values can be any number, or
7079
one of ``None``, ``"NaN"``, and ``np.nan`` for setting nodes to NaN.
7180
7281
Use ``bordervalues`` to control how nodes on feature boundaries are handled.
73-
bordervalues : bool, float, or list
82+
bordervalues
7483
Sets the behavior for nodes that fall exactly on a polygon boundary. Valid
7584
values are:
7685
@@ -110,6 +119,8 @@ def grdlandmask(
110119
raise GMTInvalidInput(msg)
111120

112121
kwargs["D"] = kwargs.get("D", _parse_coastline_resolution(resolution))
122+
kwargs["N"] = sequence_join(maskvalues, size=(2, 5), name="maskvalues")
123+
kwargs["E"] = sequence_join(bordervalues, size=(1, 4), name="bordervalues")
113124

114125
with Session() as lib:
115126
with lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd:

0 commit comments

Comments
 (0)