Skip to content

Commit 028b55a

Browse files
committed
Remove east_pacific_rise_grid, add test for load_ocean_ridge_points
One less dataset to test by replacing the east_pacific_rise_grid with the earth_relief 60m grid (sliced to the same area). Also add tests for loading the ocean_ridge_points dataset.
1 parent bcfab7f commit 028b55a

File tree

4 files changed

+20
-31
lines changed

4 files changed

+20
-31
lines changed

pygmt/datasets/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Load sample data included with GMT (downloaded from the GMT cache server).
44

55
from .tutorial import (
6-
load_east_pacific_rise_grid,
76
load_japan_quakes,
87
load_ocean_ridge_points,
98
load_sample_bathymetry,

pygmt/datasets/tutorial.py

-22
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,6 @@
77
from .. import which
88

99

10-
def load_east_pacific_rise_grid():
11-
"""
12-
Load a grid of bathymetry over part of the East Pacific Rise as a xarray.DataArray.
13-
14-
This is the ``@spac_33.nc`` dataset used in the GMT tutorials.
15-
16-
The data are downloaded to a cache directory (usually ``~/.gmt/cache``) the
17-
first time you invoke this function. Afterwards, it will load the data from
18-
the cache. So you'll need an internet connection the first time around.
19-
20-
Returns
21-
-------
22-
data : xarray.DataArray
23-
The data grid. Coordinates in longitude (lon) and latitude (lat).
24-
Data attributes: bathymetry (z) in metres.
25-
"""
26-
fname = which("@spac_33.nc", download="c")
27-
with xr.open_dataarray(fname) as dataarray:
28-
data = dataarray.load()
29-
return data
30-
31-
3210
def load_japan_quakes():
3311
"""
3412
Load a table of earthquakes around Japan as a pandas.Dataframe.

pygmt/tests/test_datasets.py

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from ..datasets import (
99
load_japan_quakes,
1010
load_earth_relief,
11+
load_ocean_ridge_points,
1112
load_sample_bathymetry,
1213
load_usgs_quakes,
1314
)
@@ -27,6 +28,17 @@ def test_japan_quakes():
2728
assert summary.loc["max", "day"] == 31
2829

2930

31+
def test_ocean_ridge_points():
32+
"Check that the @ridge.txt dataset loads without errors"
33+
data = load_ocean_ridge_points()
34+
assert data.shape == (4146, 2)
35+
summary = data.describe()
36+
assert summary.loc["min", "longitude"] == -179.9401
37+
assert summary.loc["max", "longitude"] == 179.935
38+
assert summary.loc["min", "latitude"] == -65.6182
39+
assert summary.loc["max", "latitude"] == 86.8
40+
41+
3042
def test_sample_bathymetry():
3143
"Check that the @tut_ship.xyz dataset loads without errors"
3244
data = load_sample_bathymetry()

pygmt/tests/test_grdtrack.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from .. import grdtrack
99
from .. import which
10-
from ..datasets import load_east_pacific_rise_grid, load_ocean_ridge_points
10+
from ..datasets import load_earth_relief, load_ocean_ridge_points
1111
from ..exceptions import GMTInvalidInput
1212
from ..helpers import data_kind
1313

@@ -17,12 +17,12 @@ def test_grdtrack_input_dataframe_and_dataarray():
1717
Run grdtrack by passing in a pandas.DataFrame and xarray.DataArray as inputs
1818
"""
1919
dataframe = load_ocean_ridge_points()
20-
dataarray = load_east_pacific_rise_grid()
20+
dataarray = load_earth_relief().sel(lat=slice(-49, -42), lon=slice(-118, -107))
2121

2222
output = grdtrack(points=dataframe, grid=dataarray, newcolname="bathymetry")
2323
assert isinstance(output, pd.DataFrame)
2424
assert output.columns.to_list() == ["longitude", "latitude", "bathymetry"]
25-
assert output.iloc[0].to_list() == [-110.9536, -42.2489, -2950.49576833]
25+
assert output.iloc[0].to_list() == [-110.9536, -42.2489, -2823.96637605]
2626

2727
return output
2828

@@ -32,12 +32,12 @@ def test_grdtrack_input_dataframe_and_ncfile():
3232
Run grdtrack by passing in a pandas.DataFrame and netcdf file as inputs
3333
"""
3434
dataframe = load_ocean_ridge_points()
35-
ncfile = which("@spac_33.nc", download="c")
35+
ncfile = which("@earth_relief_60m", download="c")
3636

3737
output = grdtrack(points=dataframe, grid=ncfile, newcolname="bathymetry")
3838
assert isinstance(output, pd.DataFrame)
3939
assert output.columns.to_list() == ["longitude", "latitude", "bathymetry"]
40-
assert output.iloc[0].to_list() == [-110.9536, -42.2489, -2950.49576833]
40+
assert output.iloc[0].to_list() == [-32.2971, 37.4118, -1697.87197487]
4141

4242
return output
4343

@@ -48,7 +48,7 @@ def test_grdtrack_wrong_kind_of_points_input():
4848
"""
4949
dataframe = load_ocean_ridge_points()
5050
invalid_points = dataframe.longitude.to_xarray()
51-
dataarray = load_east_pacific_rise_grid()
51+
dataarray = load_earth_relief().sel(lat=slice(-49, -42), lon=slice(-118, -107))
5252

5353
assert data_kind(invalid_points) == "grid"
5454
with pytest.raises(GMTInvalidInput):
@@ -60,7 +60,7 @@ def test_grdtrack_wrong_kind_of_grid_input():
6060
Run grdtrack using grid input that is not as xarray.DataArray (grid) or file
6161
"""
6262
dataframe = load_ocean_ridge_points()
63-
dataarray = load_east_pacific_rise_grid()
63+
dataarray = load_earth_relief().sel(lat=slice(-49, -42), lon=slice(-118, -107))
6464
invalid_grid = dataarray.to_dataset()
6565

6666
assert data_kind(invalid_grid) == "matrix"
@@ -73,7 +73,7 @@ def test_grdtrack_without_newcolname_setting():
7373
Run grdtrack by not passing in newcolname parameter setting
7474
"""
7575
dataframe = load_ocean_ridge_points()
76-
dataarray = load_east_pacific_rise_grid()
76+
dataarray = load_earth_relief().sel(lat=slice(-49, -42), lon=slice(-118, -107))
7777

7878
with pytest.raises(GMTInvalidInput):
7979
grdtrack(points=dataframe, grid=dataarray)

0 commit comments

Comments
 (0)