landlab

landlab.grid.structured_quad package

Submodules

landlab.grid.structured_quad.c_faces module

landlab.grid.structured_quad.cells module

class StructuredQuadCellGrid(shape)[source]

Bases: object

node_at_cell
number_of_cell_columns
number_of_cell_rows
number_of_cells
number_of_vertices_at_cell(cell)[source]
shape
cell_id_at_nodes(shape, bad=-1)[source]

Cell ID at each node.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Returns:

ndarray :

ID of cell associated with each node.

Examples

>>> from landlab.grid.structured_quad.cells import cell_id_at_nodes
>>> cell_id_at_nodes((4, 5), bad=-1) 
array([[-1, -1, -1, -1, -1],
       [-1,  0,  1,  2, -1],
       [-1,  3,  4,  5, -1],
       [-1, -1, -1, -1, -1]])
cell_ids(shape)[source]

IDs of all cells.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Returns:

ndarray :

ID of node associated with each cell.

Examples

>>> from landlab.grid.structured_quad.cells import cell_ids
>>> cell_ids((3, 4))
array([[0, 1]])
node_id_at_cells(shape)[source]

Node ID at each cell.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Returns:

ndarray :

ID of node associated with each cell.

Examples

>>> from landlab.grid.structured_quad.cells import node_id_at_cells
>>> node_id_at_cells((3, 4))
array([[5, 6]])
number_of_cells(shape)[source]

Number of cells is a structured quad grid.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Returns:

int :

Number of cells in the grid.

Examples

>>> from landlab.grid.structured_quad.cells import number_of_cells
>>> number_of_cells((3, 4))
2
shape_of_cells(shape)[source]

Shape of cells in a structured quad grid.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Returns:

int :

Shape of cells in grid.

Examples

>>> from landlab.grid.structured_quad.cells import shape_of_cells
>>> shape_of_cells((3, 4))
(1, 2)

landlab.grid.structured_quad.cfuncs module

landlab.grid.structured_quad.faces module

Get face for each link of a grid.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Examples

>>> from landlab.grid.structured_quad.faces import face_at_link
>>> face_at_link((4, 5), bad_index_value=-1)
...     
array([-1, -1, -1, -1, -1,  0,  1,  2, -1,
        3,  4,  5,  6, -1,  7,  8,  9, -1,
       10, 11, 12, 13, -1, 14, 15, 16, -1,
       -1, -1, -1, -1])

Get the link at each face.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Notes

The algorithm is based on the following considerations:

  1. To get the link ID associated with a face ID, we start with the face ID and add something to it.
  2. Face 0 crosses the second vertical link. The first NC-1 links are horizontal, and run along the bottom of the grid. Then there’s a vertical link on the lower-left side of the grid. Thus the link that crosses face 0 will be ID number NC, where NC is the number of cols.
  3. The offset between face ID and link ID increases by 1 every time we finish a row of horizontal faces (NC-2 of them) with vertical links, and again when we finish a row of vertical faces (NC-1 of them) with horizontal links. Together, a “row” of horizontal and vertical faces makes up 2NC-3 faces; this is the variable “fpr” (for “faces per row”) below.
  4. The quantity 2 * (face_ids // fpr) increases by 2 for every “full” (horizontal plus vertical) row of faces.
  5. The quantity ((face_ids % fpr) >= (NC-2)) increases by 1 every time we shift from a horizontal to a vertical row of faces (because each “full row” has NC-2 horizontal faces, then NC-1 vertical ones.)
  6. So, to find the offset, we add the “basic” offset, NC, to the “full row” offset, 2*(face_ids//fpr), and the “mid-row” offset, ((face_ids % fpr)>=(NC-2)).

Examples

>>> from landlab.grid.structured_quad.faces import link_at_face
>>> link_at_face((3, 5)) 
array([  5,  6,  7,
         9, 10, 11, 12,
        14, 15, 16])
number_of_faces(shape)[source]

Number of faces in a structured quad grid.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Returns:

int :

Number of faces in grid.

Examples

>>> from landlab.grid.structured_quad.faces import number_of_faces
>>> number_of_faces((3, 4))
7

landlab.grid.structured_quad.nodes module

bottom_iter(shape)[source]

Iterator for the bottom perimeter nodes.

Parameters:

shape : tuple of int

Shape of grid of nodes.

bottom_top_iter(shape)[source]

Iterator for the bottom and top perimeter nodes.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Examples

>>> import numpy as np
>>> from landlab.grid.structured_quad.nodes import bottom_top_iter
>>> np.fromiter(bottom_top_iter((4, 3)), dtype=np.int)
array([ 0,  1,  2,  9, 10, 11])
corners(shape)[source]

IDs of corner nodes.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Returns:

(4, ) ndarray :

IDs of the corner nodes.

Examples

>>> from landlab.grid.structured_quad.nodes import corners
>>> corners((3, 4))
array([ 0,  3,  8, 11])
interior_nodes(shape)[source]

IDs of interior nodes.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Returns:

(M, N) ndarray :

IDs of the interior nodes.

Examples

>>> from landlab.grid.structured_quad.nodes import interior_nodes
>>> interior_nodes((3, 4))
array([[5, 6]])
>>> interior_nodes((4, 5))
array([[ 6,  7,  8],
       [11, 12, 13]])
left_iter(shape)[source]

Iterator for the left perimeter nodes.

Parameters:

shape : tuple of int

Shape of grid of nodes.

left_right_iter(shape, stop) left_right_iter(shape, start, stop[, step])[source]

Iterator for left and right perimeter nodes.

Parameters:

shape : tuple of int

Shape of grid of nodes.

start : int, optional

Start row.

stop : int, optional

Stop row.

step : int, optional

Interval between rows.

Examples

>>> import numpy as np
>>> from landlab.grid.structured_quad.nodes import left_right_iter
>>> np.fromiter(left_right_iter((4, 3)), dtype=np.int)
array([ 0,  2,  3,  5,  6,  8,  9, 11])
>>> np.fromiter(left_right_iter((4, 3), 2), dtype=np.int)
array([0, 2, 3, 5])
>>> np.fromiter(left_right_iter((4, 3), 2, 4), dtype=np.int)
array([ 6,  8,  9, 11])
>>> np.fromiter(left_right_iter((4, 3), 1, 4, 2), dtype=np.int)
array([ 3,  5,  9, 11])
node_ids(shape)[source]

IDs of nodes.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Returns:

ndarray :

IDs of the nodes.

Examples

>>> from landlab.grid.structured_quad.nodes import node_ids
>>> node_ids((3, 4))
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11]])
number_of_core_nodes(shape)[source]

