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 a sample dataset MaunaLoa_CO2 #1961

Merged
merged 3 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
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 "data" and "co2_ppm".
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
"""
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
Comment on lines +185 to +186
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the date column a floating point column? Should we convert it to a proper pandas datetime dtype?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a floating point number in the original dataset. My concern with converting to a date time object is that the GMT API won't recognize that input.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GenericMappingTools/pygmt-maintainers Does anyone else have an input on this? My thought is to maintain the original date type in the remote file as a float, but I don't feel that strongly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with a float-type date.

assert summary.loc["min", "co2_ppm"] == 313.2
assert summary.loc["max", "co2_ppm"] == 414.83