Skip to content

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.

logger module-attribute

logger = get_logger(__name__)

SwanGrid pydantic-model

SwanGrid(**data: Any)

Bases: RegularGrid

Regular SWAN grid in geographic space.

Fields:

Validators:

grid_type pydantic-field

grid_type: Literal['REG', 'CURV'] = 'REG'

Type of grid (REG=regular, CURV=curvilinear)

exc pydantic-field

exc: Optional[float] = None

Missing value

gridfile pydantic-field

gridfile: Optional[str] = None

Name of grid file to load

inpgrid property

inpgrid

cgrid property

cgrid

cgrid_read property

cgrid_read

component property

component

Return the respective SWAN component for this grid.

x property

x: ndarray

y property

y: ndarray

minx property

minx: float

maxx property

maxx: float

miny property

miny: float

maxy property

maxy: float

x0 pydantic-field

x0: Optional[float] = None

X coordinate of the grid origin

y0 pydantic-field

y0: Optional[float] = None

Y coordinate of the grid origin

rot pydantic-field

rot: Optional[float] = 0.0

Rotation angle of the grid in degrees

dx pydantic-field

dx: Optional[float] = None

Spacing between grid points in the x direction

dy pydantic-field

dy: Optional[float] = None

Spacing between grid points in the y direction

nx pydantic-field

nx: Optional[int] = None

Number of grid points in the x direction

ny pydantic-field

ny: Optional[int] = None

Number of grid points in the y direction

xlen property

xlen

ylen property

ylen

validate_grid_type pydantic-validator

validate_grid_type(v)

validate_curvilinear_grid pydantic-validator

validate_curvilinear_grid() -> SwanGrid

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

nearby_spectra(ds_spec, dist_thres=0.05, plot=True)

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

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.

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(
    ax=None,
    figsize=None,
    fscale=10,
    buffer=0.1,
    borders=True,
    land=True,
    coastline=True,
)

Plot the grid

generate pydantic-validator

generate() -> RegularGrid

Generate the grid from the provided parameters.

clean

clean(value: float) -> float

Round away floating-point noise (e.g. 1.4000000000000001) before writing.