8
8
import pandas as pd
9
9
import pytest
10
10
from pygmt import grdvolume
11
- from pygmt .datasets import load_earth_relief
12
11
from pygmt .exceptions import GMTInvalidInput
13
12
from pygmt .helpers import GMTTempFile
13
+ from pygmt .helpers .testing import load_static_earth_relief
14
14
15
15
16
16
@pytest .fixture (scope = "module" , name = "grid" )
17
17
def fixture_grid ():
18
18
"""
19
19
Load the grid data from the sample earth_relief file.
20
20
"""
21
- return load_earth_relief (resolution = "01d" , region = [- 100 , - 95 , 34 , 39 ])
21
+ return load_static_earth_relief ()
22
+
23
+
24
+ @pytest .fixture (scope = "module" , name = "region" )
25
+ def fixture_region ():
26
+ """
27
+ Set the data region for the tests.
28
+ """
29
+ return [- 53 , - 50 , - 22 , - 20 ]
22
30
23
31
24
32
@pytest .fixture (scope = "module" , name = "data" )
@@ -28,50 +36,25 @@ def fixture_data():
28
36
"""
29
37
data = np .array (
30
38
[
31
- [
32
- 2.00000000e02 ,
33
- 1.59920815e11 ,
34
- 3.16386172e13 ,
35
- 1.97839269e02 ,
36
- ],
37
- [
38
- 2.50000000e02 ,
39
- 1.44365835e11 ,
40
- 2.38676788e13 ,
41
- 1.65327751e02 ,
42
- ],
43
- [
44
- 3.00000000e02 ,
45
- 1.23788259e11 ,
46
- 1.71278707e13 ,
47
- 1.38364259e02 ,
48
- ],
49
- [
50
- 3.50000000e02 ,
51
- 9.79597525e10 ,
52
- 1.15235913e13 ,
53
- 1.17635978e02 ,
54
- ],
55
- [
56
- 4.00000000e02 ,
57
- 7.26646663e10 ,
58
- 7.22303463e12 ,
59
- 9.94022955e01 ,
60
- ],
39
+ [2.00000000e02 , 2.30079975e10 , 3.92142453e12 , 1.70437454e02 ],
40
+ [2.50000000e02 , 2.30079975e10 , 2.77102465e12 , 1.20437454e02 ],
41
+ [3.00000000e02 , 2.30079975e10 , 1.62062477e12 , 7.04374542e01 ],
42
+ [3.50000000e02 , 1.76916116e10 , 4.53991397e11 , 2.56613930e01 ],
43
+ [4.00000000e02 , 2.81602292e09 , 2.34764859e10 , 8.33675242e00 ],
61
44
]
62
45
)
63
46
return data
64
47
65
48
66
- def test_grdvolume_format (grid ):
49
+ def test_grdvolume_format (grid , region ):
67
50
"""
68
51
Test that correct formats are returned.
69
52
"""
70
- grdvolume_default = grdvolume (grid = grid )
53
+ grdvolume_default = grdvolume (grid = grid , region = region )
71
54
assert isinstance (grdvolume_default , pd .DataFrame )
72
- grdvolume_array = grdvolume (grid = grid , output_type = "numpy" )
55
+ grdvolume_array = grdvolume (grid = grid , output_type = "numpy" , region = region )
73
56
assert isinstance (grdvolume_array , np .ndarray )
74
- grdvolume_df = grdvolume (grid = grid , output_type = "pandas" )
57
+ grdvolume_df = grdvolume (grid = grid , output_type = "pandas" , region = region )
75
58
assert isinstance (grdvolume_df , pd .DataFrame )
76
59
77
60
@@ -92,21 +75,27 @@ def test_grdvolume_no_outfile(grid):
92
75
grdvolume (grid = grid , output_type = "file" )
93
76
94
77
95
- def test_grdvolume_no_outgrid (grid , data ):
78
+ def test_grdvolume_no_outgrid (grid , data , region ):
96
79
"""
97
80
Test the expected output of grdvolume with no output file set.
98
81
"""
99
- test_output = grdvolume (grid = grid , contour = [200 , 400 , 50 ], output_type = "numpy" )
82
+ test_output = grdvolume (
83
+ grid = grid , contour = [200 , 400 , 50 ], output_type = "numpy" , region = region
84
+ )
100
85
npt .assert_allclose (test_output , data )
101
86
102
87
103
- def test_grdvolume_outgrid (grid ):
88
+ def test_grdvolume_outgrid (grid , region ):
104
89
"""
105
90
Test the expected output of grdvolume with an output file set.
106
91
"""
107
92
with GMTTempFile (suffix = ".csv" ) as tmpfile :
108
93
result = grdvolume (
109
- grid = grid , contour = [200 , 400 , 50 ], output_type = "file" , outfile = tmpfile .name
94
+ grid = grid ,
95
+ contour = [200 , 400 , 50 ],
96
+ output_type = "file" ,
97
+ outfile = tmpfile .name ,
98
+ region = region ,
110
99
)
111
100
assert result is None # return value is None
112
101
assert os .path .exists (path = tmpfile .name ) # check that outfile exists
0 commit comments