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 Mars dataset #1420

Merged
merged 12 commits into from
Sep 20, 2021
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
23 changes: 23 additions & 0 deletions pygmt/datasets/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,26 @@ 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)"])
seisman marked this conversation as resolved.
Show resolved Hide resolved
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,21 @@ 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 Down