Skip to content

Data and boundary interfaces

Interfaces fill in what depends on the run: they write input grids and boundary spectra from data sources, and set the times of the computation and output from the run period.

rompy_swan.interface

SWAN Interface Module

This module provides interface classes for SWAN model components in the ROMPY framework.

logger module-attribute

logger = get_logger(__name__)

DataInterface pydantic-model

DataInterface(**data: Any)

Bases: RompyBaseModel

SWAN forcing data interface.

Examples
from rompy_swan.interface import DataInterface

Fields:

Validators:

model_type pydantic-field

model_type: Literal["data_interface", "DATA_INTERFACE"] = (
    "data_interface"
)

Model type discriminator

bottom pydantic-field

bottom: Optional[SwanDataGrid] = None

Bathymetry data

input pydantic-field

input: list[SwanDataGrid] = []

Input grid data

ensure_unique_var pydantic-validator

ensure_unique_var(
    input: list[SwanDataGrid], info: ValidationInfo
) -> list[SwanDataGrid]

Ensure that each input var is unique.

get

get(staging_dir: Path, grid: SwanGrid, period: TimeRange)

render

render(*args, **kwargs)

Make this class consistent with the components API.

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.

BoundaryInterface pydantic-model

BoundaryInterface(**data: Any)

Bases: RompyBaseModel

SWAN forcing boundary interface.

Examples
from rompy_swan.interface import BoundaryInterface

Fields:

model_type pydantic-field

model_type: Literal[
    "boundary_interface", "BOUNDARY_INTERFACE"
] = "boundary_interface"

Model type discriminator

kind pydantic-field

Boundary data object

get

get(staging_dir: Path, grid: SwanGrid, period: TimeRange)

render

render(*args, **kwargs)

Make this class consistent with the components API.

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.

TimeInterface pydantic-model

TimeInterface(**data: Any)

Bases: RompyBaseModel

Base interface to pass time to group components.

This class is used to set consistent time parameters in a group component by redefining existing times component attribute based on the period field.

Fields:

model_type pydantic-field

model_type: Literal['interface', 'INTERFACE'] = 'interface'

Model type discriminator

group pydantic-field

group: Any

Group component to set times to

period pydantic-field

period: TimeRange

Time period to write the output over

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.

OutputInterface pydantic-model

OutputInterface(**data: Any)

Bases: TimeInterface

Output group component with consistent times.

Fields:

Validators:

model_type pydantic-field

model_type: Literal[
    "outputinterface", "OUTPUTINTERFACE"
] = "outputinterface"

Model type discriminator

group pydantic-field

group: Any

Group component to set times to

period pydantic-field

period: TimeRange

Time period to write the output over

time_interface pydantic-validator

time_interface() -> OutputInterface

Set the time parameter for all WRITE components.

Note
  • tbeg is set from the component's times if defined, otherwise from the runtime start
  • delt is set from the component's times if defined, otherwise from the runtime interval
  • tfmt is set from the component's times if defined, otherwise from TimeRange default
  • dfmt is set from the component's times if defined, otherwise from TimeRange default
  • suffix is set to the suffix of the component

A user-defined tbeg lets output start after a model spin-up period so the spin-up is excluded from output files.

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.

LockupInterface pydantic-model

LockupInterface(**data: Any)

Bases: TimeInterface

Lockup group component with consistent times.

Fields:

Validators:

model_type pydantic-field

model_type: Literal[
    "lockupinterface", "LOCKUPINTERFACE"
] = "lockupinterface"

Model type discriminator

group pydantic-field

group: Any

Group component to set times to

period pydantic-field

period: TimeRange

Time period to write the output over

time_interface pydantic-validator

time_interface() -> LockupInterface

Set the time parameter for COMPUTE components.

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.

rompy_swan.data

SWAN Data Module

This module provides data handling functionality for the SWAN model within the ROMPY framework.

logger module-attribute

logger = get_logger(__name__)

FILL_VALUE module-attribute

FILL_VALUE = -99.0

SwanDataGrid pydantic-model

SwanDataGrid(**data: Any)

Bases: DataGrid

This class is used to write SWAN data from a dataset.

Fields:

Validators:

z1 pydantic-field

z1: Optional[str] = None

Name of the data variable in dataset representing either a scaler parameter or the u-componet of a vector field

