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.
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(Literal['base'])
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
¶
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.
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:
xlen
¶
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
¶
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.
XBeachDataGrid
pydantic-model
¶
XBeachDataGrid(**data: Any)
Bases: DataGrid
Xbeach data class.
Fields:
-
id(str) -
filter(Optional[Filter]) -
variables(Optional[list[str]]) -
coords(Optional[DatasetCoords]) -
crop_data(bool) -
buffer(float) -
time_buffer(list[int]) -
model_type(Literal['xbeach_data_grid']) -
source(SOURCES) -
interpolator(INTERPOLATORS)
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
filter
pydantic-field
¶
Optional filter specification to apply to the dataset
variables
pydantic-field
¶
Subset of variables to extract from the dataset
coords
pydantic-field
¶
coords: Optional[DatasetCoords] = DatasetCoords()
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
¶
Number of source data timesteps to buffer the time range if crop_data is True
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 |
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
¶
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.
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:
-
id(str) -
source(SOURCES) -
filter(Optional[Filter]) -
coords(Optional[DatasetCoords]) -
crop_data(bool) -
buffer(float) -
time_buffer(list[int]) -
interpolator(INTERPOLATORS) -
model_type(Literal['xbeach_bathy']) -
variables(Union[str, list]) -
posdwn(bool) -
left(int) -
right(int) -
extension(Union[SeawardExtensionBase, SeawardExtensionLinear]) -
interpolate_na(bool) -
interpolate_na_kwargs(dict)
Validators:
model_type
pydantic-field
¶
model_type: Literal['xbeach_bathy'] = 'xbeach_bathy'
Model type discriminator
variables
pydantic-field
¶
The variable name in the source dataset
posdwn
pydantic-field
¶
posdwn: bool = True
Bathymerty is positive down if True, positive up if False
extension
pydantic-field
¶
extension: Union[
SeawardExtensionBase, SeawardExtensionLinear
]
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
source
pydantic-field
¶
source: SOURCES
Source reader, must return a dataset with the rioxarray accessor in the open method
filter
pydantic-field
¶
Optional filter specification to apply to the dataset
coords
pydantic-field
¶
coords: Optional[DatasetCoords] = DatasetCoords()
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
¶
Number of source data timesteps to buffer the time range if crop_data is True
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 |
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
¶
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.
plot
¶
plot(
param,
isel={},
model_grid=None,
cmap="turbo",
figsize=None,
fscale=10,
borders=True,
land=True,
coastline=True,
**kwargs,
)
Plot the grid.
XBeachAccessor
¶
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
¶
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(Literal['base']) -
kwargs(dict)
get
abstractmethod
¶
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
¶
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.
RegularGridInterpolator
pydantic-model
¶
RegularGridInterpolator(**data: Any)
Bases: BaseInterpolator
Regular grid interpolator based on scipy's RegularGridInterpolator.
Fields:
-
kwargs(dict) -
model_type(Literal['scipy_regular_grid'])
model_type
pydantic-field
¶
model_type: Literal["scipy_regular_grid"] = (
"scipy_regular_grid"
)
Model type discriminator
get
¶
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
¶
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.