Ejemplo n.º 1
0
def fixture_gridfile(region):
    """
    Load the NetCDF grid file from the sample earth_relief file
    """
    with GMTTempFile(suffix=".nc") as tmpfile:
        grdcut(grid="@earth_relief_01d_g", region=region, outgrid=tmpfile.name)
        yield tmpfile.name
Ejemplo n.º 2
0
def test_grdcut_dataarray_in_dataarray_out(grid, expected_grid, region):
    """
    grdcut an input DataArray, and output as DataArray.
    """
    outgrid = grdcut(grid, region=region)
    assert isinstance(outgrid, xr.DataArray)
    xr.testing.assert_allclose(a=outgrid, b=expected_grid)
Ejemplo n.º 3
0
def test_grdcut_dataarray_in_file_out(grid):
    "grdcut an input DataArray, and output to a grid file"
    with GMTTempFile(suffix=".nc") as tmpfile:
        result = grdcut(grid, outgrid=tmpfile.name, region="0/180/0/90")
        assert result is None  # grdcut returns None if output to a file
        result = grdinfo(tmpfile.name, C=True)
        assert result == "0 180 0 90 -8182 5651.5 1 1 180 90 1 1\n"
Ejemplo n.º 4
0
def test_grdcut_dataarray_in_file_out(grid, expected_grid, region):
    """
    grdcut an input DataArray, and output to a grid file.
    """
    with GMTTempFile(suffix=".nc") as tmpfile:
        result = grdcut(grid, outgrid=tmpfile.name, region=region)
        assert result is None  # grdcut returns None if output to a file
        temp_grid = load_dataarray(tmpfile.name)
        xr.testing.assert_allclose(a=temp_grid, b=expected_grid)
Ejemplo n.º 5
0
def test_grdcut_file_in_file_out():
    """
    grdcut an input grid file, and output to a grid file.
    """
    with GMTTempFile(suffix=".nc") as tmpfile:
        result = grdcut("@earth_relief_01d", outgrid=tmpfile.name, region="0/180/0/90")
        assert result is None  # return value is None
        assert os.path.exists(path=tmpfile.name)  # check that outgrid exists
        result = grdinfo(tmpfile.name, C=True)
        assert result == "0 180 0 90 -8182 5651.5 1 1 180 90 1 1\n"
Ejemplo n.º 6
0
def test_grdcut_file_in_dataarray_out(expected_grid):
    """
    grdcut an input grid file, and output as DataArray.
    """
    outgrid = grdcut("@earth_relief_01d", region=[-3, 1, 2, 5])
    assert isinstance(outgrid, xr.DataArray)
    assert outgrid.gmt.registration == 1  # Pixel registration
    assert outgrid.gmt.gtype == 1  # Geographic type
    # check information of the output grid
    xr.testing.assert_allclose(a=outgrid, b=expected_grid)
Ejemplo n.º 7
0
def test_grdcut_file_in_file_out(expected_grid):
    """
    grdcut an input grid file, and output to a grid file.
    """
    with GMTTempFile(suffix=".nc") as tmpfile:
        result = grdcut("@earth_relief_01d",
                        outgrid=tmpfile.name,
                        region=[-3, 1, 2, 5])
        assert result is None  # return value is None
        assert os.path.exists(path=tmpfile.name)  # check that outgrid exists
        temp_grid = load_dataarray(tmpfile.name)
        xr.testing.assert_allclose(a=temp_grid, b=expected_grid)
Ejemplo n.º 8
0
def test_grdcut_dataarray_in_dataarray_out(grid):
    "grdcut an input DataArray, and output as DataArray"
    outgrid = grdcut(grid, region="0/180/0/90")
    assert isinstance(outgrid, xr.DataArray)
    # check information of the output grid
    # the '@earth_relief_01d' is in pixel registration, so the grid range is
    # not exactly 0/180/0/90
    assert outgrid.coords["lat"].data.min() == 0.5
    assert outgrid.coords["lat"].data.max() == 89.5
    assert outgrid.coords["lon"].data.min() == 0.5
    assert outgrid.coords["lon"].data.max() == 179.5
    assert outgrid.data.min() == -8182.0
    assert outgrid.data.max() == 5651.5
    assert outgrid.sizes["lat"] == 90
    assert outgrid.sizes["lon"] == 180
Ejemplo n.º 9
0
def test_grdcut_file_in_dataarray_out():
    """
    grdcut an input grid file, and output as DataArray.
    """
    outgrid = grdcut("@earth_relief_01d", region="0/180/0/90")
    assert isinstance(outgrid, xr.DataArray)
    assert outgrid.gmt.registration == 1  # Pixel registration
    assert outgrid.gmt.gtype == 1  # Geographic type
    # check information of the output grid
    # the '@earth_relief_01d' is in pixel registration, so the grid range is
    # not exactly 0/180/0/90
    assert outgrid.coords["lat"].data.min() == 0.5
    assert outgrid.coords["lat"].data.max() == 89.5
    assert outgrid.coords["lon"].data.min() == 0.5
    assert outgrid.coords["lon"].data.max() == 179.5
    assert outgrid.data.min() == -8182.0
    assert outgrid.data.max() == 5651.5
    assert outgrid.sizes["lat"] == 90
    assert outgrid.sizes["lon"] == 180
Ejemplo n.º 10
0
def test_grdcut_fails():
    """
    Check that grdcut fails correctly.
    """
    with pytest.raises(GMTInvalidInput):
        grdcut(np.arange(10).reshape((5, 2)))
Ejemplo n.º 11
0
def fixture_xrgrid(region):
    """
    Load the xarray.DataArray grid from the sample earth_relief file
    """
    return grdcut(grid="@earth_relief_01d_g", region=region)
Ejemplo n.º 12
0
def fixture_xrgrid(grid, region):
    """
    Load the xarray.DataArray grid from the sample earth_relief file.
    """
    return grdcut(grid=grid, region=region)