z2 pydantic-field

z2: Optional[str] = None

Name of the data variable in dataset representing the v-componet of a vector field

var pydantic-field

SWAN input grid name

fac pydantic-field

fac: float = 1.0

SWAN multiplies all values that are read from file by fac. For instance if the values are given in unit decimeter, one should make fac=0.1 to obtain values in m. To change sign use a negative fac

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 reader, must return an xarray gridded dataset 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] = [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

ensure_z1_in_data_vars pydantic-validator

ensure_z1_in_data_vars() -> SwanDataGrid

get

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

Write the data source to a new location.

Parameters:

Name Type Description Default
destdir str | Path

The destination directory to write the netcdf data to.

required
grid Optional[SwanGrid]

The grid to filter the data to, only used if self.filter_grid is True.

None
time Optional[TimeRange]

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

None

Returns:

Name Type Description
cmd str

The command line string with the INPGRID/READINP commands ready to be written to the SWAN input file.

Note

The data are assumed to not have been rotated. We cannot use the grid.rot attr as this is the rotation from the model grid object which is not necessarily the same as the rotation of the 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.

Swan_accessor

Swan_accessor(xarray_obj)

Bases: object

grid

grid(
    x: str = "lon",
    y: str = "lat",
    rot: float = 0.0,
    exc: float = FILL_VALUE,
)

SWAN Grid object for this dataset.

Parameters:

Name Type Description Default
x str

Name of the x coordinate variable.

'lon'
y str

Name of the y coordinate variable.

'lat'
rot float

Rotation angle in degrees, required if the grid has been previously rotated.

0.0
exc float

Exception value for missing data.

FILL_VALUE

Returns:

Name Type Description
grid SwanGrid

SwanGrid object representing this dataset.

to_bottom_grid

to_bottom_grid(
    output_file,
    fmt="%4.2f",
    x="lon",
    y="lat",
    z="depth",
    fac=1.0,
    rot=0.0,
    vmin=float("-inf"),
    fill_value=FILL_VALUE,
)

Write SWAN inpgrid BOTTOM file.

Parameters:

Name Type Description Default
output_file

Local file name for the ascii output file.

required
fmt

String float formatter.

'%4.2f'
x

Name of the x-axis in the dataset.

'lon'
y

Name of the y-axis in the dataset.

'lat'
z

Name of the bottom variable in the dataset.

'depth'
rot

Rotation angle, required if the grid has been previously rotated.

0.0
vmin

Minimum value below which depths are masked.

float('-inf')
fill_value

Fill value.

FILL_VALUE
fac

Multiplying factor in case data are not in m or should be reversed.

1.0

Returns:

Name Type Description
inpgrid str

SWAN INPgrid command instruction.

readinp str

SWAN READinp command instruction.

TODO Merge this method with `to_inpgrid`.

to_inpgrid

to_inpgrid(
    output_file: str,
    var: str = "WIND",
    fmt: str = "%.2f",
    x: str = "lon",
    y: str = "lat",
    z1: str = "u10",
    z2: str | None = None,
    fac: float = 1.0,
    rot: float = 0.0,
    time: str = "time",
)

This function writes to a SWAN inpgrid format file (i.e. WIND)

Parameters:

Name Type Description Default
output_file str

Local file name for the ascii output file.

required
var str

Type of swan input, used to define the INPGRID/READGRID strings.

'WIND'
fmt str

String float formatter.

'%.2f'
x str

Name of the x-axis in the dataset.

'lon'
y str

Name of the y-axis in the dataset.

'lat'
z1 str

Name of the first variable in the dataset.

'u10'
z2 str | None

Name of the second variable in the dataset.

None
fac float

Multiplying factor in case data are not in m or should be reversed.

1.0
rot float

Rotation angle, required if the grid has been previously rotated.

0.0
time str

Name of the time variable in the dataset

'time'

Returns:

Name Type Description
inpgrid str

SWAN INPgrid command instruction.

readinp str

SWAN READinp command instruction.

to_tpar_boundary

to_tpar_boundary(
    dest_path,
    boundary,
    interval,
    x_var="lon",
    y_var="lat",
    hs_var="sig_wav_ht",
    per_var="pk_wav_per",
    dir_var="pk_wav_dir",
    dir_spread=20.0,
)

This function writes parametric boundary forcing to a set of TPAR files at a given distance based on gridded wave output. It returns the string to be included in the Swan INPUT file.

At present simple nearest neighbour point lookup is used.

Args: TBD

dset_to_swan

dset_to_swan(
    dset: Dataset,
    output_file: str,
    variables: list,
    fmt: str = "%4.2f",
    fill_value: float = FILL_VALUE,
    time_dim="time",
)

Convert xarray Dataset into SWAN ASCII file.

Parameters:

Name Type Description Default
dset Dataset

Dataset to write in SWAN ASCII format.

required
output_file str

Local file name for the ascii output file.

required
variables list

Variables to write to ascii.

required
fmt str

String float formatter.

'%4.2f'
fill_value float

Fill value.

FILL_VALUE
time_dim

Name of the time dimension if available in the dataset.

'time'

rompy_swan.boundary

SWAN Boundary Module

This module provides boundary condition handling for the SWAN model within the ROMPY framework.

logger module-attribute

logger = get_logger(__name__)

MISSING_SPECTRA_HINT module-attribute

MISSING_SPECTRA_HINT = "The boundary points are probably outside the spectra dataset or beyond the selection tolerance: check `sel_method_kwargs` and the extent of the source, or use sel_method='nearest'."

Boundnest1 pydantic-model

Boundnest1(**data: Any)

Bases: BoundaryWaveStation

SWAN BOUNDNEST1 NEST data class.

Fields:

Validators:

model_type pydantic-field

model_type: Literal["boundnest1", "BOUNDNEST1"] = (
    "boundnest1"
)

Model type discriminator

rectangle pydantic-field

rectangle: Literal['closed', 'open'] = 'closed'

Defines whether boundary is defined over an closed or open rectangle

id pydantic-field

id: str

Unique identifier for this data source

source pydantic-field

Dataset source reader, must return a wavespectra-enabled xarray dataset 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 filter from Time object if passed to get method

buffer pydantic-field

buffer: float = 2.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 filtered xarray dataset instance.

outfile property

outfile: str

spacing pydantic-field

spacing: Optional[Union[float, Literal['parent']]] = None

Spacing between points along the grid boundary to retrieve data for. If None (default), points are defined from the the actual grid object passed to the get method. If 'parent', the resolution of the parent dataset is used to define the spacing.

sel_method pydantic-field

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

Wavespectra method to use for selecting boundary points from the dataset

sel_method_kwargs pydantic-field

sel_method_kwargs: dict = {}

Keyword arguments for sel_method

grid_type pydantic-field

grid_type: Literal["boundary_wave_station"] = (
    "boundary_wave_station"
)

Model type discriminator

get

get(
    destdir: str,
    grid: SwanGrid,
    time: Optional[TimeRange] = None,
) -> str

Write the data source to a new location.

Parameters:

Name Type Description Default
destdir str | Path

Destination directory for the SWAN ASCII file.

required
grid RegularGrid

Grid instance to use for selecting the boundary points.

required
time Optional[TimeRange]

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

None

Returns:

Name Type Description
filename Path

The filename of the written boundary file.

cmd str

Boundary command string to render in the SWAN INPUT 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.

plot

plot(
    model_grid=None,
    cmap="turbo",
    fscale=10,
    ax=None,
    **kwargs,
)

spacing_gt_zero pydantic-validator

spacing_gt_zero(v)

plot_boundary

plot_boundary(grid=None, fscale=10, ax=None, **kwargs)

Plot the boundary points on a map.

BoundspecBase pydantic-model

BoundspecBase(**data: Any)

Bases: BoundaryWaveStation, ABC

Base class for SWAN BOUNDSPEC data classes.

Fields:

Validators:

model_type pydantic-field

model_type: Literal["boundspecbase", "BOUNDSPECBASE"] = (
    "boundspecbase"
)

Model type discriminator

shapespec pydantic-field

shapespec: SHAPESPEC = SHAPESPEC(dspr_type='degrees')

Spectral shape specification

variable pydantic-field

variable: bool = False

Whether the spectra can vary along the side

file_type pydantic-field

file_type: Literal['tpar', 'spec2d'] = 'tpar'

The type of file to write

per property

per: str

dspr property

dspr: str

tpar property

tpar: DataFrame

TPAR dataframe for the _ds attr.

id pydantic-field

id: str

Unique identifier for this data source

source pydantic-field

Dataset source reader, must return a wavespectra-enabled xarray dataset 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 filter from Time object if passed to get method

buffer pydantic-field

buffer: float = 2.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 filtered xarray dataset instance.

outfile property

outfile: str

spacing pydantic-field

spacing: Optional[Union[float, Literal['parent']]] = None

Spacing between points along the grid boundary to retrieve data for. If None (default), points are defined from the the actual grid object passed to the get method. If 'parent', the resolution of the parent dataset is used to define the spacing.

sel_method pydantic-field

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

Wavespectra method to use for selecting boundary points from the dataset

sel_method_kwargs pydantic-field

sel_method_kwargs: dict = {}

Keyword arguments for sel_method

grid_type pydantic-field

grid_type: Literal["boundary_wave_station"] = (
    "boundary_wave_station"
)

Model type discriminator

unique_not_supported pydantic-validator

unique_not_supported(kwargs: dict) -> dict

variable_not_implemented pydantic-validator

variable_not_implemented(v, values)

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

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

Write the selected boundary data to a netcdf file.

Parameters:

Name Type Description Default
destdir str | Path

Destination directory for the netcdf file.

required
grid RegularGrid

Grid instance to use for selecting the boundary points.

required
time Optional[TimeRange]

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

None

Returns:

Name Type Description
outfile Path

Path to the netcdf file.

plot

plot(
    model_grid=None,
    cmap="turbo",
    fscale=10,
    ax=None,
    **kwargs,
)

spacing_gt_zero pydantic-validator

spacing_gt_zero(v)

plot_boundary

plot_boundary(grid=None, fscale=10, ax=None, **kwargs)

Plot the boundary points on a map.

BoundspecSide pydantic-model

BoundspecSide(**data: Any)

Bases: BoundspecBase

SWAN BOUNDSPEC SIDE data class.

TODO: Handle side definition on a rotated grid. TODO: Should SIDE VARIABE be supported? TODO: Support option to choose between mid-point or averaging? TODO: Does PAR need to be supported? Guess not as nonstationary isn't supported

Note

The 'spec1d' file type is not supported yet.

Fields:

Validators:

model_type pydantic-field

model_type: Literal["boundspecside", "BOUNDSPECSIDE"] = (
    "boundspecside"
)

Model type discriminator

location pydantic-field

location: SIDE

The side of the grid to apply the boundary to

id pydantic-field

id: str

Unique identifier for this data source

source pydantic-field

Dataset source reader, must return a wavespectra-enabled xarray dataset 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 filter from Time object if passed to get method

buffer pydantic-field

buffer: float = 2.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 filtered xarray dataset instance.

outfile property

outfile: str

spacing pydantic-field

spacing: Optional[Union[float, Literal['parent']]] = None

Spacing between points along the grid boundary to retrieve data for. If None (default), points are defined from the the actual grid object passed to the get method. If 'parent', the resolution of the parent dataset is used to define the spacing.

sel_method pydantic-field

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

Wavespectra method to use for selecting boundary points from the dataset

sel_method_kwargs pydantic-field

sel_method_kwargs: dict = {}

Keyword arguments for sel_method

grid_type pydantic-field

grid_type: Literal["boundary_wave_station"] = (
    "boundary_wave_station"
)

Model type discriminator

shapespec pydantic-field

shapespec: SHAPESPEC = SHAPESPEC(dspr_type='degrees')

Spectral shape specification

variable pydantic-field

variable: bool = False

Whether the spectra can vary along the side

file_type pydantic-field

file_type: Literal['tpar', 'spec2d'] = 'tpar'

The type of file to write

per property

per: str

dspr property

dspr: str

tpar property

tpar: DataFrame

TPAR dataframe for the _ds attr.

get

get(
    destdir: str,
    grid: SwanGrid,
    time: Optional[TimeRange] = None,
) -> str

Write the data source to a new location.

Parameters:

Name Type Description Default
destdir str | Path

Destination directory for the SWAN ASCII file.

required
grid RegularGrid

Grid instance to use for selecting the boundary points.

required
time Optional[TimeRange]

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

None

Returns:

Name Type Description
filename Path

The filename of the written boundary file.

cmd str

Boundary command string to render in the SWAN INPUT 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.

plot

plot(
    model_grid=None,
    cmap="turbo",
    fscale=10,
    ax=None,
    **kwargs,
)

spacing_gt_zero pydantic-validator

spacing_gt_zero(v)

plot_boundary

plot_boundary(grid=None, fscale=10, ax=None, **kwargs)

Plot the boundary points on a map.

unique_not_supported pydantic-validator

unique_not_supported(kwargs: dict) -> dict

variable_not_implemented pydantic-validator

variable_not_implemented(v, values)

BoundspecSegmentXY pydantic-model

BoundspecSegmentXY(**data: Any)

Bases: BoundspecBase

SWAN BOUNDSPEC SEGMENT data class.

TODO: Handle side definition on a rotated grid. TODO: Should SIDE VARIABE be supported? TODO: Support option to choose between mid-point or averaging? TODO: Does PAR need to be supported? Guess not as nonstationary isn't supported TODO: If SIDES, ensure continuous

Note

Segments are defined from adjacent point locations so the order in which the points are defined is important. When using SIDES, please ensure SIDES are adjacent to each other and have correct directions (ccw or clockwise) accordint to the order in which each side is prescribed.

Note

The 'spec1d' file type is not supported yet.

Fields:

Validators:

model_type pydantic-field

model_type: Literal[
    "boundspecsegmentxy", "BOUNDSPECSEGMENTXY"
] = "boundspecsegmentxy"

Model type discriminator

location pydantic-field

location: Union[SIDE, SIDES, XY]

The side of the grid to apply the boundary to

id pydantic-field

id: str

Unique identifier for this data source

source pydantic-field

Dataset source reader, must return a wavespectra-enabled xarray dataset 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 filter from Time object if passed to get method

buffer pydantic-field

buffer: float = 2.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 filtered xarray dataset instance.

outfile property

outfile: str

spacing pydantic-field

spacing: Optional[Union[float, Literal['parent']]] = None

Spacing between points along the grid boundary to retrieve data for. If None (default), points are defined from the the actual grid object passed to the get method. If 'parent', the resolution of the parent dataset is used to define the spacing.

sel_method pydantic-field

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

Wavespectra method to use for selecting boundary points from the dataset

sel_method_kwargs pydantic-field

sel_method_kwargs: dict = {}

Keyword arguments for sel_method

grid_type pydantic-field

grid_type: Literal["boundary_wave_station"] = (
    "boundary_wave_station"
)

Model type discriminator

shapespec pydantic-field

shapespec: SHAPESPEC = SHAPESPEC(dspr_type='degrees')

Spectral shape specification

variable pydantic-field

variable: bool = False

Whether the spectra can vary along the side

file_type pydantic-field

file_type: Literal['tpar', 'spec2d'] = 'tpar'

The type of file to write

per property

per: str

dspr property

dspr: str

tpar property

tpar: DataFrame

TPAR dataframe for the _ds attr.

get

get(
    destdir: str,
    grid: SwanGrid,
    time: Optional[TimeRange] = None,
) -> str

Write the data source to a new location.

Parameters:

Name Type Description Default
destdir str | Path

Destination directory for the SWAN ASCII file.

required
grid RegularGrid

Grid instance to use for selecting the boundary points.

required
time Optional[TimeRange]

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

None

Returns:

Name Type Description
filenames list

The filenames of the written boundary files.

cmd str

Boundary command string to render in the SWAN INPUT 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.

plot

plot(
    model_grid=None,
    cmap="turbo",
    fscale=10,
    ax=None,
    **kwargs,
)

spacing_gt_zero pydantic-validator

spacing_gt_zero(v)

plot_boundary

plot_boundary(grid=None, fscale=10, ax=None, **kwargs)

Plot the boundary points on a map.

unique_not_supported pydantic-validator

unique_not_supported(kwargs: dict) -> dict

variable_not_implemented pydantic-validator

variable_not_implemented(v, values)

check_spectra

check_spectra(ds, filename: str | Path)

Raise an error if the boundary spectra have missing values.

write_tpar

write_tpar(df: DataFrame, filename: str | Path)

Write TPAR file.

Parameters:

Name Type Description Default
df DataFrame

TPAR dataframe.

required
filename str | Path

Filename to write to.

required