Skip to content

Commit

Permalink
Add earth_relief_holes to load_sample_data() (#1921)
Browse files Browse the repository at this point in the history
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
  • Loading branch information
3 people authored May 25, 2022
1 parent c70fe88 commit 8ddd11c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
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()

0 comments on commit 8ddd11c

Please sign in to comment.