Number of core nodes is a structured quad grid.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Returns:

int :

Number of core nodes in the grid.

Examples

>>> from landlab.grid.structured_quad.nodes import number_of_core_nodes
>>> number_of_core_nodes((3, 4))
2
number_of_nodes(shape)[source]

Number of nodes is a structured quad grid.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Returns:

int :

Number of nodes in the grid.

Examples

>>> from landlab.grid.structured_quad.nodes import number_of_nodes
>>> number_of_nodes((3, 4))
12
perimeter(shape)[source]

Perimeter nodes.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Returns:

ndarray :

IDs of the perimeter nodes.

Examples

>>> from landlab.grid.structured_quad.nodes import perimeter
>>> perimeter((3, 4))
array([ 0,  1,  2,  3,  4,  7,  8,  9, 10, 11])
perimeter_iter(shape)[source]

Iterator for all perimeter nodes.

Parameters:

shape : tuple of int

Shape of grid of nodes.

Examples

>>> import numpy as np
>>> from landlab.grid.structured_quad.nodes import perimeter_iter
>>> np.fromiter(perimeter_iter((4, 3)), dtype=np.int)
array([ 0,  1,  2,  3,  5,  6,  8,  9, 10, 11])
right_iter(shape)[source]

Iterator for the right perimeter nodes.

Parameters:

shape : tuple of int

Shape of grid of nodes.

status_with_perimeter_as_boundary(shape, node_status=4)[source]

Node status for a grid whose boundary is along its perimeter.

Parameters:

shape : tuple of int

Shape of grid of nodes.

node_status : int or array_lik of int, optional

Status of nodes on grid perimeter.

Returns:

ndarray :

Node status for grid.

Examples

>>> from landlab.grid.structured_quad.nodes import status_with_perimeter_as_boundary
>>> status_with_perimeter_as_boundary((3, 4))
array([[4, 4, 4, 4],
       [4, 0, 0, 4],
       [4, 4, 4, 4]])
>>> status_with_perimeter_as_boundary((3, 4), node_status=-1)
array([[-1, -1, -1, -1],
       [-1,  0,  0, -1],
       [-1, -1, -1, -1]])
top_iter(shape)[source]

Iterator for the top perimeter nodes.

Parameters:

shape : tuple of int

Shape of grid of nodes.

landlab.grid.structured_quad.rectilinear module

class RasterGrid(shape, spacing=1.0, origin=0.0)[source]

Bases: landlab.grid.structured_quad.rectilinear.UniformRectilinearGrid

Parameters:

shape : tuple

Shape of the grid in nodes.

spacing : float, optional

