Skip to content

Data interfaces

Base classes of the XBeach forcing interfaces (waves, water levels, wind). They select data at a point, at stations or on a grid, building on rompy's DataGrid.

rompy_xbeach.data.base

XBEACH Rompy data.

logger module-attribute

logger = logging.getLogger(__name__)

HERE module-attribute

HERE = Path(__file__).parent

SOURCES module-attribute

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

SOURCES_TS module-attribute

SOURCES_TS = Union[
    load_entry_points("rompy.source", etype="timeseries")
]

BaseData pydantic-model

BaseData(**data: Any)

Bases: DataGrid, ABC

Xbeach data class.

Fields:

source pydantic-field

source: SOURCES

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

location pydantic-field

location: Literal['centre', 'offshore', 'grid'] = 'centre'

Location to extract the data from the source dataset: 'centre' extracts the data at the centre of the grid, 'offshore' extracts the data at the middle of the offshore grid boundary, 'grid' at all grid points

time_buffer pydantic-field

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

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

crs cached property

crs

Return the coordinate reference system of the data source.

model_type pydantic-field

model_type: Literal['grid'] = 'grid'

Model type discriminator

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

ds property

ds

Return the xarray dataset for this data source.

outfile property

outfile: str

get abstractmethod

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

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
data Dataset

The dataset selected from the grid and times. This method is abstract and must be implemented by the subclass to generate the expected xbeach output.

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.

BaseDataPoint pydantic-model

BaseDataPoint(**data: Any)

Bases: BaseData

Base class to construct XBeach input from point timeseries type data.

Fields:

source pydantic-field

source: SOURCES_TS

Source reader, must return an xarray timeseries dataset in the open method

model_type pydantic-field

model_type: Literal['grid'] = 'grid'

Model type discriminator

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] = [1, 1]

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

ds property

ds

Return the xarray dataset for this data source.

outfile property

outfile: str

location pydantic-field

location: Literal['centre', 'offshore', 'grid'] = 'centre'

Location to extract the data from the source dataset: 'centre' extracts the data at the centre of the grid, 'offshore' extracts the data at the middle of the offshore grid boundary, 'grid' at all grid points

crs cached property

crs

Return the coordinate reference system of the data source.

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.

get abstractmethod

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

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
data Dataset

The dataset selected from the grid and times. This method is abstract and must be implemented by the subclass to generate the expected xbeach output.

plot

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

Plot the grid.

BaseDataStation pydantic-model

BaseDataStation(**data: Any)

Bases: BaseData

Base class to construct XBeach input from stations type data.

Fields:

sel_method pydantic-field

sel_method: Literal['idw', 'nearest'] = 'idw'

Defines which function from wavespectra.core.select to use for data selection: 'idw' uses sel_idw() for inverse distance weighting, 'nearest' uses sel_nearest() for nearest neighbor selection

sel_method_kwargs pydantic-field

sel_method_kwargs: dict = {}

Keyword arguments for sel_method

model_type pydantic-field

model_type: Literal['grid'] = 'grid'

Model type discriminator

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

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] = [1, 1]

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

ds property

ds

Return the xarray dataset for this data source.

outfile property

outfile: str

location pydantic-field

location: Literal['centre', 'offshore', 'grid'] = 'centre'

Location to extract the data from the source dataset: 'centre' extracts the data at the centre of the grid, 'offshore' extracts the data at the middle of the offshore grid boundary, 'grid' at all grid points

crs cached property

crs

Return the coordinate reference system of the data source.

validate_coords

validate_coords() -> BaseDataStation

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.

get abstractmethod

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

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
data Dataset

The dataset selected from the grid and times. This method is abstract and must be implemented by the subclass to generate the expected xbeach output.

plot

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

Plot the grid.

BaseDataGrid pydantic-model

BaseDataGrid(**data: Any)

Bases: BaseData

Base class to construct XBeach input from gridded type data.

