landlab

landlab.grid.unstructured package

Submodules

landlab.grid.unstructured.base module

class BaseGrid([coord0, coord1, ..., ]axis_name=None, axis_units=None)[source]

Bases: object

Parameters:
  • coord1, .. (coord0,) – Coordinates of grid nodes
  • axis_name (sequence of strings, optional) – Names of coordinate axes
  • axis_units (sequence of strings, optional) – Units of coordinate axes
Returns:

A newly-created BaseGrid

Return type:

BaseGrid

Examples

>>> from landlab.grid.unstructured.base import BaseGrid
>>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]))
>>> ngrid.number_of_nodes
4
>>> ngrid.x_at_node
array([ 0.,  1.,  0.,  1.])
>>> ngrid.x_at_node[2]
0.0
>>> ngrid.point_at_node[2]
array([ 1.,  0.])
>>> ngrid.coord_at_node[:, [2, 3]]
array([[ 1.,  1.],
       [ 0.,  1.]])
>>> cells = ([0, 1, 2, 1, 3, 2], [3, 3], [0, 1])
>>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]), cells=cells)
>>> ngrid.number_of_cells
2
>>> ngrid.node_at_cell
array([0, 1])
>>> links = [(0, 2), (1, 3), (0, 1), (1, 2), (0, 3)]
>>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]), links=zip(*links))
>>> ngrid.number_of_links
5
>>> ngrid.links_leaving_at_node(0)
array([0, 2, 4])
>>> len(ngrid.links_entering_at_node(0)) == 0
True
>>> tails, heads = zip(*links)
>>> grid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]),
...     node_status=[0, 0, 0, 4], links=[tails, heads])
>>> grid.status_at_node
array([0, 0, 0, 4])
>>> len(grid.active_links_entering_at_node(0)) == 0
True
>>> grid.active_links_leaving_at_node(0)
array([0, 2])

__init__([coord0, coord1, …], axis_name=None, axis_units=None)

Parameters:
  • coord1, .. (coord0,) – Coordinates of grid nodes
  • axis_name (sequence of strings, optional) – Names of coordinate axes
  • axis_units (sequence of strings, optional) – Units of coordinate axes
Returns:

A newly-created BaseGrid

Return type:

BaseGrid

Examples

>>> from landlab.grid.unstructured.base import BaseGrid
>>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]))
>>> ngrid.number_of_nodes
4
>>> ngrid.x_at_node
array([ 0.,  1.,  0.,  1.])
>>> ngrid.x_at_node[2]
0.0
>>> ngrid.point_at_node[2]
array([ 1.,  0.])
>>> ngrid.coord_at_node[:, [2, 3]]
array([[ 1.,  1.],
       [ 0.,  1.]])
>>> cells = ([0, 1, 2, 1, 3, 2], [3, 3], [0, 1])
>>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]), cells=cells)
>>> ngrid.number_of_cells
2
>>> ngrid.node_at_cell
array([0, 1])
>>> links = [(0, 2), (1, 3), (0, 1), (1, 2), (0, 3)]
>>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]), links=zip(*links))
>>> ngrid.number_of_links
5
>>> ngrid.links_leaving_at_node(0)
array([0, 2, 4])
>>> len(ngrid.links_entering_at_node(0)) == 0
True
>>> tails, heads = zip(*links)
>>> grid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]),
...     node_status=[0, 0, 0, 4], links=[tails, heads])
>>> grid.status_at_node
array([0, 0, 0, 4])
>>> len(grid.active_links_entering_at_node(0)) == 0
True
>>> grid.active_links_leaving_at_node(0)
array([0, 2])
__init__([coord0, coord1, ..., ]axis_name=None, axis_units=None)[source]
Parameters:
  • coord1, .. (coord0,) – Coordinates of grid nodes
  • axis_name (sequence of strings, optional) – Names of coordinate axes
  • axis_units (sequence of strings, optional) – Units of coordinate axes
Returns:

A newly-created BaseGrid

