Skip to content

Commit 1db326b

Browse files
Add a sample dataset MaunaLoa_CO2 (#1961)
Co-authored-by: Wei Ji <[email protected]>
1 parent e8fb2fd commit 1db326b

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

pygmt/datasets/samples.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def list_sample_data():
3131
"japan_quakes": "Table of earthquakes around Japan from NOAA NGDC database",
3232
"mars_shape": "Table of topographic signature of the hemispheric dichotomy of "
3333
" Mars from Smith and Zuber (1996)",
34+
"maunaloa_co2": "Table of CO2 readings from Mauna Loa",
3435
"ocean_ridge_points": "Table of ocean ridge points for the entire world",
3536
"notre_dame_topography": "Table 5.11 in Davis: Statistics and Data Analysis in Geology",
3637
"usgs_quakes": "Table of global earthquakes from the USGS",
@@ -80,6 +81,7 @@ def load_sample_data(name):
8081
# Dictionary of private load functions
8182
load_func = {
8283
"earth_relief_holes": _load_earth_relief_holes,
84+
"maunaloa_co2": _load_maunaloa_co2,
8385
"notre_dame_topography": _load_notre_dame_topography,
8486
}
8587

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

373375

376+
def _load_maunaloa_co2():
377+
"""
378+
Load a table of CO2 values from Mauna Loa.
379+
380+
Returns
381+
-------
382+
data : pandas.DataFrame
383+
The data table with columns "date" and "co2_ppm".
384+
"""
385+
fname = which("@MaunaLoa_CO2.txt", download="c")
386+
return pd.read_csv(
387+
fname, header=None, skiprows=1, sep=r"\s+", names=["date", "co2_ppm"]
388+
)
389+
390+
374391
def _load_earth_relief_holes():
375392
"""
376393
Loads the remote file @earth_relief_20m_holes.grd.

pygmt/tests/test_datasets_samples.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,16 @@ def test_earth_relief_holes():
173173
npt.assert_allclose(grid.min(), -4929.5)
174174
# Test for the NaN values in the remote file
175175
assert grid[2, 21].isnull()
176+
177+
178+
def test_maunaloa_co2():
179+
"""
180+
Check that the @MaunaLoa_CO2.txt dataset loads without errors.
181+
"""
182+
data = load_sample_data(name="maunaloa_co2")
183+
assert data.shape == (730, 2)
184+
summary = data.describe()
185+
assert summary.loc["min", "date"] == 1958.2027
186+
assert summary.loc["max", "date"] == 2019.3699
187+
assert summary.loc["min", "co2_ppm"] == 313.2
188+
assert summary.loc["max", "co2_ppm"] == 414.83

0 commit comments

Comments
 (0)