@@ -43,21 +43,30 @@ def test_grdcut_file_in_dataarray_out():
4343
4444def test_grdcut_dataarray_in_file_out ():
4545 "grdcut an input DataArray, and output to a grid file"
46- # Not supported yet.
47- # See https://github.com/GenericMappingTools/gmt/pull/3532
46+ ingrid = load_earth_relief ()
47+ with GMTTempFile (suffix = ".nc" ) as tmpfile :
48+ result = grdcut (ingrid , outgrid = tmpfile .name , region = "0/180/0/90" )
49+ assert result is None # grdcut returns None if output to a file
50+ result = grdinfo (tmpfile .name , C = True )
51+ assert result == "0 180 0 90 -8182 5651.5 1 1 180 90 1 1"
4852
4953
5054def test_grdcut_dataarray_in_dataarray_out ():
51- "grdcut an input DataArray, and output to a grid file"
52- # Not supported yet.
53- # See https://github.com/GenericMappingTools/gmt/pull/3532
54-
55-
56- def test_grdcut_dataarray_in_fail ():
57- "Make sure that grdcut fails correctly if DataArray is the input grid"
58- with pytest .raises (NotImplementedError ):
59- grid = load_earth_relief ()
60- grdcut (grid , region = "0/180/0/90" )
55+ "grdcut an input DataArray, and output as DataArray"
56+ ingrid = load_earth_relief ()
57+ outgrid = grdcut (ingrid , region = "0/180/0/90" )
58+ assert isinstance (outgrid , xr .DataArray )
59+ # check information of the output grid
60+ # the '@earth_relief_01d' is in pixel registration, so the grid range is
61+ # not exactly 0/180/0/90
62+ assert outgrid .coords ["lat" ].data .min () == 0.5
63+ assert outgrid .coords ["lat" ].data .max () == 89.5
64+ assert outgrid .coords ["lon" ].data .min () == 0.5
65+ assert outgrid .coords ["lon" ].data .max () == 179.5
66+ assert outgrid .data .min () == - 8182.0
67+ assert outgrid .data .max () == 5651.5
68+ assert outgrid .sizes ["lat" ] == 90
69+ assert outgrid .sizes ["lon" ] == 180
6170
6271
6372def test_grdcut_fails ():
0 commit comments