Return type:

BaseGrid

Examples

>>> from landlab.grid.unstructured.base import BaseGrid
>>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]))
>>> ngrid.number_of_nodes
4
>>> ngrid.x_at_node
array([ 0.,  1.,  0.,  1.])
>>> ngrid.x_at_node[2]
0.0
>>> ngrid.point_at_node[2]
array([ 1.,  0.])
>>> ngrid.coord_at_node[:, [2, 3]]
array([[ 1.,  1.],
       [ 0.,  1.]])
>>> cells = ([0, 1, 2, 1, 3, 2], [3, 3], [0, 1])
>>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]), cells=cells)
>>> ngrid.number_of_cells
2
>>> ngrid.node_at_cell
array([0, 1])
>>> links = [(0, 2), (1, 3), (0, 1), (1, 2), (0, 3)]
>>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]), links=zip(*links))
>>> ngrid.number_of_links
5
>>> ngrid.links_leaving_at_node(0)
array([0, 2, 4])
>>> len(ngrid.links_entering_at_node(0)) == 0
True
>>> tails, heads = zip(*links)
>>> grid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]),
...     node_status=[0, 0, 0, 4], links=[tails, heads])
>>> grid.status_at_node
array([0, 0, 0, 4])
>>> len(grid.active_links_entering_at_node(0)) == 0
True
>>> grid.active_links_leaving_at_node(0)
array([0, 2])
active_nodes()[source]
axis_name

Name of each axis.

Returns:Names of each axis.
Return type:tuple of strings

Examples

>>> from landlab.grid.unstructured.base import BaseGrid
>>> ngrid = BaseGrid(([0, 1, 0], [1, 1, 0]))
>>> ngrid.axis_name
('y', 'x')
>>> ngrid = BaseGrid(([0, 1, 0], [1, 1, 0]), axis_name=['lat', 'lon'])
>>> ngrid.axis_name
('lat', 'lon')
axis_units

Coordinate units of each axis.

Returns:Coordinate units of each axis.
Return type:tuple of strings

Examples

>>> from landlab.grid.unstructured.base import BaseGrid
>>> ngrid = BaseGrid(([0, 1, 0], [1, 1, 0]))
>>> ngrid.axis_units
('-', '-')
>>> ngrid = BaseGrid(([0, 1, 0], [1, 1, 0]),
...     axis_units=['degrees_north', 'degrees_east'])
>>> ngrid.axis_units
('degrees_north', 'degrees_east')
boundary_nodes()[source]
cell_at_node
closed_boundary_nodes()[source]
coord_at_node
core_cells()[source]
core_nodes()[source]
fixed_gradient_boundary_nodes()[source]
fixed_value_boundary_nodes()[source]

Length of grid links.

Parameters:link (array-like, optional) – Link IDs

Examples

>>> from landlab.grid.unstructured.base import BaseGrid
>>> links = [(0, 2), (1, 3), (0, 1), (2, 3), (0, 3)]
>>> grid = BaseGrid(([0, 0, 4, 4], [0, 3, 0, 3]), links=links)
>>> grid.length_of_link()
array([ 4.,  4.,  3.,  3.,  5.])
>>> grid.length_of_link(0)
array([ 4.])
>>> grid.length_of_link().min()
3.0
>>> grid.length_of_link().max()
5.0
ndim
node_at_cell
node_to_node_distance(node0, node1, out=None)[source]

Distance between nodes.

Parameters:
  • node0 (array-like) – Node ID of start
  • node1 (array-like) – Node ID of end
Returns:

Distances between nodes.

Return type:

array

Examples

>>> from landlab.grid.unstructured.base import BaseGrid
>>> grid = BaseGrid(([0, 0, 4, 4], [0, 3, 0, 3]))
>>> grid.node_to_node_distance(0, 3)
array([ 5.])
>>> grid.node_to_node_distance(0, [0, 1, 2, 3])
array([ 0.,  3.,  4.,  5.])
number_of_cells

Number of cells.

