Skip to content

Commit c5c404b

Browse files
michaelgrundwillschlitzerseisman
authored
Add a sample dataset for ternary examples (#2211)
Co-authored-by: Will Schlitzer <schlitzer90@gmail.com> Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
1 parent 8854774 commit c5c404b

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

pygmt/datasets/samples.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ def list_sample_data():
3232
"mars_shape": "Table of topographic signature of the hemispheric dichotomy of "
3333
" Mars from Smith and Zuber (1996)",
3434
"maunaloa_co2": "Table of CO2 readings from Mauna Loa",
35-
"ocean_ridge_points": "Table of ocean ridge points for the entire world",
3635
"notre_dame_topography": "Table 5.11 in Davis: Statistics and Data Analysis in Geology",
36+
"ocean_ridge_points": "Table of ocean ridge points for the entire world",
37+
"rock_compositions": "Table of rock sample compositions",
3738
"usgs_quakes": "Table of global earthquakes from the USGS",
3839
}
3940
return names
@@ -80,6 +81,7 @@ def load_sample_data(name):
8081

8182
# Dictionary of private load functions
8283
load_func = {
84+
"rock_compositions": _load_rock_sample_compositions,
8385
"earth_relief_holes": _load_earth_relief_holes,
8486
"maunaloa_co2": _load_maunaloa_co2,
8587
"notre_dame_topography": _load_notre_dame_topography,
@@ -360,6 +362,26 @@ def load_mars_shape(**kwargs):
360362
return data
361363

362364

365+
def _load_rock_sample_compositions():
366+
"""
367+
Loads a table of rock sample compositions.
368+
369+
Returns
370+
-------
371+
data : pandas.DataFrame
372+
The data table with columns "water", "air", and "limestone".
373+
"""
374+
375+
fname = which("@ternary.txt", download="c")
376+
return pd.read_csv(
377+
fname,
378+
delim_whitespace=True,
379+
header=None,
380+
names=["water", "air", "limestone"],
381+
usecols=(0, 1, 2),
382+
)
383+
384+
363385
def _load_notre_dame_topography():
364386
"""
365387
Load Table 5.11 in Davis: Statistics and Data Analysis in Geology.

pygmt/tests/test_datasets_samples.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,18 @@ def test_maunaloa_co2():
186186
assert summary.loc["max", "date"] == 2019.3699
187187
assert summary.loc["min", "co2_ppm"] == 313.2
188188
assert summary.loc["max", "co2_ppm"] == 414.83
189+
190+
191+
def test_rock_sample_compositions():
192+
"""
193+
Check that the @ternary.txt dataset loads without errors.
194+
"""
195+
data = load_sample_data(name="rock_compositions")
196+
assert data.shape == (1000, 3)
197+
summary = data.describe()
198+
assert summary.loc["min", "water"] == 0
199+
assert summary.loc["max", "water"] == 1
200+
assert summary.loc["min", "air"] == 0
201+
assert summary.loc["max", "air"] == 0.921
202+
assert summary.loc["min", "limestone"] == 0
203+
assert summary.loc["max", "limestone"] == 0.981

0 commit comments

Comments
 (0)