Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions pygmt/src/grdlandmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
grdlandmask - Create a "wet-dry" mask grid from shoreline database.
"""

from collections.abc import Sequence
from typing import Literal

import xarray as xr
from pygmt._typing import PathLike
from pygmt.clib import Session
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
from pygmt.helpers import (
build_arg_list,
fmt_docstring,
kwargs_to_strings,
sequence_join,
use_alias,
)
from pygmt.src._common import _parse_coastline_resolution

__doctest_skip__ = ["grdlandmask"]
Expand All @@ -18,17 +25,19 @@
@use_alias(
A="area_thresh",
D="resolution-",
E="bordervalues",
E="bordervalues-",
I="spacing",
N="maskvalues",
N="maskvalues-",
R="region",
V="verbose",
r="registration",
x="cores",
)
@kwargs_to_strings(I="sequence", R="sequence", N="sequence", E="sequence")
@kwargs_to_strings(I="sequence", R="sequence")
def grdlandmask(
outgrid: PathLike | None = None,
maskvalues: Sequence[float] | None = None,
bordervalues: bool | float | Sequence[float] | None = None,
resolution: Literal[
"auto", "full", "high", "intermediate", "low", "crude", None
] = None,
Expand Down Expand Up @@ -62,15 +71,15 @@ def grdlandmask(
mask file using one resolution is not guaranteed to remain inside [or outside]
when a different resolution is selected. If ``None``, the low resolution is used
by default.
maskvalues : list
maskvalues
Set the values that will be assigned to nodes, in the form of [*wet*, *dry*], or
[*ocean*, *land*, *lake*, *island*, *pond*]. Default is ``[0, 1, 0, 1, 0]``
(i.e., ``[0, 1]``), meaning that all "wet" nodes will be assigned a value of 0
and all "dry" nodes will be assigned a value of 1. Values can be any number, or
one of ``None``, ``"NaN"``, and ``np.nan`` for setting nodes to NaN.

Use ``bordervalues`` to control how nodes on feature boundaries are handled.
bordervalues : bool, float, or list
bordervalues
Sets the behavior for nodes that fall exactly on a polygon boundary. Valid
values are:

Expand Down Expand Up @@ -110,6 +119,8 @@ def grdlandmask(
raise GMTInvalidInput(msg)

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

with Session() as lib:
with lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd:
Expand Down
Loading