Skip to content

Commit 2cd454c

Browse files
authored
Add function to load the USGS quakes data (#207)
This is a dataset from the GMT tutorial of global earthquakes.
1 parent 7f7479b commit 2cd454c

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

gmt/datasets/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
22
Load sample data included with GMT (downloaded from the GMT cache server).
33
"""
4-
from .tutorial import load_japan_quakes
4+
from .tutorial import load_japan_quakes, load_usgs_quakes
55
from .earth_relief import load_earth_relief

gmt/datasets/tutorial.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,24 @@ def load_japan_quakes():
3636
"magnitude",
3737
]
3838
return data
39+
40+
41+
def load_usgs_quakes():
42+
"""
43+
Load a table of global earthquakes form the USGS as a pandas.Dataframe.
44+
45+
This is the ``@usgs_quakes_22.txt`` dataset used in the GMT tutorials.
46+
47+
The data are downloaded to a cache directory (usually ``~/.gmt/cache``) the
48+
first time you invoke this function. Afterwards, it will load the data from
49+
the cache. So you'll need an internet connection the first time around.
50+
51+
Returns
52+
-------
53+
data : pandas.Dataframe
54+
The data table. Use ``print(data.describe())`` to see the available columns.
55+
56+
"""
57+
fname = which("@usgs_quakes_22.txt", download="c")
58+
data = pd.read_csv(fname)
59+
return data

gmt/tests/test_datasets.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66
import numpy.testing as npt
77

8-
from ..datasets import load_japan_quakes, load_earth_relief
8+
from ..datasets import load_japan_quakes, load_earth_relief, load_usgs_quakes
99
from ..exceptions import GMTInvalidInput
1010

1111

@@ -22,6 +22,12 @@ def test_japan_quakes():
2222
assert summary.loc["max", "day"] == 31
2323

2424

25+
def test_usgs_quakes():
26+
"Check that the dataset loads without errors"
27+
data = load_usgs_quakes()
28+
assert data.shape == (1197, 22)
29+
30+
2531
def test_earth_relief_fails():
2632
"Make sure earth relief fails for invalid resolutions"
2733
resolutions = "1m 1d bla 60d 01s 03s 001m 03".split()

0 commit comments

Comments
 (0)