Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check invalid combinations of resolution and registration in load_earth_relief() #965

Merged
merged 4 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 19 additions & 6 deletions pygmt/datasets/earth_relief.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
These grids can also be accessed by passing in the file name
**@earth_relief**\_\ *res*\[_\ *reg*] to any grid plotting/processing
function. *res* is the grid resolution (see below), and *reg* is grid
registration type (**p** for pixel registration or *g* for gridline
registration). Refer to :gmt-docs:`datasets/remote-data.html` for more
details.
registration type (**p** for pixel registration or **g** for gridline
registration).

Refer to :gmt-docs:`datasets/remote-data.html#global-earth-relief-grids`
for more details.

Parameters
----------
Expand All @@ -37,8 +39,10 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
or ``'01s'``.

region : str or list
The subregion of the grid to load. Required for Earth relief grids with
resolutions higher than 5 arc-minute (i.e., ``05m``).
The subregion of the grid to load, in the forms of a list
[*xmin*, *xmax*, *ymin*, *ymax*] or a string *xmin/xmax/ymin/ymax*.
Required for Earth relief grids with resolutions higher than 5
arc-minute (i.e., ``05m``).

registration : str
Grid registration type. Either ``pixel`` for pixel registration or
Expand Down Expand Up @@ -81,7 +85,7 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
reg = f"_{registration[0]}" if registration else ""
else:
raise GMTInvalidInput(
f"Invalid grid registration: {registration}, should be either "
f"Invalid grid registration: '{registration}', should be either "
"'pixel', 'gridline' or None. Default is None, where a "
"pixel-registered grid is returned unless only the "
"gridline-registered grid is available."
Expand All @@ -90,6 +94,15 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
if resolution not in non_tiled_resolutions + tiled_resolutions:
raise GMTInvalidInput(f"Invalid Earth relief resolution '{resolution}'.")

# Check combination of resolution and registeration.
if (resolution == "15s" and registration == "gridline") or (
resolution in ("03s", "01s") and registration == "pixel"
):
raise GMTInvalidInput(
f"{registration}-registered Earth relief data for "
f"resolution '{resolution}' is not supported."
)

# different ways to load tiled and non-tiled earth relief data
# Known issue: tiled grids don't support slice operation
# See https://github.com/GenericMappingTools/pygmt/issues/524
Expand Down
14 changes: 14 additions & 0 deletions pygmt/tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,17 @@ def test_earth_relief_incorrect_registration():
"""
with pytest.raises(GMTInvalidInput):
load_earth_relief(registration="improper_type")


def test_earth_relief_invalid_resolution_registration_combination():
"""
Test loading earth relief with invalid combination of resolution and
registration.
"""
for resolution, registration in [
("15s", "gridline"),
("03s", "pixel"),
("01s", "pixel"),
]:
with pytest.raises(GMTInvalidInput):
load_earth_relief(resolution=resolution, registration=registration)