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 @@ -7,6 +7,7 @@
load_fractures_compilation,
load_hotspots,
load_japan_quakes,
load_mars_shape,
load_ocean_ridge_points,
load_sample_bathymetry,
load_usgs_quakes,
Expand Down
24 changes: 23 additions & 1 deletion pygmt/datasets/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def load_fractures_compilation():
data = pd.read_csv(fname, header=None, sep=r"\s+", names=["azimuth", "length"])
return data[["length", "azimuth"]]


def load_hotspots():
"""
Load a table with the locations, names, and suggested symbol sizes of
Expand All @@ -149,3 +149,25 @@ def load_hotspots():
columns = ["longitude", "latitude", "symbol_size", "place_name"]
data = pd.read_table(filepath_or_buffer=fname, sep="\t", skiprows=3, names=columns)
return data

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 with columns "longitude", "latitude", and "radius(m)".
"""
fname = which("@mars370d.txt", download="c")
data = pd.read_csv(fname, sep="\t", header=None, names=["lon", "lat", "radius(m)"])
Comment thread
seisman marked this conversation as resolved.
Outdated
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 @@ -6,6 +6,7 @@
load_fractures_compilation,
load_hotspots,
load_japan_quakes,
load_mars_shape,
load_ocean_ridge_points,
load_sample_bathymetry,
load_usgs_quakes,
Expand Down Expand Up @@ -76,6 +77,20 @@ def test_fractures_compilation():
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

def test_hotspots():
"""
Check that the @hotspots.txt dataset loads without errors.
Expand All @@ -89,3 +104,4 @@ def test_hotspots():
"place_name",
]
assert isinstance(data, pd.DataFrame)