Skip to content

Commit fe05c56

Browse files
authored
pygmt.grdsample: Deprecate parameter 'translate' to 'toggle' (remove in v0.21.0) (#4187)
1 parent 444d3da commit fe05c56

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

pygmt/src/grdsample.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,26 @@
99
from pygmt._typing import PathLike
1010
from pygmt.alias import Alias, AliasSystem
1111
from pygmt.clib import Session
12-
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
12+
from pygmt.helpers import (
13+
build_arg_list,
14+
deprecate_parameter,
15+
fmt_docstring,
16+
kwargs_to_strings,
17+
use_alias,
18+
)
1319

1420
__doctest_skip__ = ["grdsample"]
1521

1622

23+
# TODO(PyGMT>=0.21.0): Remove the deprecated "translate" parameter.
1724
@fmt_docstring
25+
@deprecate_parameter("translate", "toggle", "v0.18.0", remove_version="v0.21.0")
1826
@use_alias(I="spacing", f="coltypes", n="interpolation", r="registration")
1927
@kwargs_to_strings(I="sequence")
2028
def grdsample(
2129
grid: PathLike | xr.DataArray,
2230
outgrid: PathLike | None = None,
23-
translate: bool = False,
31+
toggle: bool = False,
2432
region: Sequence[float | str] | str | None = None,
2533
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
2634
| bool = False,
@@ -31,7 +39,7 @@ def grdsample(
3139
Resample a grid onto a new lattice.
3240
3341
This reads a grid file and interpolates it to create a new grid
34-
file. It can change the registration with ``translate`` or
42+
file. It can change the registration with ``toggle`` or
3543
``registration``, change the grid-spacing or number of nodes with
3644
``spacing``, and set a new sub-region using ``region``. A bicubic
3745
[Default], bilinear, B-spline or nearest-neighbor interpolation is set
@@ -40,7 +48,7 @@ def grdsample(
4048
When ``region`` is omitted, the output grid will cover the same region as
4149
the input grid. When ``spacing`` is omitted, the grid spacing of the
4250
output grid will be the same as the input grid. Either ``registration`` or
43-
``translate`` can be used to change the grid registration. When omitted,
51+
``toggle`` can be used to change the grid registration. When omitted,
4452
the output grid will have the same registration as the input grid.
4553
4654
Full GMT docs at :gmt-docs:`grdsample.html`.
@@ -56,9 +64,9 @@ def grdsample(
5664
{outgrid}
5765
{spacing}
5866
{region}
59-
translate
60-
Translate between grid and pixel registration; if the input is grid-registered,
61-
the output will be pixel-registered and vice-versa. This is a *destructive* grid
67+
toggle
68+
Toggle between grid and pixel registration; if the input is grid-registered, the
69+
output will be pixel-registered and vice-versa. This is a *destructive* grid
6270
change; see :gmt-docs:`reference/options.html#switch-registrations`.
6371
registration : str or bool
6472
[**g**\|\ **p**\ ].
@@ -87,10 +95,10 @@ def grdsample(
8795
... )
8896
>>> # Create a new grid from an input grid, change the registration,
8997
>>> # and set both x- and y-spacings to 0.5 arc-degrees
90-
>>> new_grid = pygmt.grdsample(grid=grid, translate=True, spacing=[0.5, 0.5])
98+
>>> new_grid = pygmt.grdsample(grid=grid, toggle=True, spacing=[0.5, 0.5])
9199
"""
92100
aliasdict = AliasSystem(
93-
T=Alias(translate, name="translate"),
101+
T=Alias(toggle, name="toggle"),
94102
).add_common(
95103
R=region,
96104
V=verbose,

pygmt/tests/test_grdsample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_grdsample_registration_changes(grid):
9090
Test grdsample with no set outgrid and applying registration changes.
9191
"""
9292
assert grid.gmt.registration is GridRegistration.PIXEL
93-
translated_grid = grdsample(grid=grid, translate=True)
93+
translated_grid = grdsample(grid=grid, toggle=True)
9494
assert translated_grid.gmt.registration is GridRegistration.GRIDLINE
9595
registration_grid = grdsample(grid=translated_grid, registration="p")
9696
assert registration_grid.gmt.registration is GridRegistration.PIXEL

0 commit comments

Comments
 (0)