Skip to content

Commit

Permalink
Add a sample dataset MaunaLoa_CO2 (#1961)
Browse files Browse the repository at this point in the history
Co-authored-by: Wei Ji <[email protected]>
  • Loading branch information
willschlitzer and weiji14 authored Jun 23, 2022
1 parent e8fb2fd commit 1db326b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pygmt/datasets/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def list_sample_data():
"japan_quakes": "Table of earthquakes around Japan from NOAA NGDC database",
"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",
"usgs_quakes": "Table of global earthquakes from the USGS",
Expand Down Expand Up @@ -80,6 +81,7 @@ def load_sample_data(name):
# Dictionary of private load functions
load_func = {
"earth_relief_holes": _load_earth_relief_holes,
"maunaloa_co2": _load_maunaloa_co2,
"notre_dame_topography": _load_notre_dame_topography,
}

Expand Down Expand Up @@ -371,6 +373,21 @@ def _load_notre_dame_topography():
return pd.read_csv(fname, sep=r"\s+", header=None, names=["x", "y", "z"])


def _load_maunaloa_co2():
"""
Load a table of CO2 values from Mauna Loa.
Returns
-------
data : pandas.DataFrame
The data table with columns "date" and "co2_ppm".
"""
fname = which("@MaunaLoa_CO2.txt", download="c")
return pd.read_csv(
fname, header=None, skiprows=1, sep=r"\s+", names=["date", "co2_ppm"]
)


def _load_earth_relief_holes():
"""
Loads the remote file @earth_relief_20m_holes.grd.
Expand Down
13 changes: 13 additions & 0 deletions pygmt/tests/test_datasets_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,16 @@ def test_earth_relief_holes():
npt.assert_allclose(grid.min(), -4929.5)
# Test for the NaN values in the remote file
assert grid[2, 21].isnull()


def test_maunaloa_co2():
"""
Check that the @MaunaLoa_CO2.txt dataset loads without errors.
"""
data = load_sample_data(name="maunaloa_co2")
assert data.shape == (730, 2)
summary = data.describe()
assert summary.loc["min", "date"] == 1958.2027
assert summary.loc["max", "date"] == 2019.3699
assert summary.loc["min", "co2_ppm"] == 313.2
assert summary.loc["max", "co2_ppm"] == 414.83

0 comments on commit 1db326b

Please sign in to comment.