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 load_static_earth_relief function for internal testing #1727

Merged
merged 12 commits into from
Feb 9, 2022
17 changes: 17 additions & 0 deletions pygmt/datasets/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import warnings

import pandas as pd
import xarray as xr
from pygmt.exceptions import GMTInvalidInput
from pygmt.src import which

Expand All @@ -30,6 +31,7 @@ def list_sample_data():
"mars_shape": "Table of topographic signature of the hemispheric dichotomy of "
" Mars from Smith and Zuber (1996)",
"ocean_ridge_points": "Table of ocean ridge points for the entire world",
"static_earth_relief": "Sample grid used for testing",
"usgs_quakes": "Table of global earthquakes from the USGS",
}
return names
Expand Down Expand Up @@ -70,6 +72,7 @@ def load_sample_data(name):
"japan_quakes": load_japan_quakes,
"mars_shape": load_mars_shape,
"ocean_ridge_points": load_ocean_ridge_points,
"static_earth_relief": _load_static_earth_relief,
"usgs_quakes": load_usgs_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_static_earth_relief(**kwargs):
"""
Load the static_earth_relief file for internal testing.

Returns
-------
data : xarray.DataArray
A grid of Earth relief for internal tests.
"""
fname = which("@static_earth_relief.nc", download="c")
data = xr.open_dataarray(fname)
return data
16 changes: 16 additions & 0 deletions pygmt/tests/test_datasets_samples.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""
Test basic functionality for loading sample datasets.
"""
import numpy.testing as npt
import pandas as pd
import pytest
import xarray as xr
from pygmt.datasets import (
load_fractures_compilation,
load_hotspots,
Expand Down Expand Up @@ -145,3 +147,17 @@ def test_hotspots():
"place_name",
]
assert isinstance(data, pd.DataFrame)


def test_load_static_earth_relief():
"""
Check that @static_earth_relief.nc loads without errors.
"""
data = load_sample_data("static_earth_relief")
assert data.dims == ("lat", "lon")
assert data.shape == (14, 8)
assert data.min() == 190
assert data.max() == 981
assert data.median() == 467
npt.assert_allclose(data.mean(), 490.87946)
assert isinstance(data, xr.DataArray)