Skip to content

Commit 1ceb999

Browse files
Change test_grdcut.py to use static_earth_relief (#1742)
1 parent 5712b7f commit 1ceb999

File tree

1 file changed

+18
-34
lines changed

1 file changed

+18
-34
lines changed

pygmt/tests/test_grdcut.py

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,25 @@
77
import pytest
88
import xarray as xr
99
from pygmt import grdcut, load_dataarray
10-
from pygmt.datasets import load_earth_relief
1110
from pygmt.exceptions import GMTInvalidInput
1211
from pygmt.helpers import GMTTempFile
12+
from pygmt.helpers.testing import load_static_earth_relief
1313

1414

1515
@pytest.fixture(scope="module", name="grid")
1616
def fixture_grid():
1717
"""
1818
Load the grid data from the sample earth_relief file.
1919
"""
20-
return load_earth_relief(registration="pixel")
20+
return load_static_earth_relief()
21+
22+
23+
@pytest.fixture(scope="module", name="region")
24+
def fixture_region():
25+
"""
26+
Set the data region.
27+
"""
28+
return [-53, -49, -20, -17]
2129

2230

2331
@pytest.fixture(scope="module", name="expected_grid")
@@ -27,55 +35,31 @@ def fixture_grid_result():
2735
"""
2836
return xr.DataArray(
2937
data=[
30-
[-5069.5, -5105.0, -4937.0, -4708.0],
31-
[-4115.5, -4996.0, -4762.0, -4599.0],
32-
[-656.0, -160.0, -3484.5, -3897.5],
38+
[446.5, 481.5, 439.5, 553.0],
39+
[757.0, 570.5, 538.5, 524.0],
40+
[796.0, 886.0, 571.5, 638.5],
3341
],
34-
coords=dict(lon=[-2.5, -1.5, -0.5, 0.5], lat=[2.5, 3.5, 4.5]),
42+
coords=dict(lon=[-52.5, -51.5, -50.5, -49.5], lat=[-19.5, -18.5, -17.5]),
3543
dims=["lat", "lon"],
3644
)
3745

3846

39-
def test_grdcut_file_in_file_out(expected_grid):
40-
"""
41-
grdcut an input grid file, and output to a grid file.
42-
"""
43-
with GMTTempFile(suffix=".nc") as tmpfile:
44-
result = grdcut("@earth_relief_01d", outgrid=tmpfile.name, region=[-3, 1, 2, 5])
45-
assert result is None # return value is None
46-
assert os.path.exists(path=tmpfile.name) # check that outgrid exists
47-
temp_grid = load_dataarray(tmpfile.name)
48-
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)
49-
50-
51-
def test_grdcut_file_in_dataarray_out(expected_grid):
52-
"""
53-
grdcut an input grid file, and output as DataArray.
54-
"""
55-
outgrid = grdcut("@earth_relief_01d", region=[-3, 1, 2, 5])
56-
assert isinstance(outgrid, xr.DataArray)
57-
assert outgrid.gmt.registration == 1 # Pixel registration
58-
assert outgrid.gmt.gtype == 1 # Geographic type
59-
# check information of the output grid
60-
xr.testing.assert_allclose(a=outgrid, b=expected_grid)
61-
62-
63-
def test_grdcut_dataarray_in_file_out(grid, expected_grid):
47+
def test_grdcut_dataarray_in_file_out(grid, expected_grid, region):
6448
"""
6549
grdcut an input DataArray, and output to a grid file.
6650
"""
6751
with GMTTempFile(suffix=".nc") as tmpfile:
68-
result = grdcut(grid, outgrid=tmpfile.name, region=[-3, 1, 2, 5])
52+
result = grdcut(grid, outgrid=tmpfile.name, region=region)
6953
assert result is None # grdcut returns None if output to a file
7054
temp_grid = load_dataarray(tmpfile.name)
7155
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)
7256

7357

74-
def test_grdcut_dataarray_in_dataarray_out(grid, expected_grid):
58+
def test_grdcut_dataarray_in_dataarray_out(grid, expected_grid, region):
7559
"""
7660
grdcut an input DataArray, and output as DataArray.
7761
"""
78-
outgrid = grdcut(grid, region=[-3, 1, 2, 5])
62+
outgrid = grdcut(grid, region=region)
7963
assert isinstance(outgrid, xr.DataArray)
8064
xr.testing.assert_allclose(a=outgrid, b=expected_grid)
8165

0 commit comments

Comments
 (0)