Fields:

sel_method pydantic-field

sel_method: Literal['interp', 'sel'] = 'sel'

Defines which function from xarray to use for data selection: 'interp' uses interp() for interpolation, 'sel' uses sel() for selection

sel_method_kwargs pydantic-field

sel_method_kwargs: dict = {'method': 'nearest'}

Keyword arguments for sel_method

x_dim cached property

x_dim

Return the x dimension name.

y_dim cached property

y_dim

Return the y dimension name.

model_type pydantic-field

model_type: Literal['grid'] = 'grid'

Model type discriminator

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

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] = [1, 1]

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

ds property

ds

Return the xarray dataset for this data source.

outfile property

outfile: str

location pydantic-field

location: Literal['centre', 'offshore', 'grid'] = 'centre'

Location to extract the data from the source dataset: 'centre' extracts the data at the centre of the grid, 'offshore' extracts the data at the middle of the offshore grid boundary, 'grid' at all grid points

crs cached property

crs

Return the coordinate reference system of the data source.

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.

get abstractmethod

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

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
data Dataset

The dataset selected from the grid and times. This method is abstract and must be implemented by the subclass to generate the expected xbeach output.

plot

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

Plot the grid.

rompy_xbeach.data.forcing

XBeach forcing file writers.

This module contains helper classes for writing XBeach forcing files: - BaseFile: Abstract base class for time-series file writing - Wind: Simple constant wind parameters - WindFile: Time-varying wind file writer - TideFile: Time-varying tide/water level file writer

These classes are used internally by the data interface classes in rompy_xbeach.data.wind and rompy_xbeach.data.waterlevel.

logger module-attribute

logger = logging.getLogger(__name__)

BaseFile pydantic-model

BaseFile(**data: Any)

Bases: RompyBaseModel, ABC

Base file definition.

Fields:

Validators:

filename pydantic-field

filename: str

File name

tsec pydantic-field

tsec: list[float]

Time (s)

fmt pydantic-field

fmt: str = '%10.2f'

Format string for writing the wind file

data property

data

params property

params: dict

XBeach parameters to write to the params.txt file.

same_sizes pydantic-validator

same_sizes() -> BaseFile

write

write(destdir: str | Path)

Write the wind file.

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.

Wind pydantic-model

Wind(**data: Any)

Bases: RompyBaseModel

XBeach basic wind definition.

Fields:

windv pydantic-field

windv: float

Wind velocity

windth pydantic-field

windth: float

Wind direction

params property

params: dict

Return the XBeach wind parameters.

write

write(destdir: Optional[Union[str | Path]] = None)

Write the wind file.

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.

WindFile pydantic-model

WindFile(**data: Any)

Bases: BaseFile

XBeach wind file definition.

Fields:

Validators:

windv pydantic-field

windv: list[float]

Wind velocity (m/s)

windth pydantic-field

windth: list[float]

Wind direction (degrees)

fmt pydantic-field

fmt: str = '%10.2f'

Format string for writing the wind file

params property

params: dict

Return the XBeach wind file parameters.

filename pydantic-field

filename: str

File name

tsec pydantic-field

tsec: list[float]

Time (s)

data property

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.

same_sizes pydantic-validator

same_sizes() -> BaseFile

write

write(destdir: str | Path)

Write the wind file.

TideFile pydantic-model

TideFile(**data: Any)

Bases: BaseFile

XBeach tide file definition.

Fields:

Validators:

tsec pydantic-field

tsec: list[float]

Time (s)

zs pydantic-field

zs: list[float]

Tide elevation (m)

params property

params: dict

Return the XBeach tide file parameters.

filename pydantic-field

filename: str

File name

fmt pydantic-field

fmt: str = '%10.2f'

Format string for writing the wind file

data property

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.

same_sizes pydantic-validator

same_sizes() -> BaseFile

write

write(destdir: str | Path)

Write the wind file.