Skip to content

Commit

Permalink
Add a sample dataset for ternary examples (GenericMappingTools#2211)
Browse files Browse the repository at this point in the history
Co-authored-by: Will Schlitzer <schlitzer90@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
  • Loading branch information
3 people authored and Josh Sixsmith committed Dec 21, 2022
1 parent 7189188 commit 47e1d7f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
24 changes: 23 additions & 1 deletion pygmt/datasets/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ def list_sample_data():
"mars_shape": "Table of topographic signature of the hemispheric dichotomy of "
" Mars from Smith and Zuber (1996)",
"maunaloa_co2": "Table of CO2 readings from Mauna Loa",
"ocean_ridge_points": "Table of ocean ridge points for the entire world",
"notre_dame_topography": "Table 5.11 in Davis: Statistics and Data Analysis in Geology",
"ocean_ridge_points": "Table of ocean ridge points for the entire world",
"rock_compositions": "Table of rock sample compositions",
"usgs_quakes": "Table of global earthquakes from the USGS",
}
return names
Expand Down Expand Up @@ -80,6 +81,7 @@ def load_sample_data(name):

# Dictionary of private load functions
load_func = {
"rock_compositions": _load_rock_sample_compositions,
"earth_relief_holes": _load_earth_relief_holes,
"maunaloa_co2": _load_maunaloa_co2,
"notre_dame_topography": _load_notre_dame_topography,
Expand Down Expand Up @@ -360,6 +362,26 @@ def load_mars_shape(**kwargs):
return data


def _load_rock_sample_compositions():
"""
Loads a table of rock sample compositions.
Returns
-------
data : pandas.DataFrame
The data table with columns "water", "air", and "limestone".
"""

fname = which("@ternary.txt", download="c")
return pd.read_csv(
fname,
delim_whitespace=True,
header=None,
names=["water", "air", "limestone"],
usecols=(0, 1, 2),
)


def _load_notre_dame_topography():
"""
Load Table 5.11 in Davis: Statistics and Data Analysis in Geology.
Expand Down
15 changes: 15 additions & 0 deletions pygmt/tests/test_datasets_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,18 @@ def test_maunaloa_co2():
assert summary.loc["max", "date"] == 2019.3699
assert summary.loc["min", "co2_ppm"] == 313.2
assert summary.loc["max", "co2_ppm"] == 414.83


def test_rock_sample_compositions():
"""
Check that the @ternary.txt dataset loads without errors.
"""
data = load_sample_data(name="rock_compositions")
assert data.shape == (1000, 3)
summary = data.describe()
assert summary.loc["min", "water"] == 0
assert summary.loc["max", "water"] == 1
assert summary.loc["min", "air"] == 0
assert summary.loc["max", "air"] == 0.921
assert summary.loc["min", "limestone"] == 0
assert summary.loc["max", "limestone"] == 0.981

0 comments on commit 47e1d7f

Please sign in to comment.