Skip to content

Commit a95862d

Browse files
pygmt.grdfill: Deprecate parameters splinefill/constantfill/neighborfill/gridfill to spline_fill/constant_fill/neighbor_fill/grid_fill (Will be removed in v0.20.0) (#4273)
1 parent 3d0f879 commit a95862d

File tree

2 files changed

+59
-41
lines changed

2 files changed

+59
-41
lines changed

pygmt/src/grdfill.py

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@
1818

1919

2020
def _validate_params(
21-
constantfill=None,
22-
gridfill=None,
23-
neighborfill=None,
24-
splinefill=None,
21+
constant_fill=None,
22+
grid_fill=None,
23+
neighbor_fill=None,
24+
spline_fill=None,
2525
inquire=False,
2626
mode=None,
2727
):
2828
"""
2929
Validate the fill/inquire parameters.
3030
31-
>>> _validate_params(constantfill=20.0)
31+
>>> _validate_params(constant_fill=20.0)
3232
>>> _validate_params(inquire=True)
3333
>>> _validate_params(mode="c20.0")
34-
>>> _validate_params(constantfill=20.0, gridfill="bggrid.nc")
34+
>>> _validate_params(constant_fill=20.0, grid_fill="bggrid.nc")
3535
Traceback (most recent call last):
3636
...
3737
pygmt.exceptions.GMTInvalidInput: Parameters ... are mutually exclusive.
38-
>>> _validate_params(constantfill=20.0, inquire=True)
38+
>>> _validate_params(constant_fill=20.0, inquire=True)
3939
Traceback (most recent call last):
4040
...
4141
pygmt.exceptions.GMTInvalidInput: Parameters ... are mutually exclusive.
@@ -44,7 +44,7 @@ def _validate_params(
4444
...
4545
pygmt.exceptions.GMTInvalidInput: Need to specify parameter ...
4646
"""
47-
_fill_params = "'constantfill'/'gridfill'/'neighborfill'/'splinefill'"
47+
_fill_params = "'constant_fill'/'grid_fill'/'neighbor_fill'/'spline_fill'"
4848
# The deprecated 'mode' parameter is given.
4949
if mode is not None:
5050
msg = (
@@ -55,7 +55,14 @@ def _validate_params(
5555

5656
n_given = sum(
5757
param is not None and param is not False
58-
for param in [constantfill, gridfill, neighborfill, splinefill, inquire, mode]
58+
for param in [
59+
constant_fill,
60+
grid_fill,
61+
neighbor_fill,
62+
spline_fill,
63+
inquire,
64+
mode,
65+
]
5966
)
6067
if n_given > 1: # More than one mutually exclusive parameter is given.
6168
msg = f"Parameters {_fill_params}/'inquire'/'mode' are mutually exclusive."
@@ -71,15 +78,23 @@ def _validate_params(
7178
@fmt_docstring
7279
# TODO(PyGMT>=0.19.0): Remove the deprecated 'no_data' parameter.
7380
# TODO(PyGMT>=0.19.0): Remove the deprecated 'mode' parameter.
74-
@deprecate_parameter("no_data", "hole", "v0.15.0", remove_version="v0.19.0")
81+
@deprecate_parameter("no_data", "hole", "v0.18.0", remove_version="v0.20.0")
82+
@deprecate_parameter(
83+
"constantfill", "constant_fill", "v0.15.0", remove_version="v0.19.0"
84+
)
85+
@deprecate_parameter("gridfill", "grid_fill", "v0.18.0", remove_version="v0.20.0")
86+
@deprecate_parameter(
87+
"neighborfill", "neighbor_fill", "v0.18.0", remove_version="v0.20.0"
88+
)
89+
@deprecate_parameter("splinefill", "spline_fill", "v0.18.0", remove_version="v0.20.0")
7590
@use_alias(f="coltypes")
7691
def grdfill( # noqa: PLR0913
7792
grid: PathLike | xr.DataArray,
7893
outgrid: PathLike | None = None,
79-
constantfill: float | None = None,
80-
gridfill: PathLike | xr.DataArray | None = None,
81-
neighborfill: float | bool | None = None,
82-
splinefill: float | bool | None = None,
94+
constant_fill: float | None = None,
95+
grid_fill: PathLike | xr.DataArray | None = None,
96+
neighbor_fill: float | bool | None = None,
97+
spline_fill: float | bool | None = None,
8398
inquire: bool = False,
8499
hole: float | None = None,
85100
mode: str | None = None,
@@ -100,10 +115,10 @@ def grdfill( # noqa: PLR0913
100115
Full GMT docs at :gmt-docs:`grdfill.html`.
101116
102117
$aliases
103-
- Ac = constantfill
104-
- Ag = gridfill
105-
- An = neighborfill
106-
- As = splinefill
118+
- Ac = constant_fill
119+
- Ag = grid_fill
120+
- An = neighbor_fill
121+
- As = spline_fill
107122
- L = inquire
108123
- N = hole
109124
- R = region
@@ -113,17 +128,17 @@ def grdfill( # noqa: PLR0913
113128
----------
114129
$grid
115130
$outgrid
116-
constantfill
131+
constant_fill
117132
Fill the holes with a constant value. Specify the constant value to use.
118-
gridfill
133+
grid_fill
119134
Fill the holes with values sampled from another (possibly coarser) grid. Specify
120135
the grid (a file name or an :class:`xarray.DataArray`) to use for the fill.
121-
neighborfill
136+
neighbor_fill
122137
Fill the holes with the nearest neighbor. Specify the search radius in pixels.
123138
If set to ``True``, the default search radius will be used
124139
(:math:`r^2 = \sqrt{n^2 + m^2}`, where (*n,m*) are the node dimensions of the
125140
grid).
126-
splinefill
141+
spline_fill
127142
Fill the holes with a bicubic spline. Specify the tension value to use. If set
128143
to ``True``, no tension will be used.
129144
hole
@@ -141,8 +156,9 @@ def grdfill( # noqa: PLR0913
141156
(optionally append a *tension* parameter [Default is no tension]).
142157
143158
.. deprecated:: 0.15.0
144-
Use ``constantfill``, ``gridfill``, ``neighborfill``, or ``splinefill``
159+
Use ``constant_fill``, ``grid_fill``, ``neighbor_fill``, or ``spline_fill``
145160
instead. The parameter will be removed in v0.19.0.
161+
146162
$region
147163
$coltypes
148164
$verbose
@@ -165,7 +181,7 @@ def grdfill( # noqa: PLR0913
165181
>>> # Load a bathymetric grid with missing data
166182
>>> earth_relief_holes = pygmt.datasets.load_sample_data(name="earth_relief_holes")
167183
>>> # Fill the holes with a constant value of 20
168-
>>> filled_grid = pygmt.grdfill(grid=earth_relief_holes, constantfill=20)
184+
>>> filled_grid = pygmt.grdfill(grid=earth_relief_holes, constant_fill=20)
169185
170186
Inquire the bounds of each hole.
171187
@@ -174,16 +190,18 @@ def grdfill( # noqa: PLR0913
174190
[6.16666667, 7.83333333, 0.5 , 2.5 ]])
175191
"""
176192
# Validate the fill/inquire parameters.
177-
_validate_params(constantfill, gridfill, neighborfill, splinefill, inquire, mode)
193+
_validate_params(
194+
constant_fill, grid_fill, neighbor_fill, spline_fill, inquire, mode
195+
)
178196

179197
# _validate_params has already ensured that only one of the parameters is set.
180198
aliasdict = AliasSystem(
181199
A=Alias(mode, name="mode"),
182-
Ac=Alias(constantfill, name="constantfill"),
183-
# For grdfill, append the actual or virtual grid file name later.
184-
Ag=Alias(gridfill is not None, name="gridfill"),
185-
An=Alias(neighborfill, name="neighborfill"),
186-
As=Alias(splinefill, name="splinefill"),
200+
Ac=Alias(constant_fill, name="constant_fill"),
201+
# For grid_fill, append the actual or virtual grid file name later.
202+
Ag=Alias(grid_fill is not None, name="grid_fill"),
203+
An=Alias(neighbor_fill, name="neighbor_fill"),
204+
As=Alias(spline_fill, name="spline_fill"),
187205
L=Alias(inquire, name="inquire"),
188206
N=Alias(hole, name="hole"),
189207
).add_common(
@@ -207,11 +225,11 @@ def grdfill( # noqa: PLR0913
207225
# Fill mode.
208226
with (
209227
lib.virtualfile_in(
210-
check_kind="raster", data=gridfill, required=False
228+
check_kind="raster", data=grid_fill, required=False
211229
) as vbggrd,
212230
lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd,
213231
):
214-
if gridfill is not None:
232+
if grid_fill is not None:
215233
# Fill by a grid. Append the actual or virtual grid file name.
216234
aliasdict["Ag"] = vbggrd
217235
aliasdict["G"] = voutgrd

pygmt/tests/test_grdfill.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_grdfill_dataarray_out(grid, expected_grid):
6262
"""
6363
Test grdfill with a DataArray output.
6464
"""
65-
result = grdfill(grid=grid, constantfill=20)
65+
result = grdfill(grid=grid, constant_fill=20)
6666
# check information of the output grid
6767
assert isinstance(result, xr.DataArray)
6868
assert result.gmt.gtype is GridType.GEOGRAPHIC
@@ -77,7 +77,7 @@ def test_grdfill_asymmetric_pad(grid, expected_grid):
7777
7878
Regression test for https://github.com/GenericMappingTools/pygmt/issues/1745.
7979
"""
80-
result = grdfill(grid=grid, constantfill=20, region=[-55, -50, -24, -16])
80+
result = grdfill(grid=grid, constant_fill=20, region=[-55, -50, -24, -16])
8181
# check information of the output grid
8282
assert isinstance(result, xr.DataArray)
8383
assert result.gmt.gtype is GridType.GEOGRAPHIC
@@ -93,14 +93,14 @@ def test_grdfill_file_out(grid, expected_grid):
9393
Test grdfill with an outgrid set.
9494
"""
9595
with GMTTempFile(suffix=".nc") as tmpfile:
96-
result = grdfill(grid=grid, constantfill=20, outgrid=tmpfile.name)
96+
result = grdfill(grid=grid, constant_fill=20, outgrid=tmpfile.name)
9797
assert result is None # return value is None
9898
assert Path(tmpfile.name).stat().st_size > 0 # check that outfile exists
9999
temp_grid = xr.load_dataarray(tmpfile.name, engine="gmt", raster_kind="grid")
100100
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)
101101

102102

103-
def test_grdfill_gridfill_dataarray(grid):
103+
def test_grdfill_grid_fill_dataarray(grid):
104104
"""
105105
Test grdfill with a DataArray input.
106106
"""
@@ -109,7 +109,7 @@ def test_grdfill_gridfill_dataarray(grid):
109109
dims=grid.dims,
110110
coords={"lon": grid.lon, "lat": grid.lat},
111111
)
112-
result = grdfill(grid=grid, gridfill=bggrid)
112+
result = grdfill(grid=grid, grid_fill=bggrid)
113113
assert not result.isnull().any()
114114
npt.assert_array_equal(result[3:6, 3:5], bggrid[3:6, 3:5])
115115

@@ -119,11 +119,11 @@ def test_grdfill_hole(grid, expected_grid):
119119
Test grdfill with a custom value (not NaN) as holes.
120120
"""
121121
# Prepare for a grid with a node value of -99999 for holes.
122-
grid_no_nan = grdfill(grid=grid, constantfill=-99999)
122+
grid_no_nan = grdfill(grid=grid, constant_fill=-99999)
123123
assert not np.isnan(grid_no_nan).any()
124124
assert -99999 in grid_no_nan
125125
# Now fill them with a constant value of 20.
126-
result = grdfill(grid=grid_no_nan, constantfill=20, hole=-99999)
126+
result = grdfill(grid=grid_no_nan, constant_fill=20, hole=-99999)
127127

128128
# Check information of the output grid
129129
assert isinstance(result, xr.DataArray)
@@ -134,7 +134,7 @@ def test_grdfill_hole(grid, expected_grid):
134134
# Test the deprecated 'no_data' parameter.
135135
# TODO(PyGMT>=0.19.0): Remove the following lines.
136136
with pytest.warns(FutureWarning):
137-
result2 = grdfill(grid=grid_no_nan, constantfill=20, no_data=-99999)
137+
result2 = grdfill(grid=grid_no_nan, constant_fill=20, no_data=-99999)
138138
xr.testing.assert_allclose(a=result2, b=expected_grid)
139139

140140

@@ -161,7 +161,7 @@ def test_grdfill_inquire_and_fill(grid):
161161
Test that grdfill fails if both inquire and fill parameters are given.
162162
"""
163163
with pytest.raises(GMTInvalidInput):
164-
grdfill(grid=grid, inquire=True, constantfill=20)
164+
grdfill(grid=grid, inquire=True, constant_fill=20)
165165

166166

167167
# TODO(PyGMT>=0.19.0): Remove this test.

0 commit comments

Comments
 (0)