diff --git a/pygmt/datasets/samples.py b/pygmt/datasets/samples.py index cf122579338..efe885bcfe0 100644 --- a/pygmt/datasets/samples.py +++ b/pygmt/datasets/samples.py @@ -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 @@ -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, @@ -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. diff --git a/pygmt/tests/test_datasets_samples.py b/pygmt/tests/test_datasets_samples.py index 3bbe93bc5d3..e0d3b3f3a7c 100644 --- a/pygmt/tests/test_datasets_samples.py +++ b/pygmt/tests/test_datasets_samples.py @@ -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