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
15 changes: 15 additions & 0 deletions pygmt/helpers/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from matplotlib.testing.compare import compare_images
from pygmt.exceptions import GMTImageComparisonFailure
from pygmt.io import load_dataarray
from pygmt.src import which


Expand Down Expand Up @@ -178,10 +179,24 @@ def download_test_data():
"@ridge.txt",
"@mars370d.txt",
"@srtm_tiles.nc", # needed for 03s and 01s relief data
"@static_earth_relief.nc",
"@test.dat.nc",
"@tut_bathy.nc",
"@tut_quakes.ngdc",
"@tut_ship.xyz",
"@usgs_quakes_22.txt",
]
which(fname=datasets, download="a")


def load_static_earth_relief():
"""
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")
return load_dataarray(fname)
15 changes: 15 additions & 0 deletions pygmt/tests/test_datasets_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import pandas as pd
import pytest
import xarray as xr
from pygmt.datasets import (
load_fractures_compilation,
load_hotspots,
Expand All @@ -14,6 +15,7 @@
load_usgs_quakes,
)
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers.testing import load_static_earth_relief


def test_load_sample_invalid():
Expand Down Expand Up @@ -145,3 +147,16 @@ 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_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
assert isinstance(data, xr.DataArray)