Skip to content

Commit f1328ca

Browse files
pygmt.grdfill: Migrate the hole parameter to the new alias system and add a test (#4108)
Co-authored-by: Yvonne Fröhlich <[email protected]>
1 parent e5d845f commit f1328ca

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

pygmt/src/grdfill.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _validate_params(
7777
# TODO(PyGMT>=0.19.0): Remove the deprecated 'no_data' parameter.
7878
# TODO(PyGMT>=0.19.0): Remove the deprecated 'mode' parameter.
7979
@deprecate_parameter("no_data", "hole", "v0.15.0", remove_version="v0.19.0")
80-
@use_alias(N="hole", R="region", f="coltypes")
80+
@use_alias(R="region", f="coltypes")
8181
@kwargs_to_strings(R="sequence")
8282
def grdfill(
8383
grid: PathLike | xr.DataArray,
@@ -87,6 +87,7 @@ def grdfill(
8787
neighborfill: float | bool | None = None,
8888
splinefill: float | bool | None = None,
8989
inquire: bool = False,
90+
hole: float | None = None,
9091
mode: str | None = None,
9192
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
9293
| bool = False,
@@ -109,6 +110,7 @@ def grdfill(
109110
- An = neighborfill
110111
- As = splinefill
111112
- L = inquire
113+
- N = hole
112114
- V = verbose
113115
114116
Parameters
@@ -128,7 +130,7 @@ def grdfill(
128130
splinefill
129131
Fill the holes with a bicubic spline. Specify the tension value to use. If set
130132
to ``True``, no tension will be used.
131-
hole : float
133+
hole
132134
Set the node value used to identify a point as a member of a hole [Default is
133135
NaN].
134136
inquire
@@ -187,6 +189,7 @@ def grdfill(
187189
An=Alias(neighborfill, name="neighborfill"),
188190
As=Alias(splinefill, name="splinefill"),
189191
L=Alias(inquire, name="inquire"),
192+
N=Alias(hole, name="hole"),
190193
).add_common(
191194
V=verbose,
192195
)

pygmt/tests/test_grdfill.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,30 @@ def test_grdfill_gridfill_dataarray(grid):
114114
npt.assert_array_equal(result[3:6, 3:5], bggrid[3:6, 3:5])
115115

116116

117+
def test_grdfill_hole(grid, expected_grid):
118+
"""
119+
Test grdfill with a custom value (not NaN) as holes.
120+
"""
121+
# Prepare for a grid with a node value of -99999 for holes.
122+
grid_no_nan = grdfill(grid=grid, constantfill=-99999)
123+
assert not np.isnan(grid_no_nan).any()
124+
assert -99999 in grid_no_nan
125+
# Now fill them with a constant value of 20.
126+
result = grdfill(grid=grid_no_nan, constantfill=20, hole=-99999)
127+
128+
# Check information of the output grid
129+
assert isinstance(result, xr.DataArray)
130+
assert result.gmt.gtype is GridType.GEOGRAPHIC
131+
assert result.gmt.registration is GridRegistration.PIXEL
132+
xr.testing.assert_allclose(a=result, b=expected_grid)
133+
134+
# Test the deprecated 'no_data' parameter.
135+
# TODO(PyGMT>=0.19.0): Remove the following lines.
136+
with pytest.warns(FutureWarning):
137+
result2 = grdfill(grid=grid_no_nan, constantfill=20, no_data=-99999)
138+
xr.testing.assert_allclose(a=result2, b=expected_grid)
139+
140+
117141
def test_grdfill_inquire(grid):
118142
"""
119143
Test grdfill with inquire mode.

0 commit comments

Comments
 (0)