Skip to content
1 change: 1 addition & 0 deletions pygmt/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pygmt.datasets.samples import (
load_fractures_compilation,
load_japan_quakes,
load_mars_shape,
load_ocean_ridge_points,
load_sample_bathymetry,
load_usgs_quakes,
Expand Down
24 changes: 24 additions & 0 deletions pygmt/datasets/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,27 @@ def load_fractures_compilation():
fname = which("@fractures_06.txt", download="c")
data = pd.read_csv(fname, header=None, sep=r"\s+", names=["azimuth", "length"])
return data[["length", "azimuth"]]


def load_mars_shape():
"""
Load a table of data for the shape of Mars.

This is the ``@mars370d.txt`` dataset used in GMT examples, with data and
information from Smith, D. E., and M. T. Zuber (1996), The shape of Mars
and the topographic signature of the hemispheric dichotomy. Data columns
are "longitude," "latitude", and "radius (meters)."

The data are downloaded to a cache directory (usually ``~/.gmt/cache``) the
first time you invoke this function. Afterwards, it will load the data from
the cache. So you'll need an internet connection the first time around.

Returns
-------
data : pandas.DataFrame
The data table. Use ``print(data.describe())`` to see the available
columns.
"""
fname = which("@mars370d.txt", download="c")
data = pd.read_csv(fname, sep="\t", header=None, names=["lon", "lat", "radius(m)"])
return data
16 changes: 16 additions & 0 deletions pygmt/tests/test_datasets_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pygmt.datasets import (
load_fractures_compilation,
load_japan_quakes,
load_mars_shape,
load_ocean_ridge_points,
load_sample_bathymetry,
load_usgs_quakes,
Expand Down Expand Up @@ -72,3 +73,18 @@ def test_fractures_compilation():
assert summary.loc["max", "length"] == 984.652
assert summary.loc["min", "azimuth"] == 0.0
assert summary.loc["max", "azimuth"] == 360.0


def test_mars_shape():
"""
Check that the @mars370d.txt dataset loads without errors.
"""
data = load_mars_shape()
assert data.shape == (370, 3)
summary = data.describe()
assert summary.loc["min", "lon"] == 0.008
assert summary.loc["max", "lon"] == 359.983
assert summary.loc["min", "lat"] == -79.715
assert summary.loc["max", "lat"] == 85.887
assert summary.loc["min", "radius(m)"] == -6930
assert summary.loc["max", "radius(m)"] == 15001