Number of links.

number_of_nodes

Number of nodes.

point_at_node
point_to_node_angle(point, node=None, out=None)[source]

Angle from a point to a node.

Parameters:
  • point (tuple) – Coordinates of point
  • node (array-like) – Node IDs
Returns:

Angles from point to node as radians.

Return type:

array

Examples

>>> from landlab.grid.unstructured.base import BaseGrid
>>> grid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]))
>>> grid.point_to_node_angle((0., 0.), [1, 2, 3]) / np.pi
array([ 0.  ,  0.5 ,  0.25])
>>> grid.point_to_node_angle((0., 0.)) / np.pi
array([ 0.  ,  0.  ,  0.5 ,  0.25])
>>> out = np.empty(4)
>>> out is grid.point_to_node_angle((0., 0.), out=out)
True
>>> out / np.pi
array([ 0.  ,  0.  ,  0.5 ,  0.25])
point_to_node_azimuth(point, node=None, out=None)[source]

Azimuth from a point to a node.

Parameters:
  • point (tuple) – Coordinates of point
  • node (array-like) – Node IDs
Returns:

Azimuths from point to node.

Return type:

array

Examples

>>> from landlab.grid.unstructured.base import BaseGrid
>>> grid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]))
>>> grid.point_to_node_azimuth((0., 0.), [1, 2, 3])
array([ 90.,   0.,  45.])
>>> grid.point_to_node_azimuth((0., 0.))
array([ 90.,  90.,   0.,  45.])
>>> grid.point_to_node_azimuth((0., 0.), 1)
array([ 90.])
>>> out = np.empty(4)
>>> out is grid.point_to_node_azimuth((0., 0.), out=out)
True
>>> out
array([ 90.,  90.,   0.,  45.])
point_to_node_distance(point, node=None, out=None)[source]

Distance from a point to a node.

Parameters:
  • point (tuple) – Coordinates of point
  • node (array-like) – Node IDs
Returns:

Distances from point to node.

Return type:

array

Examples

>>> from landlab.grid.unstructured.base import BaseGrid
>>> grid = BaseGrid(([0, 0, 4, 4], [0, 3, 0, 3]))
>>> grid.point_to_node_distance((0., 0.), [1, 2, 3])
array([ 3.,  4.,  5.])
>>> grid.point_to_node_distance((0., 0.))
array([ 0.,  3.,  4.,  5.])
>>> out = np.empty(4)
>>> out is grid.point_to_node_distance((0., 0.), out=out)
True
>>> out
array([ 0.,  3.,  4.,  5.])
point_to_node_vector(point, node=None, out=None)[source]

Azimuth from a point to a node.

Parameters:
  • point (tuple) – Coordinates of point
  • node (array-like) – Node IDs
Returns:

Vector from point to node.

Return type:

array

Examples

>>> from landlab.grid.unstructured.base import BaseGrid
>>> grid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]))
>>> grid.point_to_node_vector((0., 0.), [1, 2, 3])
array([[ 0.,  1.,  1.],
       [ 1.,  0.,  1.]])
>>> grid.point_to_node_vector((0., 0.))
array([[ 0.,  0.,  1.,  1.],
       [ 0.,  1.,  0.,  1.]])
>>> grid.point_to_node_vector((0., 0.), 1)
array([[ 0.],
       [ 1.]])
>>> out = np.empty((2, 1))
>>> out is grid.point_to_node_vector((0., 0.), 1, out=out)
True
>>> out
array([[ 0.],
       [ 1.]])
status_at_node
x_at_node
y_at_node
point_to_point_angle(point0, point1, out=None)[source]

Angle of vector that joins two points.

Parameters:
  • x0) ((y0,) –
  • x1) ((y1,) –
  • out (array_like, optional) – An array to store the output. Must be the same shape as the output would have.
Returns:

a – Angle of vector joining points; if out is provided, v will be equal to out.

Return type:

array_like

point_to_point_azimuth(point0, point1, out=None)[source]

Azimuth of vector that joins two points.

Parameters:
  • x0) ((y0,) –
  • x1) ((y1,) –
  • out (array_like, optional) – An array to store the output. Must be the same shape as the output would have.
Returns:

azimuth – Azimuth of vector joining points; if out is provided, v will be equal to out.

Return type:

array_like

Examples

>>> from landlab.grid.unstructured.base import point_to_point_azimuth
>>> point_to_point_azimuth((0, 0), (1, 0))
array([ 0.])
>>> point_to_point_azimuth([(0, 1), (0, 1)], (1, 0))
array([  0., -90.])
>>> point_to_point_azimuth([(0, 1, 0), (0, 1, 2)], [(1, 1, 2), (0, 0, 4)])
array([  0., -90.,  45.])
point_to_point_distance(point0, point1, out=None)[source]

Length of vector that joins two points.

Parameters:
  • x0) ((y0,) –
  • x1) ((y1,) –
  • out (array_like, optional) – An array to store the output. Must be the same shape as the output would have.
Returns:

l – Length of vector joining points; if out is provided, v will be equal to out.

Return type:

array_like

Examples

>>> from landlab.grid.unstructured.base import point_to_point_distance
>>> point_to_point_distance((0, 0), (3, 4))
array([ 5.])
>>> point_to_point_distance((0, 0), ([3, 6], [4, 8]))
array([  5.,  10.])
point_to_point_vector(point0, point1, out=None)[source]

Vector that joins two points.

Parameters:
  • x0) ((y0,) –
  • x1) ((y1,) –
  • out (array_like, optional) – An array to store the output. Must be the same shape as the output would have.
Returns:

(dy, dx) – Vectors between points; if out is provided, v will be equal to out.

Return type:

tuple of array_like

Examples

>>> from landlab.grid.unstructured.base import point_to_point_vector
>>> point_to_point_vector((0, 0), (1, 2))
array([[1],
       [2]])
>>> point_to_point_vector([(0, 1), (0, 1)], (1, 2))
array([[1, 0],
       [2, 1]])
>>> point_to_point_vector([(0, 0, 0), (0, 1, 2)], [(1, 2, 2), (2, 4, 4)])
array([[1, 2, 2],
       [2, 3, 2]])

landlab.grid.unstructured.cells module

class CellGrid(vertices, vertices_per_cell, node_at_cell=None)[source]

Bases: object

Parameters:
  • vertices (array-like) – Vertex IDs at each grid cell
  • vertices_per_cell (array-like) – Number of vertices per grid cell
Returns:

A newly-created CellGrid

Return type:

CellGrid

Examples

Create a grid of two cells where the first cell has four vertices and the second has three.

>>> from landlab.grid.unstructured.cells import CellGrid
>>> cgrid = CellGrid([0, 1, 3, 2, 1, 4, 3], [4, 3])
>>> cgrid.number_of_cells
2
>>> cgrid.number_of_vertices_at_cell(0)
4
>>> cgrid.number_of_vertices_at_cell(1)
3
>>> cgrid.vertices_at_cell(0)
array([0, 1, 3, 2])
>>> cgrid.vertices_at_cell(1)
array([1, 4, 3])

Associate nodes with each cell.

>>> cgrid = CellGrid([0, 1, 2, 3, 1, 3, 4], [4, 3], node_at_cell=[10, 11])
>>> cgrid.node_at_cell
array([10, 11])
>>> cgrid.cell_at_node[10]
0
>>> cgrid.cell_at_node[11]
1
Parameters:
  • vertices (array-like) – Vertex IDs at each grid cell
  • vertices_per_cell (array-like) – Number of vertices per grid cell
Returns:

A newly-created CellGrid

Return type:

CellGrid

Examples

Create a grid of two cells where the first cell has four vertices and the second has three.

>>> from landlab.grid.unstructured.cells import CellGrid
>>> cgrid = CellGrid([0, 1, 3, 2, 1, 4, 3], [4, 3])
>>> cgrid.number_of_cells
2
>>> cgrid.number_of_vertices_at_cell(0)
4
>>> cgrid.number_of_vertices_at_cell(1)
3
>>> cgrid.vertices_at_cell(0)
array([0, 1, 3, 2])
>>> cgrid.vertices_at_cell(1)
array([1, 4, 3])

Associate nodes with each cell.

>>> cgrid = CellGrid([0, 1, 2, 3, 1, 3, 4], [4, 3], node_at_cell=[10, 11])
>>> cgrid.node_at_cell
array([10, 11])
>>> cgrid.cell_at_node[10]
0
>>> cgrid.cell_at_node[11]
1
__init__(vertices, vertices_per_cell, node_at_cell=None)[source]
Parameters:
  • vertices (array-like) – Vertex IDs at each grid cell
  • vertices_per_cell (array-like) – Number of vertices per grid cell
Returns:

A newly-created CellGrid

Return type:

CellGrid

Examples

Create a grid of two cells where the first cell has four vertices and the second has three.

>>> from landlab.grid.unstructured.cells import CellGrid
>>> cgrid = CellGrid([0, 1, 3, 2, 1, 4, 3], [4, 3])
>>> cgrid.number_of_cells
2
>>> cgrid.number_of_vertices_at_cell(0)
4
>>> cgrid.number_of_vertices_at_cell(1)
3
>>> cgrid.vertices_at_cell(0)
array([0, 1, 3, 2])
>>> cgrid.vertices_at_cell(1)
array([1, 4, 3])

Associate nodes with each cell.

>>> cgrid = CellGrid([0, 1, 2, 3, 1, 3, 4], [4, 3], node_at_cell=[10, 11])
>>> cgrid.node_at_cell
array([10, 11])
>>> cgrid.cell_at_node[10]
0
>>> cgrid.cell_at_node[11]
1
cell_at_node
cell_id
iter()[source]

Iterate over the cells of the grid.

Returns:Nodes entering and leaving each node
Return type:ndarray
node_at_cell
number_of_cells
number_of_vertices_at_cell(cell)[source]
vertices_at_cell(cell)[source]
vertices_at_cell_id(cell_id)[source]

landlab.grid.unstructured.nodes module

class NodeGrid(nodes)[source]

Bases: object

__init__((coord0, coord1)) Create a grid of nodes.

Parameters:coord1 (coord0,) – Coordinates of grid nodes
Returns:A newly-created NodeGrid
Return type:NodeGrid

Examples

>>> from landlab.grid.unstructured.nodes import NodeGrid
>>> ngrid = NodeGrid(([0, 0, 1, 1], [0, 1, 0, 1]))
>>> ngrid.ndim == 2
True
>>> ngrid.number_of_nodes == 4
True
>>> ngrid.x
array([ 0.,  1.,  0.,  1.])
>>> ngrid.y
array([ 0.,  0.,  1.,  1.])

Create a 1D grid.

>>> ngrid = NodeGrid(((0, 1, 3), ))
>>> ngrid.ndim == 1
True
>>> ngrid.number_of_nodes
3
>>> ngrid.x
array([ 0.,  1.,  3.])
>>> ngrid.y
Traceback (most recent call last):
AttributeError: Grid has no y-coordinate

__init__((coord0, coord1)) Create a grid of nodes.

Parameters:coord1 (coord0,) – Coordinates of grid nodes
Returns:A newly-created NodeGrid
Return type:NodeGrid

Examples

>>> from landlab.grid.unstructured.nodes import NodeGrid
>>> ngrid = NodeGrid(([0, 0, 1, 1], [0, 1, 0, 1]))
>>> ngrid.ndim == 2
True
>>> ngrid.number_of_nodes == 4
True
>>> ngrid.x
array([ 0.,  1.,  0.,  1.])
>>> ngrid.y
array([ 0.,  0.,  1.,  1.])

Create a 1D grid.

>>> ngrid = NodeGrid(((0, 1, 3), ))
>>> ngrid.ndim == 1
True
>>> ngrid.number_of_nodes
3
>>> ngrid.x
array([ 0.,  1.,  3.])
>>> ngrid.y
Traceback (most recent call last):
AttributeError: Grid has no y-coordinate
__init__(nodes)[source]

__init__((coord0, coord1)) Create a grid of nodes.

Parameters:coord1 (coord0,) – Coordinates of grid nodes
Returns:A newly-created NodeGrid
Return type:NodeGrid

Examples

>>> from landlab.grid.unstructured.nodes import NodeGrid
>>> ngrid = NodeGrid(([0, 0, 1, 1], [0, 1, 0, 1]))
>>> ngrid.ndim == 2
True
>>> ngrid.number_of_nodes == 4
True
>>> ngrid.x
array([ 0.,  1.,  0.,  1.])
>>> ngrid.y
array([ 0.,  0.,  1.,  1.])

Create a 1D grid.

>>> ngrid = NodeGrid(((0, 1, 3), ))
>>> ngrid.ndim == 1
True
>>> ngrid.number_of_nodes
3
>>> ngrid.x
array([ 0.,  1.,  3.])
>>> ngrid.y
Traceback (most recent call last):
AttributeError: Grid has no y-coordinate
coord

Examples

>>> from landlab.grid.unstructured.nodes import NodeGrid
>>> ngrid = NodeGrid(([0, 0, 1], [0, 1, 0]))
>>> ngrid.coord[0]
array([ 0.,  0.,  1.])
>>> ngrid.coord[1]
array([ 0.,  1.,  0.])
ndim
number_of_nodes

Examples

>>> from landlab.grid.unstructured.nodes import NodeGrid
>>> ngrid = NodeGrid(([0, 0, 1], [0, 1, 0]))
>>> ngrid.number_of_nodes
3
point

Examples

>>> from landlab.grid.unstructured.nodes import NodeGrid
>>> ngrid = NodeGrid(([0, 0, 1], [0, 1, 0]))
>>> ngrid.point
array([[ 0.,  0.],
       [ 0.,  1.],
       [ 1.,  0.]])
>>> ngrid.point[1]
array([ 0.,  1.])
x

Node coordinates of the “fast” dimension.

Examples

>>> from landlab.grid.unstructured.nodes import NodeGrid
>>> ngrid = NodeGrid(([0, 0, 1], [0, 1, 0]))
>>> ngrid.x
array([ 0.,  1.,  0.])
y

Node y-coordinates.

Examples

>>> from landlab.grid.unstructured.nodes import NodeGrid
>>> ngrid = NodeGrid(([0, 0, 1], [0, 1, 0]))
>>> ngrid.y
array([ 0.,  0.,  1.])
z

Node z-coordinates.

Examples

>>> from landlab.grid.unstructured.nodes import NodeGrid
>>> ngrid = NodeGrid(([0, 0, 1], [0, 1, 0]))
>>> ngrid.y
array([ 0.,  0.,  1.])

landlab.grid.unstructured.status module

class StatusGrid(node_status)[source]

Bases: object

active_nodes()[source]

Node IDs of all active (core & open boundary) nodes.

core_nodes will return just core nodes.

boundary_nodes()[source]

Node IDs of all boundary nodes.

closed_boundary_nodes()[source]

Node id of all closed boundary nodes.

core_nodes()[source]

Node IDs of all core nodes.

fixed_gradient_boundary_nodes()[source]

Node id of all fixed gradient boundary nodes.

fixed_value_boundary_nodes()[source]

Node id of all fixed value boundary nodes.

node_status

Status of nodes.

Return an array of the status of a grid’s nodes. The node status can be one of the following: - NodeStatus.CORE - NodeStatus.FIXED_VALUE - NodeStatus.FIXED_GRADIENT - NodeStatus.LOOPED - NodeStatus.CLOSED

open_boundary_nodes()[source]

Node id of all open boundary nodes.

Module contents