Skip to content

Commit 8ddd11c

Browse files
willschlitzerweiji14seisman
authored
Add earth_relief_holes to load_sample_data() (#1921)
Co-authored-by: Wei Ji <[email protected]> Co-authored-by: Dongdong Tian <[email protected]>
1 parent c70fe88 commit 8ddd11c

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

pygmt/datasets/samples.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pandas as pd
77
from pygmt.exceptions import GMTInvalidInput
8+
from pygmt.io import load_dataarray
89
from pygmt.src import which
910

1011

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

6668
load_func = {
6769
"bathymetry": load_sample_bathymetry,
70+
"earth_relief_holes": _load_earth_relief_holes,
6871
"fractures": load_fractures_compilation,
6972
"hotspots": load_hotspots,
7073
"japan_quakes": load_japan_quakes,
@@ -343,3 +346,17 @@ def load_mars_shape(**kwargs):
343346
fname, sep="\t", header=None, names=["longitude", "latitude", "radius(m)"]
344347
)
345348
return data
349+
350+
351+
def _load_earth_relief_holes(**kwargs): # pylint: disable=unused-argument
352+
"""
353+
Loads the remote file @earth_relief_20m_holes.grd.
354+
355+
Returns
356+
-------
357+
grid : :class:`xarray.DataArray`
358+
The Earth relief grid. Coordinates are latitude and longitude in
359+
degrees. Relief is in meters.
360+
"""
361+
fname = which("@earth_relief_20m_holes.grd", download="c")
362+
return load_dataarray(fname, engine="netcdf4")

pygmt/helpers/testing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ def download_test_data():
171171
"@earth_age_01d_g",
172172
"@S90W180.earth_age_05m_g.nc", # Specific grid for 05m test
173173
# Other cache files
174+
"@earth_relief_20m_holes.grd",
174175
"@EGM96_to_36.txt",
175176
"@MaunaLoa_CO2.txt",
176177
"@RidgeTest.shp",

pygmt/tests/test_datasets_samples.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Test basic functionality for loading sample datasets.
33
"""
4+
import numpy.testing as npt
45
import pandas as pd
56
import pytest
67
from pygmt.datasets import (
@@ -145,3 +146,15 @@ def test_hotspots():
145146
"place_name",
146147
]
147148
assert isinstance(data, pd.DataFrame)
149+
150+
151+
def test_earth_relief_holes():
152+
"""
153+
Check that the @earth_relief_20m_holes.grd dataset loads without errors.
154+
"""
155+
grid = load_sample_data(name="earth_relief_holes")
156+
assert grid.shape == (31, 31)
157+
npt.assert_allclose(grid.max(), 1601)
158+
npt.assert_allclose(grid.min(), -4929.5)
159+
# Test for the NaN values in the remote file
160+
assert grid[2, 21].isnull()

0 commit comments

Comments
 (0)