Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
5 changes: 5 additions & 0 deletions pygmt/src/grdsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ def grdsample(
)
aliasdict.merge(kwargs)

# Enforce mutual exclusivity between -T (toggle) and -r (registration)
if toggle and aliasdict.get("r") is not None:
msg = "Parameters 'toggle' and 'registration' cannot be used together."
raise GMTInvalidInput(msg)

with Session() as lib:
with (
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,
Expand Down
9 changes: 9 additions & 0 deletions pygmt/tests/test_grdsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import xarray as xr
from pygmt import grdsample
from pygmt.enums import GridRegistration, GridType
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import GMTTempFile
from pygmt.helpers.testing import load_static_earth_relief

Expand Down Expand Up @@ -94,3 +95,11 @@ def test_grdsample_registration_changes(grid):
assert translated_grid.gmt.registration is GridRegistration.GRIDLINE
registration_grid = grdsample(grid=translated_grid, registration="p")
assert registration_grid.gmt.registration is GridRegistration.PIXEL


def test_grdsample_toggle_and_registration_mutually_exclusive(grid):
"""
Raise an exception if toggle and registration are both set.
"""
with pytest.raises(GMTInvalidInput):
grdsample(grid=grid, toggle=True, registration="p")
Loading