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

Add earth_relief_holes to load_sample_data() #1921

Merged
merged 13 commits into from
May 25, 2022
17 changes: 17 additions & 0 deletions pygmt/datasets/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pandas as pd
from pygmt.exceptions import GMTInvalidInput
from pygmt.io import load_dataarray
from pygmt.src import which


Expand All @@ -23,6 +24,7 @@ def list_sample_data():
"""
names = {
"bathymetry": "Table of ship bathymetric observations off Baja California",
"earth_relief_holes": "Regional 20 arc-minute Earth relief grid with holes",
"fractures": "Table of hypothetical fracture lengths and azimuths",
"hotspots": "Table of locations, names, and symbol sizes of hotpots from "
" Mueller et al., 1993",
Expand Down Expand Up @@ -65,6 +67,7 @@ def load_sample_data(name):

load_func = {
"bathymetry": load_sample_bathymetry,
"earth_relief_holes": _load_earth_relief_holes,
"fractures": load_fractures_compilation,
"hotspots": load_hotspots,
"japan_quakes": load_japan_quakes,
Expand Down Expand Up @@ -343,3 +346,17 @@ def load_mars_shape(**kwargs):
fname, sep="\t", header=None, names=["longitude", "latitude", "radius(m)"]
)
return data


def _load_earth_relief_holes(**kwargs): # pylint: disable=unused-argument
"""
Loads the remote file @earth_relief_20m_holes.grd.

Returns
-------
grid : :class:`xarray.DataArray`
The Earth relief grid. Coordinates are latitude and longitude in
degrees. Relief is in meters.
"""
fname = which("@earth_relief_20m_holes.grd", download="c")
return load_dataarray(fname, engine="netcdf4")
1 change: 1 addition & 0 deletions pygmt/helpers/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def download_test_data():
"@earth_age_01d_g",
"@S90W180.earth_age_05m_g.nc", # Specific grid for 05m test
# Other cache files
"@earth_relief_20m_holes.grd",
"@EGM96_to_36.txt",
"@MaunaLoa_CO2.txt",
"@RidgeTest.shp",
Expand Down
13 changes: 13 additions & 0 deletions pygmt/tests/test_datasets_samples.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test basic functionality for loading sample datasets.
"""
import numpy.testing as npt
import pandas as pd
import pytest
from pygmt.datasets import (
Expand Down Expand Up @@ -145,3 +146,15 @@ def test_hotspots():
"place_name",
]
assert isinstance(data, pd.DataFrame)


def test_earth_relief_holes():
"""
Check that the @earth_relief_20m_holes.grd dataset loads without errors.
"""
grid = load_sample_data(name="earth_relief_holes")
assert grid.shape == (31, 31)
npt.assert_allclose(grid.max(), 1601)
npt.assert_allclose(grid.min(), -4929.5)
# Test for the NaN values in the remote file
assert grid[2, 21].isnull()