fastscapelib.RasterGrid#
- class fastscapelib.RasterGrid#
A 2-dimensional raster grid.
This raster grid type has 8-node connectivity (i.e., including diagonals).
- __init__(self, size: List[int], spacing: array_like, bounds_status: NodeStatus | List[NodeStatus] | RasterBoundaryStatus, nodes_status: Dict[Tuple[int, int], NodeStatus] | None = None) None #
Raster grid initializer.
- Parameters:
shape (
tuple
) – Shape of the grid (number of rows and cols).spacing (array_like) – Distance between two adjacent grid nodes (row, cols).
bounds_status (
NodeStatus
orlist
orRasterBoundaryStatus
) – Status at boundary borders (left/right/top/bottom grid borders).nodes_status (
dict
, optional) – A dictionary where keys are node (row, col) indices and values areNodeStatus
values. If present (default isNone
), it is used to manually define the status at any node on the grid.
Methods
__init__
(self, size, spacing, bounds_status)Raster grid initializer.
from_length
(self, shape, length, bounds_status)Raster grid initializer from given total lengths.
neighbors
(idx)Returns the neighbors of a given node.
neighbors_count
(idx)Returns the number of neighbors at a given node.
neighbors_distances
(idx)Returns the distances from a given node to its neighbors.
neighbors_indices
(idx)Returns the (flat) indices of the neighbors of a given node.
nodes_areas
(*args)Returns the area of the direct vicinity of a given node or all nodes.
nodes_indices
(*args)Returns the (flattened) indices of grid nodes, possibly filtered by node status.
nodes_status
(*args)Returns the status of a given node or all nodes.
Attributes
is_structured
is_uniform
Returns the total length of the grid for each of its dimension.
n_neighbors_max
Returns the shape of the grid node arrays.
Returns the total number of grid nodes.
Returns the fixed distance between two adjacent nodes for each dimension.
- static from_length(self, shape: tuple, length: array_like, bounds_status: NodeStatus | List[NodeStatus] | RasterBoundaryStatus, nodes_status: Dict[Tuple[int, int], NodeStatus] | None = None) None #
Raster grid initializer from given total lengths.
- Parameters:
shape (
tuple
) – Shape of the grid (number of rows and cols).length (array_like) – Total physical length of the grid in y (rows) and x (cols).
bounds_status (
NodeStatus
orlist
orRasterBoundaryStatus
) – Status at boundary borders (left/right/top/bottom grid borders).nodes_status (
dict
, optional) – A dictionary where keys are node (row, col) indices and values areNodeStatus
values. If present (default isNone
), it is used to manually define the status at any node on the grid.
- property length#
Returns the total length of the grid for each of its dimension.
- neighbors(idx: int) List[Neighbor] #
Returns the neighbors of a given node.
- Parameters:
idx (
int
) – The grid node (flat) index.- Returns:
Notes
For a
RasterGrid
, it is also possible to providerow
andcol
indices as arguments, which returns a list ofRasterNeighbor
instances.
- neighbors_count(idx: int) int #
Returns the number of neighbors at a given node.
- Parameters:
idx (
int
) – The grid node (flat) index.
- neighbors_distances(idx: int) numpy.ndarray #
Returns the distances from a given node to its neighbors.
- Parameters:
idx (
int
) – The grid node (flat) index.- Returns:
distances (
numpy.ndarray
) – A 1-dimensional array of node distances (float). The neighbor order is the same than the one returned byneighbors_indices(idx)
.
- neighbors_indices(idx: int) numpy.ndarray #
Returns the (flat) indices of the neighbors of a given node.
- Parameters:
idx (
int
) – The grid node (flat) index.- Returns:
indices (
numpy.ndarray
) – A 1-dimensional array of node (flat) indices (int).
Notes
For a
RasterGrid
, it is also possible to providerow
andcol
indices as arguments.
- nodes_areas(*args) float | numpy.ndarray #
Returns the area of the direct vicinity of a given node or all nodes.
Overloaded method that supports the following signatures:
nodes_areas() -> numpy.ndarray
nodes_areas(idx: int) -> float
- Parameters:
idx (
int
) – The grid node (flat) index.
- nodes_indices(*args) numpy.ndarray #
Returns the (flattened) indices of grid nodes, possibly filtered by node status.
Overloaded method that supports the following signatures:
nodes_indices() -> numpy.ndarray
nodes_indices(status: NodeStatus) -> numpy.ndarray
- Parameters:
status (
NodeStatus
) – The status of the grid nodes to filter in.- Returns:
indices (
numpy.ndarray
) – A new, 1-dimensional array with grid node (filtered) flat indices.
- nodes_status(*args) NodeStatus | numpy.ndarray #
Returns the status of a given node or all nodes.
Overloaded method that supports the following signatures:
nodes_status() -> numpy.ndarray
nodes_status(idx: int) -> NodeStatus
- Parameters:
idx (
int
) – The grid node (flat) index.- Returns:
status (
NodeStatus
ornumpy.ndarray
) – If an array is returned, it is a copy of the original array and has theNodeStatus
enum class values (int) as values.
- property shape#
Returns the shape of the grid node arrays.
- property size#
Returns the total number of grid nodes.
- property spacing#
Returns the fixed distance between two adjacent nodes for each dimension.