示例#1
0
def test_grdproject_no_outgrid(grid, expected_grid):
    """
    Test grdproject with no set outgrid.
    """
    assert grid.gmt.gtype == 1  # Geographic grid
    result = grdproject(
        grid=grid, projection="M10c", spacing=3, region=[-53, -51, -20, -17]
    )
    assert result.gmt.gtype == 0  # Rectangular grid
    assert result.gmt.registration == 1  # Pixel registration
    # check information of the output grid
    xr.testing.assert_allclose(a=result, b=expected_grid)
示例#2
0
def test_grdproject_no_outgrid(grid):
    """
    Test grdproject with no set outgrid.
    """
    assert grid.gmt.gtype == 1  # Geographic grid
    temp_grid = grdproject(grid=grid, projection="M10c")
    assert temp_grid.dims == ("y", "x")
    assert temp_grid.gmt.gtype == 0  # Rectangular grid
    assert temp_grid.gmt.registration == 1  # Pixel registration
    npt.assert_allclose(temp_grid.min(), -5130.482)
    npt.assert_allclose(temp_grid.max(), -152.58528)
    npt.assert_allclose(temp_grid.median(), -4578.288)
    npt.assert_allclose(temp_grid.mean(), -4354.3296)
示例#3
0
def test_grdproject_file_out(grid):
    """
    grdproject with an outgrid set.
    """
    with GMTTempFile(suffix=".nc") as tmpfile:
        result = grdproject(grid=grid, projection="M10c", outgrid=tmpfile.name)
        assert result is None  # return value is None
        assert os.path.exists(path=tmpfile.name)  # check that outgrid exists
        result = grdinfo(tmpfile.name, per_column=True).strip().split()
        npt.assert_allclose(float(result[0]), 0)  # x min
        npt.assert_allclose(float(result[1]), 10)  # x max
        npt.assert_allclose(float(result[2]), 0, atol=1.0e-10)  # y min
        npt.assert_allclose(float(result[3]), 9.94585661273)  # y max
        npt.assert_allclose(float(result[4]), -5130.48193359)  # min
        npt.assert_allclose(float(result[5]), -152.585281372)  # max
示例#4
0
def test_grdproject_no_outgrid(grid, projection, expected_grid):
    """
    Test grdproject with no set outgrid.

    Also check that providing the projection as an EPSG code or PROJ4 string
    works.
    """
    assert grid.gmt.gtype == 1  # Geographic grid
    result = grdproject(
        grid=grid, projection=projection, spacing=3, region=[-53, -51, -20, -17]
    )
    assert result.gmt.gtype == 0  # Rectangular grid
    assert result.gmt.registration == 1  # Pixel registration
    # check information of the output grid
    xr.testing.assert_allclose(a=result, b=expected_grid)
示例#5
0
def test_grdproject_file_out(grid, expected_grid):
    """
    grdproject with an outgrid set.
    """
    with GMTTempFile(suffix=".nc") as tmpfile:
        result = grdproject(
            grid=grid,
            projection="M10c",
            outgrid=tmpfile.name,
            spacing=3,
            region=[-53, -51, -20, -17],
        )
        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)
示例#6
0
def test_grdproject_fails(grid):
    """
    Check that grdproject fails correctly.
    """
    with pytest.raises(GMTInvalidInput):
        grdproject(grid=grid)