SWAN
TODO: Ensure the model_type is shown next to each class in the autosummaries.
TODO: Fix broken links to classes and modules.
Grid
SwanGrid
Bases: RegularGrid
Regular SWAN grid in geographic space.
Source code in rompy_swan/grid.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
Attributes
grid_type
class-attribute
instance-attribute
grid_type: Literal['REG', 'CURV'] = Field('REG', description='Type of grid (REG=regular, CURV=curvilinear)')
exc
class-attribute
instance-attribute
gridfile
class-attribute
instance-attribute
Functions
validate_grid_type
classmethod
validate_curvilinear_grid
validate_curvilinear_grid() -> SwanGrid
boundary
Returns the grid boundary polygon.
Override the parent method to use the actual points from the regular grid boundary instead of the convex hull which is not always the boundary.
Source code in rompy_swan/grid.py
nearby_spectra
Find points nearby and project to the boundary
Parameters
ds_spec: xarray.Dataset an XArray dataset of wave spectra at a number of points. Dataset variable names standardised using wavespectra.read_* functions.
See https://wavespectra.readthedocs.io/en/latest/api.html#input-functions
dist_thres: float, optional [Default: 0.05] Maximum distance to translate the input spectra to the grid boundary plot: boolean, optional [Default: True] Generate a plot that shows the applied projections
Returns
xarray.Dataset A subset of ds_spec with lat and lon coordinates projected to the boundary
Source code in rompy_swan/grid.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
from_component
classmethod
from_component(component: GRIDREGULAR) -> SwanGrid
Swan grid from an existing component.
Parameters
component: GRIDREGULAR A GRIDREGULAR SWAN component.
Returns
SwanGrid A SwanGrid object.
Source code in rompy_swan/grid.py
Data
SwanDataGrid
Bases: DataGrid
This class is used to write SWAN data from a dataset.
Source code in rompy_swan/data.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
Attributes
z1
class-attribute
instance-attribute
z1: Optional[str] = Field(default=None, description='Name of the data variable in dataset representing either a scaler parameter or the u-componet of a vector field')
z2
class-attribute
instance-attribute
z2: Optional[str] = Field(default=None, description='Name of the data variable in dataset representing the v-componet of a vector field')
fac
class-attribute
instance-attribute
fac: float = Field(description='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`', default=1.0)
Functions
get
get(destdir: str | Path, grid: Optional[SwanGrid] = None, time: Optional[TimeRange] = None) -> Path
Write the data source to a new location.
Parameters
destdir : str | Path
The destination directory to write the netcdf data to.
grid: SwanGrid, optional
The grid to filter the data to, only used if self.filter_grid is True.
time: TimeRange, optional
The times to filter the data to, only used if self.filter_time is True.
Returns
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.
Source code in rompy_swan/data.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
Boundnest1
Bases: BoundaryWaveStation
SWAN BOUNDNEST1 NEST data class.
Source code in rompy_swan/boundary.py
Attributes
model_type
class-attribute
instance-attribute
model_type: Literal['boundnest1', 'BOUNDNEST1'] = Field(default='boundnest1', description='Model type discriminator')
rectangle
class-attribute
instance-attribute
rectangle: Literal['closed', 'open'] = Field(default='closed', description='Defines whether boundary is defined over an closed or open rectangle')
Functions
get
get(destdir: str, grid: SwanGrid, time: Optional[TimeRange] = None) -> str
Write the data source to a new location.
Parameters
destdir : str | Path
Destination directory for the SWAN ASCII file.
grid : RegularGrid
Grid instance to use for selecting the boundary points.
time: TimeRange, optional
The times to filter the data to, only used if self.crop_data is True.
Returns
filename: Path The filename of the written boundary file. cmd : str Boundary command string to render in the SWAN INPUT file
Source code in rompy_swan/boundary.py
Components
SWAN command instructions are described in Rompy by a set of pydantic models defined as
components. Each component defines a full command instruction such as PROJECT,
CGRID, GEN3, NUMERIC, etc. Inputs to the components may include other pydantic
models called subcomponents to handle more complex arguments.
Components are subclasses of rompy_swan.components.base.BaseComponent.
The base component class implements the following attribues:
-
The model_type field that should be overwritten in each component subclass. The
model_typefield is defined as aLiteraltype and is used to discriminate the exact components to use in fields defined by aUniontype of two or more components in a declarative framework (i.e., instantiating with a dict from yaml or json file). -
The cmd() method that must be overwritten in each component subclass. The
cmd()method should return either a string or a list of strings to fully define a SWAN command line instruction. A list of strings defines multiple command line instructions that are executed in sequence such as the INPGRID/READGRID components. -
The render() method that constructs the command line instruction from the content returned from the
cmd()method. Therender()method is typically called inside the__call__method of the config class to construct the specific command line instruction from that component, taking care of maximum line size, line break and line continuation.
Components are defined within the rompy_swan.components subpackage and
render an entire SWAN command line specification. The following modules are available:
- Startup Components
- CGRID Components
- INPGRID Components
- Boundary Components
- Physics Components
- Numerics Components
- Output Components
- Lockup Components
- Group Components
Subcomponents
Subcomponents are defined within the rompy_swan.subcomponents subpackage
and render part of a SWAN command line specification. They typically define specific
arguments to one or more component. The following modules are available:
- Base Subcomponents
- Startup Subcomponents
- Spectrum Subcomponents
- Time Subcomponents
- CGRID Subcomponents
- READGRID Subcomponents
- Boundary Subcomponents
- Physics Subcomponents
- Numerics Subcomponents
- Output Subcomponents
Interface
Interface classes provide an interface between swan components and higher level objects
such as TimeRange, Data and Grid objects. They are used inside the __call__
method of the config classes to pass instances of these objects to the appropriate
components and define consistent parameters to the config after instantiating them.
DataInterface
Bases: RompyBaseModel
SWAN forcing data interface.
Examples
.. ipython:: python :okwarning:
from rompy_swan.interface import DataInterface
Source code in rompy_swan/interface.py
Attributes
model_type
class-attribute
instance-attribute
model_type: Literal['data_interface', 'DATA_INTERFACE'] = Field(default='data_interface', description='Model type discriminator')
bottom
class-attribute
instance-attribute
bottom: Optional[SwanDataGrid] = Field(default=None, description='Bathymetry data')
input
class-attribute
instance-attribute
input: list[SwanDataGrid] = Field(default=[], description='Input grid data')
Functions
ensure_unique_var
classmethod
ensure_unique_var(input: list[SwanDataGrid], info: ValidationInfo) -> list[SwanDataGrid]
Ensure that each input var is unique.
Source code in rompy_swan/interface.py
get
get(staging_dir: Path, grid: SwanGrid, period: TimeRange)
Source code in rompy_swan/interface.py
BoundaryInterface
Bases: RompyBaseModel
SWAN forcing boundary interface.
Examples
.. ipython:: python :okwarning:
from rompy_swan.interface import BoundaryInterface
Source code in rompy_swan/interface.py
Attributes
model_type
class-attribute
instance-attribute
model_type: Literal['boundary_interface', 'BOUNDARY_INTERFACE'] = Field(default='boundary_interface', description='Model type discriminator')
kind
class-attribute
instance-attribute
kind: Union[Boundnest1, BoundspecSide, BoundspecSegmentXY] = Field(default=None, description='Boundary data object')
Functions
get
get(staging_dir: Path, grid: SwanGrid, period: TimeRange)
OutputInterface
Bases: TimeInterface
Output group component with consistent times.
Source code in rompy_swan/interface.py
Attributes
model_type
class-attribute
instance-attribute
model_type: Literal['outputinterface', 'OUTPUTINTERFACE'] = Field(default='outputinterface', description='Model type discriminator')
Functions
time_interface
time_interface() -> OutputInterface
Set the time parameter for all WRITE components.
Source code in rompy_swan/interface.py
LockupInterface
Bases: TimeInterface
Lockup group component with consistent times.
Source code in rompy_swan/interface.py
Attributes
model_type
class-attribute
instance-attribute
model_type: Literal['lockupinterface', 'LOCKUPINTERFACE'] = Field(default='lockupinterface', description='Model type discriminator')
Functions
time_interface
time_interface() -> LockupInterface
Set the time parameter for COMPUTE components.
Source code in rompy_swan/interface.py
Types
SWAN types provide valid values for a specific SWAN command line argument.