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 ternary sample dataset #2211

Merged
merged 24 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
91cb50b
Add ternary sample dataset
michaelgrund Nov 25, 2022
e0726e1
[format-command] fixes
actions-bot Nov 25, 2022
8bb35cc
Update samples.py
michaelgrund Nov 25, 2022
569e1e4
Update test_datasets_samples.py
michaelgrund Nov 28, 2022
84ef5d9
Merge branch 'main' into add-ternary-dataset
michaelgrund Nov 28, 2022
db7ffaf
[format-command] fixes
actions-bot Nov 28, 2022
6cefa4c
Update test_datasets_samples.py
michaelgrund Nov 28, 2022
9ffa946
Update samples.py
michaelgrund Nov 28, 2022
810c7e5
Apply suggestions from code review
michaelgrund Nov 29, 2022
d0f952d
Merge branch 'main' into add-ternary-dataset
michaelgrund Nov 29, 2022
bce8763
Merge branch 'main' into add-ternary-dataset
michaelgrund Dec 1, 2022
a7a7f65
Update samples.py
michaelgrund Dec 1, 2022
8db20cf
Update samples.py
michaelgrund Dec 1, 2022
30c38ec
Update test_datasets_samples.py
michaelgrund Dec 1, 2022
1a04108
Update samples.py
michaelgrund Dec 2, 2022
5abacb5
Apply suggestions from code review
michaelgrund Dec 2, 2022
e57a8f1
Merge branch 'main' into add-ternary-dataset
michaelgrund Dec 2, 2022
b904ede
[format-command] fixes
actions-bot Dec 2, 2022
0de3fa2
Apply suggestions from code review
michaelgrund Dec 4, 2022
809c578
Update samples.py
michaelgrund Dec 4, 2022
97f5338
Apply suggestions from code review
michaelgrund Dec 4, 2022
82a3108
Merge branch 'main' into add-ternary-dataset
michaelgrund Dec 4, 2022
213b215
[format-command] fixes
actions-bot Dec 4, 2022
8ffb6e3
Apply suggestions from code review
michaelgrund Dec 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pygmt/datasets/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def list_sample_data():
"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",
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
"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,22 @@ 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", "limestone", "z".
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
"""

fname = which("@ternary.txt", download="c")
return pd.read_csv(
fname, sep="\t", header=None, names=["water", "air", "limestone", "z"]
)
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved


def _load_notre_dame_topography():
"""
Load Table 5.11 in Davis: Statistics and Data Analysis in Geology.
Expand Down
17 changes: 17 additions & 0 deletions pygmt/tests/test_datasets_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,20 @@ 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_ternary():
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
"""
Check that the @ternary.txt dataset loads without errors.
"""
data = load_sample_data(name="rock_compositions")
assert data.shape == (1000, 4)
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
summary = data.describe()
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
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
assert summary.loc["min", "z"] == 1.041
assert summary.loc["max", "z"] == 70.844
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved