Skip to content

Bathymetry

XBeachBathy interpolates bathymetry onto the XBeach grid and writes the depth files. It builds on rompy's DataGrid.

rompy_xbeach.data.bathy

XBEACH Rompy bathymetry data.

logger module-attribute

logger = logging.getLogger(__name__)

SOURCES module-attribute

SOURCES = Union[load_entry_points('xbeach.source')]

INTERPOLATORS module-attribute

INTERPOLATORS = Union[
    load_entry_points("xbeach.interpolator")
]

default_interpolator module-attribute

default_interpolator = entry_points(
    group="xbeach.interpolator"
)["regular_grid"].load()

SeawardExtensionBase pydantic-model

SeawardExtensionBase(**data: Any)

Bases: RompyBaseModel, ABC

Base class for extending the data grid seaward.

Fields:

model_type pydantic-field

model_type: Literal['base'] = 'base'

Model type discriminator

get

get(
    data: Np2DArray, grid: RegularGrid, posdwn: bool
) -> tuple[Np2DArray, RegularGrid]

Override to implement the method to extend the data in the seaward direction.

Parameters:

Name Type Description Default
data Np2DArray

The data grid to extend.

required
grid RegularGrid

The grid associated with the data.

required
posdwn bool

Bathymetry is positive down if True, positive up if False.

required

Returns:

Name Type Description
data_ext ndarray

The extended data grid.

grid_ext RegularGrid

The grid associated with the extended data.

check_for_typos classmethod

check_for_typos(data: Any) -> Any

Suggest the closest field name for an unknown input key.

A field can be given by its name or, like in pydantic, by its alias.

dump_inputs_dict

dump_inputs_dict() -> dict

Return the original inputs as a dictionary.

dump_inputs_json

dump_inputs_json() -> str

Return the original inputs as a JSON string.

SeawardExtensionLinear pydantic-model

SeawardExtensionLinear(**data: Any)

Bases: SeawardExtensionBase

Linear extension of the data grid.

This class extends the data grid in the seaward direction by linearly interpolating between the existing offshore boundary and the extended boundary. The length of the extension is calculated based on the shallowest offshore depth, the depth at the extended boundary, and the maximum slope.

Fields:

model_type pydantic-field

model_type: Literal['linear'] = 'linear'

Model type discriminator

depth pydantic-field

depth: float = 25

Depth at the offshore boundary of the extended grid

slope pydantic-field

slope: float = 0.3

Slope of the linear extension

xlen

xlen(h_profile: float) -> float

Calculate the 1D extension length.

Parameters:

Name Type Description Default
h_profile float

Depth at the offshore boundary of the existing cross shore profile.

required

Returns:

Name Type Description
xlen float

The extension length in the cross shore direction (m).

get

get(
    data: Np2DArray, grid: RegularGrid, posdwn: bool
) -> tuple[Np2DArray, RegularGrid]

Extend the data in the seaward direction.

Parameters:

Name Type Description Default
data Np2DArray

The data grid to extend.

required
grid RegularGrid

The grid associated with the data.

required
posdwn bool

Bathymetry is positive down if True, positive up if False.

required

Returns:

Name Type Description
data_ext ndarray

The extended data grid.

grid_ext RegularGrid

The grid associated with the extended data.

check_for_typos classmethod

check_for_typos(data: Any) -> Any

Suggest the closest field name for an unknown input key.

A field can be given by its name or, like in pydantic, by its alias.

dump_inputs_dict

dump_inputs_dict() -> dict

Return the original inputs as a dictionary.

dump_inputs_json

dump_inputs_json() -> str

Return the original inputs as a JSON string.

XBeachDataGrid pydantic-model

XBeachDataGrid(**data: Any)

Bases: DataGrid

Xbeach data class.

Fields:

model_type pydantic-field

model_type: Literal["xbeach_data_grid"] = "xbeach_data_grid"

Model type discriminator

source pydantic-field

source: SOURCES

Source reader, must return a dataset with the rioxarray accessor in the open method

interpolator pydantic-field

interpolator: INTERPOLATORS

Interpolator for the data

crs cached property

crs

Return the coordinate reference system of the data source.

x_dim cached property

x_dim

Return the x dimension name.

y_dim cached property

y_dim

Return the y dimension name.

id pydantic-field

id: str = 'data'

Unique identifier for this data source

filter pydantic-field

filter: Optional[Filter]

Optional filter specification to apply to the dataset

variables pydantic-field

variables: Optional[list[str]] = []

Subset of variables to extract from the dataset

coords pydantic-field

Names of the coordinates in the dataset

crop_data pydantic-field

crop_data: bool = True

Update crop filters from Grid and Time objects if passed to get method

buffer pydantic-field

buffer: float = 0.0

Space to buffer the grid bounding box if crop_data is True

time_buffer pydantic-field

time_buffer: list[int] = [0, 0]

Number of source data timesteps to buffer the time range if crop_data is True

ds property

ds

Return the xarray dataset for this data source.

outfile property

outfile: str

get

get(
    destdir: str | Path,
    grid: RegularGrid,
    time: Optional[TimeRange] = None,
) -> tuple[Path, Path, list[Path], RegularGrid]

Write the data source to a new location.

Parameters:

Name Type Description Default
destdir str | Path

The destination directory to write data file to.

required
grid RegularGrid

The grid to interpolate the data to.

required
time Optional[TimeRange]

The times to filter the data to, only used if self.filter_time is True.

None

Returns:

Name Type Description
xfile Path

The path to the generated x-coordinate data file.

yfile Path

The path to the generated y-coordinate data file.

datafiles list[Path]

The paths to the generated data file for each variable.

grid RegularGrid

The grid associated with the bathymetry data.

check_for_typos classmethod

check_for_typos(data: Any) -> Any

Suggest the closest field name for an unknown input key.

A field can be given by its name or, like in pydantic, by its alias.

dump_inputs_dict

dump_inputs_dict() -> dict

Return the original inputs as a dictionary.

dump_inputs_json

dump_inputs_json() -> str

Return the original inputs as a JSON string.

plot

plot(
    param,
    isel={},
    model_grid=None,
    cmap="turbo",
    figsize=None,
    fscale=10,
    borders=True,
    land=True,
    coastline=True,
    **kwargs,
)

Plot the grid.

XBeachBathy pydantic-model

XBeachBathy(**data: Any)

Bases: XBeachDataGrid

XBeach bathymetry data class.

Fields:

Validators:

model_type pydantic-field

model_type: Literal['xbeach_bathy'] = 'xbeach_bathy'

Model type discriminator

variables pydantic-field

variables: Union[str, list] = 'data'

The variable name in the source dataset

posdwn pydantic-field

posdwn: bool = True

Bathymerty is positive down if True, positive up if False

left pydantic-field

left: int = 0

Number of points to extend the left lateral boundary

right pydantic-field

right: int = 0

Number of points to extend the right lateral boundary

extension pydantic-field

Method to extend the data seaward

interpolate_na pydantic-field

interpolate_na: bool = True

Interpolate NaN values in the source data

interpolate_na_kwargs pydantic-field

interpolate_na_kwargs: dict

Keyword arguments for the interpolate_na method

params property

params

Return the XBeach parameters for the bathy data.

id pydantic-field

id: str = 'data'

Unique identifier for this data source

source pydantic-field

source: SOURCES

Source reader, must return a dataset with the rioxarray accessor in the open method

filter pydantic-field

filter: Optional[Filter]

Optional filter specification to apply to the dataset

coords pydantic-field

Names of the coordinates in the dataset

crop_data pydantic-field

crop_data: bool = True

Update crop filters from Grid and Time objects if passed to get method

buffer pydantic-field

buffer: float = 0.0

Space to buffer the grid bounding box if crop_data is True

time_buffer pydantic-field

time_buffer: list[int] = [0, 0]

Number of source data timesteps to buffer the time range if crop_data is True

ds property

ds

Return the xarray dataset for this data source.

outfile property

outfile: str

interpolator pydantic-field

interpolator: INTERPOLATORS

Interpolator for the data

crs cached property

crs

Return the coordinate reference system of the data source.

x_dim cached property

x_dim

Return the x dimension name.

y_dim cached property

y_dim

Return the y dimension name.

single_variable pydantic-validator

single_variable() -> XBeachBathy

Ensure a single variable is provided.

expand_lateral

expand_lateral(
    data: Np2DArray, grid: RegularGrid
) -> tuple[Np2DArray, RegularGrid]

Extend the data laterally.

Parameters:

Name Type Description Default
data Np2DArray

The data grid to extend.

required
grid RegularGrid

The grid associated with the data.

required

Returns:

Name Type Description
data_ext Np2DArray

The extended data grid.

grid_ext RegularGrid

The grid associated with the extended data.

get

get(
    destdir: str | Path,
    grid: RegularGrid,
    time: Optional[TimeRange] = None,
) -> tuple[Path, Path, Path, RegularGrid]

Write the data source to a new location.

Parameters:

Name Type Description Default
destdir str | Path

The destination directory to write data file to.

required
grid RegularGrid

The grid to interpolate the data to.

required
time Optional[TimeRange]

The times to filter the data to, only used if self.filter_time is True.

None

Returns:

Name Type Description
xfile Path

The path to the generated x-coordinate data file.

yfile Path

The path to the generated y-coordinate data file.

depfile Path

The path to the generated bathymetry data file.

grid RegularGrid

The grid associated with the bathymetry data.

check_for_typos classmethod

check_for_typos(data: Any) -> Any

Suggest the closest field name for an unknown input key.

A field can be given by its name or, like in pydantic, by its alias.

dump_inputs_dict

dump_inputs_dict() -> dict

Return the original inputs as a dictionary.

dump_inputs_json

dump_inputs_json() -> str

Return the original inputs as a JSON string.

plot

plot(
    param,
    isel={},
    model_grid=None,
    cmap="turbo",
    figsize=None,
    fscale=10,
    borders=True,
    land=True,
    coastline=True,
    **kwargs,
)

Plot the grid.

XBeachAccessor

XBeachAccessor(xarray_obj)

Bases: object

XBeach accessor for xarray datasets with the model data.

plot_model_bathy

plot_model_bathy(
    grid: RegularGrid,
    variable: str = "dep",
    posdwn: bool = True,
    figsize=(15, 12),
    vmin: float = -20,
    vmax: float = 20,
    cmap: str = "terrain",
)

Plot the model bathy.

This method plots the bathymetry in real and model coordinates, and the cross-shore profiles and slopes.

Parameters:

Name Type Description Default
grid RegularGrid

The grid associated with the data.

required
variable str

The variable to plot.

'dep'
posdwn bool

Bathymetry is positive down if True, positive up if False.

True
figsize

The figure size.

(15, 12)
vmin float

The minimum value for the colormap.

-20
vmax float

The maximum value for the colormap.

20
cmap str

The colormap.

'terrain'

from_xbeach classmethod

from_xbeach(datafile, grid)

Construct an xarray bathy dataset from a XBeach data file.

Parameters:

Name Type Description Default
datafile str | Path

The path to the XBeach bathy data file.

required
grid RegularGrid

The grid associated with the data.

required

Returns:

Name Type Description
dset Dataset

The xarray dataset with the bathy data.

rompy_xbeach.interpolate

BaseInterpolator pydantic-model

BaseInterpolator(**data: Any)

Bases: ABC, RompyBaseModel

Base interpolator class.

Fields:

model_type pydantic-field

model_type: Literal['base'] = 'base'

Model type discriminator

kwargs pydantic-field

kwargs: dict = {}

Keyword arguments for the interpolator

get abstractmethod

get(
    x: Np1DArray,
    y: Np1DArray,
    data: Np2DArray,
    xi: Np2DArray,
    yi: Np2DArray,
) -> Np2DArray

Perform interpolation.

New classes should implement this which must take the x, y, and data arrays and interpolate the data to the xi, yi coordinates.

Parameters:

Name Type Description Default
x Np1DArray

The x-coordinates of the data.

required
y Np1DArray

The y-coordinates of the data.

required
data Np2DArray

The data to interpolate.

required
xi Np2DArray

The x-coordinates of the interpolated data.

required
yi Np2DArray

The y-coordinates of the interpolated data.

required

Returns:

Name Type Description
datai Np2DArray

The interpolated data.

check_for_typos classmethod

check_for_typos(data: Any) -> Any

Suggest the closest field name for an unknown input key.

A field can be given by its name or, like in pydantic, by its alias.

dump_inputs_dict

dump_inputs_dict() -> dict

Return the original inputs as a dictionary.

dump_inputs_json

dump_inputs_json() -> str

Return the original inputs as a JSON string.

RegularGridInterpolator pydantic-model

RegularGridInterpolator(**data: Any)

Bases: BaseInterpolator

Regular grid interpolator based on scipy's RegularGridInterpolator.

Fields:

model_type pydantic-field

model_type: Literal["scipy_regular_grid"] = (
    "scipy_regular_grid"
)

Model type discriminator

kwargs pydantic-field

kwargs: dict = {}

Keyword arguments for the interpolator

get

get(
    x: Np1DArray,
    y: Np1DArray,
    data: Np2DArray,
    xi: Np2DArray,
    yi: Np2DArray,
) -> Np2DArray

Interpolate the data to the grid.

Parameters:

Name Type Description Default
x Np1DArray

The x-coordinates of the data.

required
y Np1DArray

The y-coordinates of the data.

required
data Np2DArray

The data to interpolate.

required
xi Np2DArray

The x-coordinates of the interpolated data.

required
yi Np2DArray

The y-coordinates of the interpolated data.

required

Returns:

Name Type Description
datai Np2DArray

The interpolated data.

check_for_typos classmethod

check_for_typos(data: Any) -> Any

Suggest the closest field name for an unknown input key.

A field can be given by its name or, like in pydantic, by its alias.

dump_inputs_dict

dump_inputs_dict() -> dict

Return the original inputs as a dictionary.

dump_inputs_json

dump_inputs_json() -> str

Return the original inputs as a JSON string.