Skip to content

Grids

Grids define where a model computes. Model plugins subclass BaseGrid for their own grid types.

logger module-attribute

logger = logging.getLogger(__name__)

grid0 module-attribute

grid0 = RegularGrid(
    x0=-1, y0=1, rot=35, nx=10, ny=10, dx=1, dy=2
)

grid1 module-attribute

grid1 = RegularGrid(x=grid0.x, y=grid0.y)

BaseGrid pydantic-model

BaseGrid(**data: Any)

Bases: RompyBaseModel

Representation of a grid in geographic space.

This is the base class for all Grid objects. The minimum representation of a grid are two NumPy array's representing the vertices or nodes of some structured or unstructured grid, its bounding box and a boundary polygon. No knowledge of the grid connectivity is expected.

Fields:

grid_type pydantic-field

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

x property

x: ndarray

y property

y: ndarray

minx property

minx: float

maxx property

maxx: float

miny property

miny: float

maxy property

maxy: float

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.

plot

plot(
    ax=None,
    figsize=None,
    fscale=10,
    buffer=0.1,
    borders=True,
    land=True,
    coastline=True,
)

Plot the grid

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

Regular grid in geographic space.

This object provides an abstract representation of a regular grid in some geographic space.

Fields:

Validators:

grid_type pydantic-field

grid_type: Literal['regular'] = 'regular'

Type of grid, must be 'regular'

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

x property

x: ndarray

y property

y: ndarray

xlen property

xlen

ylen property

ylen

minx property

minx: float

maxx property

maxx: float

miny property

miny: float

maxy property

maxy: float

generate pydantic-validator

generate() -> RegularGrid

Generate the grid from the provided parameters.

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.

plot

plot(
    ax=None,
    figsize=None,
    fscale=10,
    buffer=0.1,
    borders=True,
    land=True,
    coastline=True,
)

Plot the grid