Skip to content

Commit 4db28ef

Browse files
Check invalid combination of resolution and registration in load_earth_relief (#965)
*Add check to see the registration type when passing a registration type for a specific resolution, and raise an error if an invalid registration is passed. *Add a test to confirm an error is raised when an invalid registration is passed. Co-authored-by: Will Schlitzer <[email protected]>
1 parent 8b42490 commit 4db28ef

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

pygmt/datasets/earth_relief.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
2323
These grids can also be accessed by passing in the file name
2424
**@earth_relief**\_\ *res*\[_\ *reg*] to any grid plotting/processing
2525
function. *res* is the grid resolution (see below), and *reg* is grid
26-
registration type (**p** for pixel registration or *g* for gridline
27-
registration). Refer to :gmt-docs:`datasets/remote-data.html` for more
28-
details.
26+
registration type (**p** for pixel registration or **g** for gridline
27+
registration).
28+
29+
Refer to :gmt-docs:`datasets/remote-data.html#global-earth-relief-grids`
30+
for more details.
2931
3032
Parameters
3133
----------
@@ -37,8 +39,10 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
3739
or ``'01s'``.
3840
3941
region : str or list
40-
The subregion of the grid to load. Required for Earth relief grids with
41-
resolutions higher than 5 arc-minute (i.e., ``05m``).
42+
The subregion of the grid to load, in the forms of a list
43+
[*xmin*, *xmax*, *ymin*, *ymax*] or a string *xmin/xmax/ymin/ymax*.
44+
Required for Earth relief grids with resolutions higher than 5
45+
arc-minute (i.e., ``05m``).
4246
4347
registration : str
4448
Grid registration type. Either ``pixel`` for pixel registration or
@@ -81,7 +85,7 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
8185
reg = f"_{registration[0]}" if registration else ""
8286
else:
8387
raise GMTInvalidInput(
84-
f"Invalid grid registration: {registration}, should be either "
88+
f"Invalid grid registration: '{registration}', should be either "
8589
"'pixel', 'gridline' or None. Default is None, where a "
8690
"pixel-registered grid is returned unless only the "
8791
"gridline-registered grid is available."
@@ -90,6 +94,15 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
9094
if resolution not in non_tiled_resolutions + tiled_resolutions:
9195
raise GMTInvalidInput(f"Invalid Earth relief resolution '{resolution}'.")
9296

97+
# Check combination of resolution and registeration.
98+
if (resolution == "15s" and registration == "gridline") or (
99+
resolution in ("03s", "01s") and registration == "pixel"
100+
):
101+
raise GMTInvalidInput(
102+
f"{registration}-registered Earth relief data for "
103+
f"resolution '{resolution}' is not supported."
104+
)
105+
93106
# different ways to load tiled and non-tiled earth relief data
94107
# Known issue: tiled grids don't support slice operation
95108
# See https://github.com/GenericMappingTools/pygmt/issues/524

pygmt/tests/test_datasets.py

+14
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,17 @@ def test_earth_relief_incorrect_registration():
146146
"""
147147
with pytest.raises(GMTInvalidInput):
148148
load_earth_relief(registration="improper_type")
149+
150+
151+
def test_earth_relief_invalid_resolution_registration_combination():
152+
"""
153+
Test loading earth relief with invalid combination of resolution and
154+
registration.
155+
"""
156+
for resolution, registration in [
157+
("15s", "gridline"),
158+
("03s", "pixel"),
159+
("01s", "pixel"),
160+
]:
161+
with pytest.raises(GMTInvalidInput):
162+
load_earth_relief(resolution=resolution, registration=registration)

0 commit comments

Comments
 (0)