From 0f03904304642ec982fce1bbff6c436c339209cd Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 23 Jun 2022 02:26:12 +0100 Subject: [PATCH] Add a sample dataset MaunaLoa_CO2 (#1961) Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/datasets/samples.py | 17 +++++++++++++++++ pygmt/tests/test_datasets_samples.py | 13 +++++++++++++ 2 files changed, 30 insertions(+) diff --git a/pygmt/datasets/samples.py b/pygmt/datasets/samples.py index 802bfe1c55f..cf122579338 100644 --- a/pygmt/datasets/samples.py +++ b/pygmt/datasets/samples.py @@ -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", @@ -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, } @@ -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. diff --git a/pygmt/tests/test_datasets_samples.py b/pygmt/tests/test_datasets_samples.py index c66ccc3f98d..3bbe93bc5d3 100644 --- a/pygmt/tests/test_datasets_samples.py +++ b/pygmt/tests/test_datasets_samples.py @@ -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