|
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:
|
@@ -41,23 +47,30 @@ def test_grdcut_file_in_dataarray_out():
|
41 | 47 | assert outgrid.sizes["lon"] == 180
|
42 | 48 |
|
43 | 49 |
|
44 |
| -def test_grdcut_dataarray_in_file_out(): |
45 |
| - "grdcut an input DataArray, and output to a grid file" |
46 |
| - # Not supported yet. |
47 |
| - # See https://github.com/GenericMappingTools/gmt/pull/3532 |
48 |
| - |
49 |
| - |
50 |
| -def test_grdcut_dataarray_in_dataarray_out(): |
| 50 | +def test_grdcut_dataarray_in_file_out(grid): |
51 | 51 | "grdcut an input DataArray, and output to a grid file"
|
52 |
| - # Not supported yet. |
53 |
| - # 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" |
54 | 57 |
|
55 | 58 |
|
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") |
| 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 |
61 | 74 |
|
62 | 75 |
|
63 | 76 | def test_grdcut_fails():
|
|
0 commit comments