Skip to content

Commit d22db1a

Browse files
committed
pygmt.grdfill: Add new parameter 'inquire' to inquire the bounds of holes
1 parent c6aeadf commit d22db1a

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

pygmt/src/grdfill.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def grdfill(
7676
gridfill: str | xr.DataArray | None = None,
7777
neighborfill: float | bool | None = None,
7878
splinefill: float | bool | None = None,
79+
inquire: bool = False,
7980
**kwargs,
8081
) -> xr.DataArray | None:
8182
r"""
@@ -111,6 +112,9 @@ def grdfill(
111112
hole : float
112113
Set the node value used to identify a point as a member of a hole [Default is
113114
NaN].
115+
inquire
116+
Output the bounds of each hole. The bounds are 2-D numpy arrays in the form of
117+
(west, east, south, north). No grid fill takes place and ``outgrid`` is ignored.
114118
mode : str
115119
Specify the hole-filling algorithm to use. Choose from **c** for constant fill
116120
and append the constant value, **n** for nearest neighbor (and optionally append
@@ -155,10 +159,34 @@ def grdfill(
155159
# Determine the -A option from the fill parameters.
156160
kwargs["A"] = _parse_fill_mode(constantfill, gridfill, neighborfill, splinefill)
157161

158-
if kwargs.get("A") is None and kwargs.get("L") is None:
159-
msg = "At least parameter 'mode' or 'L' must be specified."
162+
if kwargs.get("A") is None and not inquire:
163+
msg = (
164+
"Need to specify parameter 'constantfill'/'gridfill'/'neighborfill'/"
165+
"'splinefill' or 'inquire'."
166+
)
167+
raise GMTInvalidInput(msg)
168+
if kwargs.get("A") is not None and inquire:
169+
msg = (
170+
"Parameters 'constantfill'/'gridfill'/'neighborfill'/'splinefill' and "
171+
"'inquire' are mutually exclusive."
172+
)
160173
raise GMTInvalidInput(msg)
161174

175+
# Inquire only, no grid fill.
176+
if inquire:
177+
kwargs["L"] = True
178+
with Session() as lib:
179+
with (
180+
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,
181+
lib.virtualfile_out(kind="dataset") as vouttbl,
182+
):
183+
lib.call_module(
184+
module="grdfill",
185+
args=build_arg_list(kwargs, infile=vingrd, outfile=vouttbl),
186+
)
187+
return lib.virtualfile_to_dataset(vfname=vouttbl, output_type="numpy")
188+
189+
# Fill the grid:
162190
with Session() as lib:
163191
with (
164192
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,

0 commit comments

Comments
 (0)