12
12
from ..helpers import GMTTempFile
13
13
14
14
15
+ @pytest .fixture (scope = "module" , name = "grid" )
16
+ def fixture_grid ():
17
+ "Load the grid data from the sample earth_relief file"
18
+ return load_earth_relief (registration = "pixel" )
19
+
20
+
15
21
def test_grdcut_file_in_file_out ():
16
22
"grduct an input grid file, and output to a grid file"
17
23
with GMTTempFile (suffix = ".nc" ) as tmpfile :
@@ -26,6 +32,8 @@ def test_grdcut_file_in_dataarray_out():
26
32
"grdcut an input grid file, and output as DataArray"
27
33
outgrid = grdcut ("@earth_relief_01d" , region = "0/180/0/90" )
28
34
assert isinstance (outgrid , xr .DataArray )
35
+ assert outgrid .gmt .registration == 1 # Pixel registration
36
+ assert outgrid .gmt .gtype == 1 # Geographic type
29
37
# check information of the output grid
30
38
# the '@earth_relief_01d' is in pixel registration, so the grid range is
31
39
# not exactly 0/180/0/90
@@ -39,23 +47,30 @@ def test_grdcut_file_in_dataarray_out():
39
47
assert outgrid .sizes ["lon" ] == 180
40
48
41
49
42
- def test_grdcut_dataarray_in_file_out ():
43
- "grdcut an input DataArray, and output to a grid file"
44
- # Not supported yet.
45
- # See https://github.com/GenericMappingTools/gmt/pull/3532
46
-
47
-
48
- def test_grdcut_dataarray_in_dataarray_out ():
50
+ def test_grdcut_dataarray_in_file_out (grid ):
49
51
"grdcut an input DataArray, and output to a grid file"
50
- # Not supported yet.
51
- # See https://github.com/GenericMappingTools/gmt/pull/3532
52
+ with GMTTempFile (suffix = ".nc" ) as tmpfile :
53
+ result = grdcut (grid , outgrid = tmpfile .name , region = "0/180/0/90" )
54
+ assert result is None # grdcut returns None if output to a file
55
+ result = grdinfo (tmpfile .name , C = True )
56
+ assert result == "0 180 0 90 -8182 5651.5 1 1 180 90 1 1\n "
52
57
53
58
54
- def test_grdcut_dataarray_in_fail ():
55
- "Make sure that grdcut fails correctly if DataArray is the input grid"
56
- with pytest .raises (NotImplementedError ):
57
- grid = load_earth_relief ()
58
- grdcut (grid , region = "0/180/0/90" )
59
+ def test_grdcut_dataarray_in_dataarray_out (grid ):
60
+ "grdcut an input DataArray, and output as DataArray"
61
+ outgrid = grdcut (grid , region = "0/180/0/90" )
62
+ assert isinstance (outgrid , xr .DataArray )
63
+ # check information of the output grid
64
+ # the '@earth_relief_01d' is in pixel registration, so the grid range is
65
+ # not exactly 0/180/0/90
66
+ assert outgrid .coords ["lat" ].data .min () == 0.5
67
+ assert outgrid .coords ["lat" ].data .max () == 89.5
68
+ assert outgrid .coords ["lon" ].data .min () == 0.5
69
+ assert outgrid .coords ["lon" ].data .max () == 179.5
70
+ assert outgrid .data .min () == - 8182.0
71
+ assert outgrid .data .max () == 5651.5
72
+ assert outgrid .sizes ["lat" ] == 90
73
+ assert outgrid .sizes ["lon" ] == 180
59
74
60
75
61
76
def test_grdcut_fails ():
0 commit comments