Пример #1
0
def test_nearneighbor_wrong_kind_of_input(ship_data):
    """
    Run nearneighbor using grid input that is not file/matrix/vectors.
    """
    data = ship_data.bathymetry.to_xarray()  # convert pandas.Series to xarray.DataArray
    assert data_kind(data) == "grid"
    with pytest.raises(GMTInvalidInput):
        nearneighbor(
            data=data, spacing="5m", region=[245, 255, 20, 30], search_radius="10m"
        )
Пример #2
0
def test_nearneighbor_input_data(array_func, ship_data):
    """
    Run nearneighbor by passing in a numpy.array or xarray.Dataset.
    """
    data = array_func(ship_data)
    output = nearneighbor(
        data=data, spacing="5m", region=[245, 255, 20, 30], search_radius="10m"
    )
    assert isinstance(output, xr.DataArray)
    assert output.gmt.registration == 0  # Gridline registration
    assert output.gmt.gtype == 1  # Geographic type
    assert output.shape == (121, 121)
    npt.assert_allclose(output.mean(), -2378.2385)
Пример #3
0
def test_nearneighbor_input_xyz(ship_data):
    """
    Run nearneighbor by passing in x, y, z numpy.ndarrays individually.
    """
    output = nearneighbor(
        x=ship_data.longitude,
        y=ship_data.latitude,
        z=ship_data.bathymetry,
        spacing="5m",
        region=[245, 255, 20, 30],
        search_radius="10m",
    )
    assert isinstance(output, xr.DataArray)
    assert output.shape == (121, 121)
    npt.assert_allclose(output.mean(), -2378.2385)
Пример #4
0
def test_nearneighbor_with_outgrid_param(ship_data):
    """
    Run nearneighbor with the 'outgrid' parameter.
    """
    with GMTTempFile() as tmpfile:
        output = nearneighbor(
            data=ship_data,
            spacing="5m",
            region=[245, 255, 20, 30],
            outgrid=tmpfile.name,
            search_radius="10m",
        )
        assert output is None  # check that output is None since outgrid is set
        assert os.path.exists(path=tmpfile.name)  # check that outgrid exists at path
        with xr.open_dataarray(tmpfile.name) as grid:
            assert isinstance(grid, xr.DataArray)  # ensure netcdf grid loads ok
            assert grid.shape == (121, 121)
            npt.assert_allclose(grid.mean(), -2378.2385)