From 9cb1df460ef4ac7d3d21c89231bfe3b3011a01c1 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 4 Jan 2023 07:49:06 -0500 Subject: [PATCH 1/7] replace "load_usgs_quakes" with "_load_usgs_quakes" --- doc/api/index.rst | 1 - pygmt/datasets/__init__.py | 1 - pygmt/datasets/samples.py | 24 +++--------------------- pygmt/tests/test_datasets_samples.py | 5 +---- 4 files changed, 4 insertions(+), 27 deletions(-) diff --git a/doc/api/index.rst b/doc/api/index.rst index 618e95b6786..85dd09927c9 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -241,7 +241,6 @@ Use :func:`pygmt.datasets.load_sample_data` instead. datasets.load_mars_shape datasets.load_ocean_ridge_points datasets.load_sample_bathymetry - datasets.load_usgs_quakes .. automodule:: pygmt.exceptions diff --git a/pygmt/datasets/__init__.py b/pygmt/datasets/__init__.py index 87595e0b6bc..ff23fd932ad 100644 --- a/pygmt/datasets/__init__.py +++ b/pygmt/datasets/__init__.py @@ -19,5 +19,4 @@ load_ocean_ridge_points, load_sample_bathymetry, load_sample_data, - load_usgs_quakes, ) diff --git a/pygmt/datasets/samples.py b/pygmt/datasets/samples.py index 52cc349a1c8..5ca9c790c47 100644 --- a/pygmt/datasets/samples.py +++ b/pygmt/datasets/samples.py @@ -76,7 +76,6 @@ def load_sample_data(name): "japan_quakes": load_japan_quakes, "mars_shape": load_mars_shape, "ocean_ridge_points": load_ocean_ridge_points, - "usgs_quakes": load_usgs_quakes, } # Dictionary of private load functions @@ -85,6 +84,7 @@ def load_sample_data(name): "earth_relief_holes": _load_earth_relief_holes, "maunaloa_co2": _load_maunaloa_co2, "notre_dame_topography": _load_notre_dame_topography, + "usgs_quakes": _load_usgs_quakes, } if name in load_func_old: @@ -215,36 +215,18 @@ def load_sample_bathymetry(**kwargs): return data -def load_usgs_quakes(**kwargs): +def _load_usgs_quakes(): """ - (Deprecated) Load a table of global earthquakes from the USGS as a - pandas.DataFrame. - - .. warning:: Deprecated since v0.6.0. This function has been replaced with - ``load_sample_data(name="usgs_quakes")`` and will be removed in - v0.9.0. + Load a table of global earthquakes from the USGS as a pandas.DataFrame. This is the ``@usgs_quakes_22.txt`` dataset used in the GMT tutorials. - 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. Use ``print(data.describe())`` to see the available columns. """ - - if "suppress_warning" not in kwargs: - warnings.warn( - "This function has been deprecated since v0.6.0 and will be " - "removed in v0.9.0. Please use " - "load_sample_data(name='usgs_quakes') instead.", - category=FutureWarning, - stacklevel=2, - ) fname = which("@usgs_quakes_22.txt", download="c") data = pd.read_csv(fname) return data diff --git a/pygmt/tests/test_datasets_samples.py b/pygmt/tests/test_datasets_samples.py index 8fa1d8153ba..6468ab3c9e9 100644 --- a/pygmt/tests/test_datasets_samples.py +++ b/pygmt/tests/test_datasets_samples.py @@ -12,7 +12,6 @@ load_ocean_ridge_points, load_sample_bathymetry, load_sample_data, - load_usgs_quakes, ) from pygmt.exceptions import GMTInvalidInput @@ -89,9 +88,7 @@ def test_usgs_quakes(): """ Check that the dataset loads without errors. """ - with pytest.warns(expected_warning=FutureWarning) as record: - data = load_usgs_quakes() - assert len(record) == 1 + data = load_sample_data(name="usgs_quakes") assert data.shape == (1197, 22) From d6c4a08f4e7be074d6b4fc0fc82016a5aed26d89 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 4 Jan 2023 08:11:41 -0500 Subject: [PATCH 2/7] add additional checks to test_usgs_quakes() --- pygmt/tests/test_datasets_samples.py | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/pygmt/tests/test_datasets_samples.py b/pygmt/tests/test_datasets_samples.py index 6468ab3c9e9..f1e6e564733 100644 --- a/pygmt/tests/test_datasets_samples.py +++ b/pygmt/tests/test_datasets_samples.py @@ -90,6 +90,54 @@ def test_usgs_quakes(): """ data = load_sample_data(name="usgs_quakes") assert data.shape == (1197, 22) + assert list(data.columns) == [ + "time", + "latitude", + "longitude", + "depth", + "mag", + "magType", + "nst", + "gap", + "dmin", + "rms", + "net", + "id", + "updated", + "place", + "type", + "horizontalError", + "depthError", + "magError", + "magNst", + "status", + "locationSource", + "magSource", + ] + npt.assert_allclose(data["latitude"].min(), -60.6819) + npt.assert_allclose(data["latitude"].max(), 72.6309) + npt.assert_allclose(data["longitude"].min(), -179.9953) + npt.assert_allclose(data["longitude"].max(), 179.9129) + npt.assert_allclose(data["depth"].min(), -0.21) + npt.assert_allclose(data["depth"].max(), 640.49) + npt.assert_allclose(data["mag"].min(), 3) + npt.assert_allclose(data["mag"].max(), 8.1) + npt.assert_allclose(data["nst"].min(), 3) + npt.assert_allclose(data["nst"].max(), 167) + npt.assert_allclose(data["gap"].min(), 10.0) + npt.assert_allclose(data["gap"].max(), 353.0) + npt.assert_allclose(data["dmin"].min(), 0.006421) + npt.assert_allclose(data["dmin"].max(), 39.455) + npt.assert_allclose(data["rms"].min(), 0.02) + npt.assert_allclose(data["rms"].max(), 1.76) + npt.assert_allclose(data["horizontalError"].min(), 0.09) + npt.assert_allclose(data["horizontalError"].max(), 36.8) + npt.assert_allclose(data["depthError"].min(), 0) + npt.assert_allclose(data["depthError"].max(), 65.06) + npt.assert_allclose(data["magError"].min(), 0.02) + npt.assert_allclose(data["magError"].max(), 0.524) + npt.assert_allclose(data["magNst"].min(), 1) + npt.assert_allclose(data["magNst"].max(), 944) def test_fractures_compilation(): From be61e6953bb7d755f97b1c59598074162f89e3a7 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 6 Jan 2023 07:02:27 -0500 Subject: [PATCH 3/7] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com> --- pygmt/datasets/samples.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pygmt/datasets/samples.py b/pygmt/datasets/samples.py index 5ca9c790c47..7a9bd6311e4 100644 --- a/pygmt/datasets/samples.py +++ b/pygmt/datasets/samples.py @@ -219,8 +219,6 @@ def _load_usgs_quakes(): """ Load a table of global earthquakes from the USGS as a pandas.DataFrame. - This is the ``@usgs_quakes_22.txt`` dataset used in the GMT tutorials. - Returns ------- data : pandas.DataFrame From 8897d64a773b41b7dc33b0e6d2d0862d0634b004 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 14 Jan 2023 17:31:55 -0500 Subject: [PATCH 4/7] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dongdong Tian Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com> --- pygmt/datasets/samples.py | 3 +-- pygmt/tests/test_datasets_samples.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pygmt/datasets/samples.py b/pygmt/datasets/samples.py index 2db5e6d5af1..5d8e3701f2a 100644 --- a/pygmt/datasets/samples.py +++ b/pygmt/datasets/samples.py @@ -194,8 +194,7 @@ def _load_usgs_quakes(): columns. """ fname = which("@usgs_quakes_22.txt", download="c") - data = pd.read_csv(fname) - return data + return pd.read_csv(fname) def _load_fractures_compilation(): diff --git a/pygmt/tests/test_datasets_samples.py b/pygmt/tests/test_datasets_samples.py index 91359ee7689..ea2d82dde55 100644 --- a/pygmt/tests/test_datasets_samples.py +++ b/pygmt/tests/test_datasets_samples.py @@ -65,7 +65,7 @@ def test_sample_bathymetry(): def test_usgs_quakes(): """ - Check that the dataset loads without errors. + Check that the @usgs_quakes_22.txt dataset loads without errors. """ data = load_sample_data(name="usgs_quakes") assert data.shape == (1197, 22) From 0a01818374106dbcd450de155048c73e99458812 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 18 Jan 2023 08:22:56 -0500 Subject: [PATCH 5/7] Update pygmt/datasets/samples.py Co-authored-by: Dongdong Tian --- pygmt/datasets/samples.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pygmt/datasets/samples.py b/pygmt/datasets/samples.py index 5d8e3701f2a..85b3f85aa7f 100644 --- a/pygmt/datasets/samples.py +++ b/pygmt/datasets/samples.py @@ -73,7 +73,6 @@ def load_sample_data(name): "bathymetry": load_sample_bathymetry, "hotspots": load_hotspots, "mars_shape": load_mars_shape, - "ocean_ridge_points": load_ocean_ridge_points, "usgs_quakes": load_usgs_quakes, } From 25457d6c2a630ceedaff070dc742a134efe08975 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 19 Jan 2023 18:34:03 -0500 Subject: [PATCH 6/7] remove old function from load_func_old --- pygmt/datasets/samples.py | 1 - pygmt/tests/test_datasets_samples.py | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/pygmt/datasets/samples.py b/pygmt/datasets/samples.py index 9d7852bccbe..3940aa0afa2 100644 --- a/pygmt/datasets/samples.py +++ b/pygmt/datasets/samples.py @@ -72,7 +72,6 @@ def load_sample_data(name): load_func_old = { "hotspots": load_hotspots, "mars_shape": load_mars_shape, - "usgs_quakes": load_usgs_quakes, } # Dictionary of private load functions diff --git a/pygmt/tests/test_datasets_samples.py b/pygmt/tests/test_datasets_samples.py index 384d5160244..14288dbe699 100644 --- a/pygmt/tests/test_datasets_samples.py +++ b/pygmt/tests/test_datasets_samples.py @@ -4,11 +4,7 @@ import numpy.testing as npt import pandas as pd import pytest -from pygmt.datasets import ( - load_hotspots, - load_mars_shape, - load_sample_data, -) +from pygmt.datasets import load_hotspots, load_mars_shape, load_sample_data from pygmt.exceptions import GMTInvalidInput From 153c281fe0b06cd0373dd77b4108a15c9eb177a5 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 19 Jan 2023 18:37:03 -0500 Subject: [PATCH 7/7] run make format --- pygmt/datasets/__init__.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pygmt/datasets/__init__.py b/pygmt/datasets/__init__.py index eaa3a0d7d56..1cec254953f 100644 --- a/pygmt/datasets/__init__.py +++ b/pygmt/datasets/__init__.py @@ -10,8 +10,4 @@ from pygmt.datasets.earth_vertical_gravity_gradient import ( load_earth_vertical_gravity_gradient, ) -from pygmt.datasets.samples import ( - list_sample_data, - load_mars_shape, - load_sample_data, -) +from pygmt.datasets.samples import list_sample_data, load_mars_shape, load_sample_data