Skip to content

Grid

The XBeach grid. RegularGrid builds on rompy's BaseGrid.

XBEACH Rompy grid.

logger module-attribute

logger = logging.getLogger(__name__)

HERE module-attribute

HERE = Path(__file__).parent

CRS_TYPES module-attribute

CRS_TYPES = Union[
    str, int, CRS, cartopy.crs.CRS, rasterio.crs.CRS
]

GeoPoint pydantic-model

GeoPoint(**data: Any)

Bases: RompyBaseModel

Origin of the grid in geographic space.

Config:

  • arbitrary_types_allowed: True

Fields:

x pydantic-field

x: float

X coordinate of the origin

y pydantic-field

y: float

Y coordinate of the origin

crs pydantic-field

crs: Optional[CRS_TYPES] = None

Coordinate reference system of the origin

reproject

reproject(crs: CRS_TYPES) -> GeoPoint

Transform the origin to a new coordinate reference system.

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.

RegularGrid pydantic-model

RegularGrid(**data: Any)

Bases: BaseGrid

Xbeach regular grid class.

Config:

  • arbitrary_types_allowed: True

Fields:

model_type pydantic-field

model_type: Literal['regular'] = 'regular'

Model type discriminator

ori pydantic-field

ori: GeoPoint

Origin of the grid in geographic space

alfa pydantic-field

alfa: float

Angle of x-axis from east in degrees

dx pydantic-field

dx: float

Grid spacing in the x-direction, for projected CRS, this value is defined in meters, for geographic CRS, it is defined in degrees

dy pydantic-field

dy: float

Grid spacing in the y-direction, for projected CRS, this value is defined in meters, for geographic CRS, it is defined in degrees

nx pydantic-field

nx: int

Number of grid points in the x-direction, the 'nx' paramter in the XBeach namelist will be one less than this value (nx - 1)

ny pydantic-field

ny: int

Number of grid points in the y-direction, the 'ny' paramter in the XBeach namelist will be one less than this value (ny - 1)

crs pydantic-field

crs: Optional[CRS_TYPES] = None

Coordinate reference system of the grid

x0 cached property

x0: float

X coordinate of the grid origin in the grid crs.

y0 cached property

y0: float

Y coordinate of the grid origin in the grid crs.

x cached property

x: ndarray

X coordinates of the grid.

y cached property

y: ndarray

Y coordinates of the grid.

shape cached property

shape: tuple[int, int]

Shape of the grid.

gdf cached property

gdf

Geodataframe representation with multi-polygons for each grid cell.

left cached property

left: tuple[ndarray, ndarray]

Coordinates of the left (lateral) boundary of the grid.

right cached property

right: tuple[ndarray, ndarray]

Coordinates of the right (lateral) boundary of the grid.

back cached property

back: tuple[ndarray, ndarray]

Coordinates of the back (land) boundary of the grid.

front cached property

front: tuple[ndarray, ndarray]

Coordinates of the front (offshore) boundary of the grid.

offshore cached property

offshore: tuple[float, float]

Coordinates at the centre of the offshore boundary.

centre cached property

centre: tuple[float, float]

Coordinates at the centre of the grid.

proj4 cached property

proj4

PROJ4 string of the grid.

transform cached property

transform

Cartopy transformation for the grid.

projection cached property

projection

Cartopy stereographic projection for this grid.

params cached property

params

Return the XBeach parameters for the grid.

vardx=0 is set explicitly because the grid is defined by its origin, rotation and constant spacing; newer XBeach versions default to vardx=1, which expects the grid coordinates from xfile and yfile instead.

grid_type pydantic-field

grid_type: Literal['base'] = 'base'

minx property

minx: float

maxx property

maxx: float

miny property

miny: float

maxy property

maxy: float

expand

expand(left=0, right=0, back=0, front=0) -> RegularGrid

Expand the grid boundaries.

plot

plot(
    ax: GeoAxes = None,
    scale: str = None,
    projection: PlateCarree = None,
    buffer: float = 500,
    set_extent: bool = True,
    set_gridlines: bool = True,
    grid_kwargs: dict = dict(alpha=0.5, zorder=2),
    figsize: tuple = None,
    show_mesh: bool = False,
    mesh_step: int = 1,
    mesh_kwargs: dict = dict(color="k", linewidth=0.5),
    show_offshore: bool = True,
    show_origin: bool = True,
) -> GeoAxes

Plot the grid optionally overlaid with GSHHS coastlines.

Parameters:

Name Type Description Default
ax GeoAxes

Axes object to plot on, by default create a new figure and axes.

None
scale str

Scale for the GSHHS coastline feature, one of 'c', 'l', 'i', 'h', 'f', by default None which implies no coastlines are plotted.

None
projection PlateCarree

Map projection, by default use a stereographic projection.

None
buffer float

Buffer around the grid in meters, by default 500.

500
set_extent bool

Set the extent of the axes to the grid bbox and buffer, by default True.

True
set_gridlines bool

Add gridlines to the plot, by default True.

True
grid_kwargs dict

Keyword arguments for the grid plot, by default dict(alpha=0.5, zorder=2).

dict(alpha=0.5, zorder=2)
figsize tuple

Figure size in inches, by default None.

None
show_mesh bool

Show the model grid mesh, by default False.

False
mesh_step int

Step for the mesh plot, by default 1.

1
mesh_kwargs dict

Keyword arguments for the mesh, by default dict(color="k", linewidth=0.5).

dict(color='k', linewidth=0.5)
show_offshore bool

Show the offshore boundary, by default True.

True
show_origin bool

Show the origin of the grid, by default True.

True

Returns:

Type Description
Axes

Axes object with the plot.

to_file

to_file(filename, **kwargs)

from_file classmethod

from_file(filename: str, **kwargs) -> RegularGrid

Read a grid from a file.

Parameters:

Name Type Description Default
filename str

Path to the file.

required
kwargs dict

Additional keyword arguments for the geopandas read_file method.

{}

Returns:

Type Description
RegularGrid

RegularGrid 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

boundary(tolerance=0.2) -> Polygon

Returns the convex hull boundary polygon from the grid.

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

Returns:

Name Type Description
polygon Polygon

See https://shapely.readthedocs.io/en/stable/manual.html#Polygon

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.

validate_crs

validate_crs(crs: Optional[CRS_TYPES]) -> CRS

Validate the coordinate reference system input.