Exemple #1
0
def fixture_tracks():
    """
    Load track data from the sample bathymetry file.
    """
    dataframe = load_sample_bathymetry()
    dataframe.columns = ["x", "y", "z"]  # longitude, latitude, bathymetry
    return [dataframe.query(expr="z > -20")]  # reduce size of dataset
Exemple #2
0
def test_surface_input_data_array():
    """
    Run surface by passing in a numpy array into data
    """
    ship_data = load_sample_bathymetry()
    data = ship_data.values  # convert pandas.DataFrame to numpy.ndarray
    output = surface(data=data, spacing="5m", region=[245, 255, 20, 30])
    assert isinstance(output, xr.DataArray)
    return output
Exemple #3
0
def test_blockmean_wrong_kind_of_input_table_grid():
    """
    Run blockmean using table input that is not a pandas.DataFrame or file but
    a grid.
    """
    dataframe = load_sample_bathymetry()
    invalid_table = dataframe.bathymetry.to_xarray()
    assert data_kind(invalid_table) == "grid"
    with pytest.raises(GMTInvalidInput):
        blockmean(table=invalid_table, spacing="5m", region=[245, 255, 20, 30])
Exemple #4
0
def test_blockmean_wrong_kind_of_input_table_matrix():
    """
    Run blockmean using table input that is not a pandas.DataFrame but still a
    matrix.
    """
    dataframe = load_sample_bathymetry()
    invalid_table = dataframe.values
    assert data_kind(invalid_table) == "matrix"
    with pytest.raises(GMTInvalidInput):
        blockmean(table=invalid_table, spacing="5m", region=[245, 255, 20, 30])
Exemple #5
0
def test_surface_wrong_kind_of_input():
    """
    Run surface using grid input that is not file/matrix/vectors
    """
    ship_data = load_sample_bathymetry()
    data = ship_data.bathymetry.to_xarray(
    )  # convert pandas.Series to xarray.DataArray
    assert data_kind(data) == "grid"
    with pytest.raises(GMTInvalidInput):
        surface(data=data, spacing="5m", region=[245, 255, 20, 30])
Exemple #6
0
def test_sample_bathymetry():
    "Check that the @tut_ship.xyz dataset loads without errors"
    data = load_sample_bathymetry()
    assert data.shape == (82970, 3)
    summary = data.describe()
    assert summary.loc["min", "longitude"] == 245.0
    assert summary.loc["max", "longitude"] == 254.705
    assert summary.loc["min", "latitude"] == 20.0
    assert summary.loc["max", "latitude"] == 29.99131
    assert summary.loc["min", "bathymetry"] == -7708.0
    assert summary.loc["max", "bathymetry"] == -9.0
Exemple #7
0
def test_surface_input_xy_no_z():
    """
    Run surface by passing in x and y, but no z
    """
    ship_data = load_sample_bathymetry()
    with pytest.raises(GMTInvalidInput):
        surface(
            x=ship_data.longitude,
            y=ship_data.latitude,
            spacing="5m",
            region=[245, 255, 20, 30],
        )
def test_blockmedian_input_dataframe():
    """
    Run blockmedian by passing in a pandas.DataFrame as input
    """
    dataframe = load_sample_bathymetry()
    output = blockmedian(table=dataframe, spacing="5m", region=[245, 255, 20, 30])
    assert isinstance(output, pd.DataFrame)
    assert all(dataframe.columns == output.columns)
    assert output.shape == (5849, 3)
    npt.assert_allclose(output.iloc[0], [245.88819, 29.97895, -385.0])

    return output
Exemple #9
0
def test_surface_input_xyz():
    """
    Run surface by passing in x, y, z numpy.ndarrays individually
    """
    ship_data = load_sample_bathymetry()
    output = surface(
        x=ship_data.longitude,
        y=ship_data.latitude,
        z=ship_data.bathymetry,
        spacing="5m",
        region=[245, 255, 20, 30],
    )
    assert isinstance(output, xr.DataArray)
    return output
Exemple #10
0
def test_sample_bathymetry():
    """
    Check that the @tut_ship.xyz dataset loads without errors.
    """
    with pytest.warns(expected_warning=FutureWarning) as record:
        data = load_sample_bathymetry()
        assert len(record) == 1
    assert data.shape == (82970, 3)
    summary = data.describe()
    assert summary.loc["min", "longitude"] == 245.0
    assert summary.loc["max", "longitude"] == 254.705
    assert summary.loc["min", "latitude"] == 20.0
    assert summary.loc["max", "latitude"] == 29.99131
    assert summary.loc["min", "bathymetry"] == -7708.0
    assert summary.loc["max", "bathymetry"] == -9.0
Exemple #11
0
def test_surface_short_aliases():
    """
    Run surface using short aliases -I for spacing, -R for region, -G for
    outfile
    """
    ship_data = load_sample_bathymetry()
    data = ship_data.values  # convert pandas.DataFrame to numpy.ndarray
    try:
        output = surface(data=data, I="5m", R=[245, 255, 20, 30], G=TEMP_GRID)
        assert output is None  # check that output is None since outfile is set
        assert os.path.exists(
            path=TEMP_GRID)  # check that outfile exists at path
        with xr.open_dataarray(TEMP_GRID) as grid:
            assert isinstance(grid,
                              xr.DataArray)  # ensure netcdf grid loads ok
    finally:
        os.remove(path=TEMP_GRID)
    return output
Exemple #12
0
def test_surface_with_outfile_param():
    """
    Run surface with the -Goutputfile.nc parameter
    """
    ship_data = load_sample_bathymetry()
    data = ship_data.values  # convert pandas.DataFrame to numpy.ndarray
    try:
        output = surface(data=data,
                         spacing="5m",
                         region=[245, 255, 20, 30],
                         outfile=TEMP_GRID)
        assert output is None  # check that output is None since outfile is set
        assert os.path.exists(
            path=TEMP_GRID)  # check that outfile exists at path
        with xr.open_dataarray(TEMP_GRID) as grid:
            assert isinstance(grid,
                              xr.DataArray)  # ensure netcdf grid loads ok
    finally:
        os.remove(path=TEMP_GRID)
    return output
Exemple #13
0
def fixture_ship_data():
    """
    Load the data from the sample bathymetry dataset.
    """
    return load_sample_bathymetry()
Exemple #14
0
def fixture_dataframe():
    """
    Load the grid data from the sample earth_relief file.
    """
    return load_sample_bathymetry()
Exemple #15
0
def fixture_dataframe():
    """
    Load the table data from the sample bathymetry dataset.
    """
    return load_sample_bathymetry()