Base components¶
Base classes of the components and subcomponents.
rompy_swan.components.base¶
SWAN Components Base Module
This module provides the base classes for SWAN components in the ROMPY framework.
How to subclass:
1. Define a new model_type Literal for the subclass
2. Overwrite the cmd method to return the SWAN input file string
BaseComponent
pydantic-model
¶
BaseComponent(**data: Any)
Bases: RompyBaseModel
Base class for SWAN components.
This class is not intended to be used directly, but to be subclassed by other SWAN components to implement the following common behaviour:
- Define a
render()method to render a CMD string from the component - Split the rendered CMD if longer than 132 characters
- Forbid extra arguments so only implemented fields must be specified
Fields:
-
model_type(Literal['component'])
MultiComponents
pydantic-model
¶
MultiComponents(**data: Any)
Bases: BaseComponent
Mixin for components that can have multiple components.
Fields:
-
model_type(Literal['component']) -
components(list)
split_string
¶
split_string(
cmd: str, max_length: int = MAX_LENGTH, spaces: int = 4
) -> list
Split command cmd if longer than max_length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
str
|
SWAN CMD string to split. |
required |
max_length
|
int
|
Maximum length of each split string. |
MAX_LENGTH
|
spaces
|
int
|
Number of spaces in each identation before each new line. |
4
|
Returns:
| Name | Type | Description |
|---|---|---|
split_cmd |
list
|
List of split CMD strings. |
rompy_swan.subcomponents.base¶
SWAN Subcomponents Base Module
This module provides the base classes for SWAN subcomponents in the ROMPY framework.
BaseSubComponent
pydantic-model
¶
BaseSubComponent(**data: Any)
Bases: RompyBaseModel, ABC
Base class for SWAN sub-components.
This class is not intended to be used directly, but to be subclassed by other SWAN sub-components to implement the following common behaviour:
- Define a
render()method to render a CMD string from the subcomponent - Forbid extra arguments so only implemented fields must be specified
Fields:
-
model_type(Literal['subcomponent'])
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.
XY
pydantic-model
¶
XY(**data: Any)
Bases: BaseSubComponent
Points in problem coordinates.
Note
Coordinates should be given in m when Cartesian coordinates are used or degrees
when Spherical coordinates are used (see command COORD).
Examples:
from rompy_swan.subcomponents.base import XY
points = XY(
x=[172, 172, 172, 172.5, 173],
y=[-41, -40.5, -40, -40, -40],
fmt="0.2f",
)
print(points.render())
Fields:
Validators:
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.
IJ
pydantic-model
¶
IJ(**data: Any)
Bases: BaseSubComponent
Points in grid indices coordinates.
Grid indices are 0-based and must be in the range 0 ≤ i ≤ mx and
0 ≤ j ≤ my where mx and my are the number of cells in each
direction as defined by the CGRID command.
Note
A value of -1 may be used as a sentinel for the last grid index: -1
in the i list is replaced by mx, and -1 in the j list is
replaced by my. The substitution is performed automatically by
:meth:SwanConfig.resolve_segment_ij_sentinels when the IJ object is used
as the points of a BOUNDSPEC SEGMENT location.
Warning
SWAN terminates its SEGMENT IJ reading loop when it encounters a negative
i value, so -1 cannot be passed literally to SWAN — it must be
resolved to the actual grid index before the INPUT file is written.
Examples:
from rompy_swan.subcomponents.base import IJ
points = IJ(i=[0, 0, 5], j=[0, 19, 19])
print(points.render())
Fields:
Validators:
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.