Spacing between rows and columns.

origin : tuple, optional

Coordinates of grid origin.

Examples

>>> from landlab.grid.structured_quad.rectilinear import RasterGrid
>>> grid = RasterGrid((4, 5), spacing=2, origin=(-1, 1))
>>> grid.number_of_nodes
20

#>>> grid.number_of_core_nodes 6 >>> grid.number_of_node_rows 4 >>> grid.number_of_node_columns 5 >>> grid.nodes_at_corners_of_grid array([ 0, 4, 15, 19]) >>> grid.number_of_cells 6 >>> grid.node_row_coord array([-1., 1., 3., 5.]) >>> grid.node_col_coord array([ 1., 3., 5., 7., 9.])

class RectilinearGrid(coord)[source]

Bases: landlab.grid.structured_quad.structured.StructuredQuadGrid

Parameters:

coord : tuple

Coordinates of node rows and node columns.

Examples

>>> import numpy as np
>>> from landlab.grid.structured_quad.rectilinear import RectilinearGrid
>>> (y, x) = np.arange(4.), np.arange(5.)
>>> grid = RectilinearGrid((y, x))
>>> grid.number_of_nodes
20
>>> grid.number_of_node_rows
4
>>> grid.number_of_node_columns
5
>>> grid.nodes_at_corners_of_grid
array([ 0,  4, 15, 19])
>>> grid.number_of_cells
6
>>> grid.node_row_coord
array([ 0.,  1.,  2.,  3.])
>>> grid.node_col_coord
array([ 0.,  1.,  2.,  3.,  4.])
coord

Node row and column coordinates.

node_col_coord
node_row_coord
class UniformRectilinearGrid(shape, spacing=(1.0, 1.0), origin=(0.0, 0.0))[source]

Bases: landlab.grid.structured_quad.rectilinear.RectilinearGrid

Parameters:

shape : tuple

Shape of the grid in nodes.

spacing : tuple, optional

Spacing between rows and columns.

origin : tuple, optional

Coordinates of grid origin.

Examples

>>> from landlab.grid.structured_quad.rectilinear import UniformRectilinearGrid
>>> grid = UniformRectilinearGrid((4, 5), spacing=(2, 3), origin=(-1, 1))
>>> grid.number_of_nodes
20

#>>> grid.number_of_core_nodes 6 >>> grid.number_of_node_rows 4 >>> grid.number_of_node_columns 5 >>> grid.nodes_at_corners_of_grid array([ 0, 4, 15, 19]) >>> grid.number_of_cells 6 >>> grid.node_row_coord array([-1., 1., 3., 5.]) >>> grid.node_col_coord array([ 1., 4., 7., 10., 13.])

dx

Spacing between columns of grid nodes.

dy

Spacing between rows of grid nodes.

spacing

Spacing of rows and columns of grid nodes.

landlab.grid.structured_quad.structured module

Examples

>>> import numpy as np
>>> from landlab.grid.structured_quad.structured import StructuredQuadGrid
>>> (y, x) = np.meshgrid(np.arange(4.), np.arange(5.), indexing='ij')
>>> grid = StructuredQuadGrid((y, x))
>>> grid.number_of_nodes
20
>>> grid.number_of_node_rows == 4
True
>>> grid.number_of_node_columns == 5
True
>>> grid.nodes_at_corners_of_grid
array([ 0,  4, 15, 19])
>>> grid.number_of_cells
6
class StructuredQuadGrid(node_coord, shape=None, axis_name=None, axis_units=None, links=True, cells=True, node_status=None)[source]

Bases: landlab.grid.unstructured.base.BaseGrid

Parameters:

node_coord : tuple

Coordinates of all grid nodes.

shape : tuple, optional

Shape of the grid of nodes.

corner_nodes

Note

This method is deprecated as of Landlab version 1.0.

Use nodes_at_corners_of_grid() instead.

nodes_at_corners_of_grid

Nodes in grid corners.

Return the IDs to the corner nodes of the grid, sorted by ID.

Returns:

(4, ) ndarray

Array of corner node IDs.

Examples

>>> import numpy as np
>>> from landlab.grid.structured_quad.structured import StructuredQuadGrid
>>> (x, y) = np.meshgrid(np.arange(4.), np.arange(5.), indexing='ij')
>>> grid = StructuredQuadGrid((x, y))
>>> grid.nodes_at_corners_of_grid
array([ 0,  4, 15, 19])
number_of_node_columns

Number of node columns.

Returns the number of columns, including boundaries.

number_of_node_rows

Number of node rows.

Returns the number of rows, including boundaries.

shape

Shape of the grid as rows, columns.

Module contents