Skip to content

Add function to import hotspot dataset #1386

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

Merged
merged 26 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4d37512
add sphdistance.py and import statements
willschlitzer Jul 11, 2021
5b829b1
add sphdistance to index.rst
willschlitzer Jul 11, 2021
41491db
add if statement for required arguments
willschlitzer Jul 11, 2021
6a58014
add sequence for increment in sphdistance.py
willschlitzer Jul 11, 2021
164d414
add test_sphdistance.py
willschlitzer Jul 11, 2021
ae2afcf
add sphdistance docstring to sphdistance.py
willschlitzer Jul 12, 2021
0113d48
add load_hotspot to samples.py
willschlitzer Jul 14, 2021
244b8bb
add docstring to load_hotspots()
willschlitzer Jul 16, 2021
7c77a8e
add test_hotspots() to test_datasets_samples.py
willschlitzer Jul 16, 2021
60e3816
run make format
willschlitzer Jul 16, 2021
1ccc512
rename variable
willschlitzer Jul 17, 2021
c4dc675
add additional tests for test_hotspots()
willschlitzer Jul 17, 2021
411b400
format imports in test_datasets_samples.py
willschlitzer Jul 17, 2021
751f832
Update pygmt/datasets/samples.py
willschlitzer Jul 27, 2021
2fa63b0
remove sphdistance
willschlitzer Jul 27, 2021
15f9325
update test_hotspots() in test_datasets_samples.py
willschlitzer Jul 28, 2021
b1c14c1
Merge branch 'master' into add-hotspot-dataset
willschlitzer Jul 29, 2021
23f6343
add "@hotspots.txt" to testing.py
willschlitzer Jul 31, 2021
e4f8584
Update pygmt/datasets/samples.py
willschlitzer Aug 9, 2021
8089ef9
update load_hotspots() for new format of source file
willschlitzer Aug 22, 2021
9330943
Apply suggestions from code review
willschlitzer Aug 24, 2021
c146942
add load_hotspots to docs
willschlitzer Aug 24, 2021
09963fd
Merge branch 'add-hotspot-dataset' of github.com:GenericMappingTools/…
willschlitzer Aug 24, 2021
6c47e40
rename "placename" to "place_name"
willschlitzer Aug 24, 2021
1639d74
Update pygmt/datasets/samples.py
willschlitzer Aug 25, 2021
d00988a
Merge branch 'main' into add-hotspot-dataset
willschlitzer Aug 25, 2021
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
1 change: 1 addition & 0 deletions doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ and store them in the GMT cache folder.
datasets.load_sample_bathymetry
datasets.load_usgs_quakes
datasets.load_fractures_compilation
datasets.load_hotspots

.. automodule:: pygmt.exceptions

Expand Down
1 change: 1 addition & 0 deletions pygmt/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pygmt.datasets.earth_relief import load_earth_relief
from pygmt.datasets.samples import (
load_fractures_compilation,
load_hotspots,
load_japan_quakes,
load_ocean_ridge_points,
load_sample_bathymetry,
Expand Down
26 changes: 26 additions & 0 deletions pygmt/datasets/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,29 @@ def load_fractures_compilation():
fname = which("@fractures_06.txt", download="c")
data = pd.read_csv(fname, header=None, sep=r"\s+", names=["azimuth", "length"])
return data[["length", "azimuth"]]


def load_hotspots():
"""
Load a table with the locations, names, and suggested symbol sizes of
hotspots.

This is the ``@hotspots.txt`` dataset used in the GMT tutorials, with data
from Mueller, Royer, and Lawver, 1993, Geology, vol. 21, pp. 275-278. The
main 5 hotspots used by Doubrovine et al. [2012] have symbol sizes twice
the size of all other hotspots.

The data are downloaded to a cache directory (usually ``~/.gmt/cache``) the
first time you invoke this function. Afterwards, it will load the data from
the cache. So you'll need an internet connection the first time around.

Returns
-------
data : pandas.DataFrame
The data table with columns "longitude", "latitude", "symbol_size", and
"placename".
"""
fname = which("@hotspots.txt", download="c")
columns = ["longitude", "latitude", "symbol_size", "place_name"]
data = pd.read_table(filepath_or_buffer=fname, sep="\t", skiprows=3, names=columns)
return data
1 change: 1 addition & 0 deletions pygmt/helpers/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def download_test_data():
"@N00W090.earth_relief_03m_p.nc",
# Other cache files
"@fractures_06.txt",
"@hotspots.txt",
"@ridge.txt",
"@srtm_tiles.nc", # needed for 03s and 01s relief data
"@Table_5_11.txt",
Expand Down
17 changes: 17 additions & 0 deletions pygmt/tests/test_datasets_samples.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""
Test basic functionality for loading sample datasets.
"""
import pandas as pd
from pygmt.datasets import (
load_fractures_compilation,
load_hotspots,
load_japan_quakes,
load_ocean_ridge_points,
load_sample_bathymetry,
Expand Down Expand Up @@ -72,3 +74,18 @@ def test_fractures_compilation():
assert summary.loc["max", "length"] == 984.652
assert summary.loc["min", "azimuth"] == 0.0
assert summary.loc["max", "azimuth"] == 360.0


def test_hotspots():
"""
Check that the @hotspots.txt dataset loads without errors.
"""
data = load_hotspots()
assert data.shape == (55, 4)
assert data.columns.values.tolist() == [
"longitude",
"latitude",
"symbol_size",
"place_name",
]
assert isinstance(data, pd.DataFrame)