Grid¶
The XBeach grid. RegularGrid builds on rompy's BaseGrid.
XBEACH Rompy grid.
GeoPoint
pydantic-model
¶
GeoPoint(**data: Any)
Bases: RompyBaseModel
Origin of the grid in geographic space.
Config:
arbitrary_types_allowed:True
Fields:
RegularGrid
pydantic-model
¶
RegularGrid(**data: Any)
Bases: BaseGrid
Xbeach regular grid class.
Config:
arbitrary_types_allowed:True
Fields:
-
grid_type(Literal['base']) -
model_type(Literal['regular']) -
ori(GeoPoint) -
alfa(float) -
dx(float) -
dy(float) -
nx(int) -
ny(int) -
crs(Optional[CRS_TYPES])
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)
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
¶
Coordinates at the centre of the offshore boundary.
params
cached
property
¶
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.
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. |
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
¶
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
¶
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.