Grid¶
SwanGrid is the computational grid as a rompy grid, used by the data and boundary interfaces. It builds on rompy's RegularGrid.
SWAN Grid Module
This module provides grid-related functionality for the SWAN model within the ROMPY framework.
SwanGrid
pydantic-model
¶
SwanGrid(**data: Any)
Bases: RegularGrid
Regular SWAN grid in geographic space.
Fields:
-
x0(Optional[float]) -
y0(Optional[float]) -
rot(Optional[float]) -
dx(Optional[float]) -
dy(Optional[float]) -
nx(Optional[int]) -
ny(Optional[int]) -
grid_type(Literal['REG', 'CURV']) -
exc(Optional[float]) -
gridfile(Optional[str])
Validators:
grid_type
pydantic-field
¶
grid_type: Literal['REG', 'CURV'] = 'REG'
Type of grid (REG=regular, CURV=curvilinear)
boundary
¶
boundary(*args, **kwargs) -> tuple
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.
nearby_spectra
¶
Find points nearby and project to the boundary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds_spec
|
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 |
required | |
dist_thres
|
Maximum distance to translate the input spectra to the grid boundary |
0.05
|
|
plot
|
Generate a plot that shows the applied projections |
True
|
Returns:
| Type | Description |
|---|---|
Dataset
|
A subset of ds_spec with lat and lon coordinates projected to the boundary |
from_component
classmethod
¶
from_component(component: GRIDREGULAR) -> SwanGrid
Swan grid from an existing component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
GRIDREGULAR
|
A GRIDREGULAR SWAN component. |
required |
Returns:
| Type | Description |
|---|---|
SwanGrid
|
A SwanGrid object. |
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.
bbox
¶
bbox(buffer=0.0) -> Bbox
Returns a bounding box for the spatial grid
This function returns a list [ll_x, ll_y, ur_x, ur_y] where ll_x, ll_y (ur_x, ur_y) are the lower left (upper right) x and y coordinates bounding box of the model domain
boundary_points
¶
boundary_points(spacing=None, tolerance=0.2) -> tuple
Returns array of coordinates from boundary polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance
|
Simplify polygon shape based on maximum distance from original geometry, see https://shapely.readthedocs.io/en/stable/manual.html#object.simplify. |
0.2
|
|
spacing
|
If specified, points are returned evenly spaced along the boundary at the specified spacing, otherwise all points are returned. |
None
|
Returns:
points: tuple Tuple of x and y coordinates of the boundary points.
plot
¶
Plot the grid
generate
pydantic-validator
¶
generate() -> RegularGrid
Generate the grid from the provided parameters.