BaseGrid
([coord0, coord1, ..., ]axis_name=None, axis_units=None)[source]¶Bases: object
Parameters: | coord0, coord1, ... : sequence of array-like
axis_name : sequence of strings, optional
axis_units : sequence of strings, optional
|
---|---|
Returns: | 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])
axis_name
¶Name of each axis.
Returns: | 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: | 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')
cell_at_node
¶coord_at_node
¶length_of_link
(link=None)[source]¶Length of grid links.
Parameters: | link : array-like, optional
|
---|
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_at_link_end
¶node_at_link_start
¶node_to_node_distance
(node0, node1, out=None)[source]¶Distance between nodes.
Parameters: | node0 : array-like
node1 : array-like
|
---|---|
Returns: | 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 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
node : array-like
|
---|---|
Returns: | 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
node : array-like
|
---|---|
Returns: | 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
node : array-like
|
---|---|
Returns: | 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
node : array-like
|
---|---|
Returns: | 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: | (y0, x0) : tuple of array_like (y1, x1) : tuple of array_like out : array_like, optional
|
---|---|
Returns: | a : array_like
|
point_to_point_azimuth
(point0, point1, out=None)[source]¶Azimuth of vector that joins two points.
Parameters: | (y0, x0) : tuple of array_like (y1, x1) : tuple of array_like out : array_like, optional
|
---|---|
Returns: | azimuth : 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: | (y0, x0) : tuple of array_like (y1, x1) : tuple of array_like out : array_like, optional
|
---|---|
Returns: | l : 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: | (y0, x0) : tuple of array_like (y1, x1) : tuple of array_like out : array_like, optional
|
---|---|
Returns: | (dy, dx) : 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]])
CellGrid
(vertices, vertices_per_cell, node_at_cell=None)[source]¶Bases: object
Parameters: | vertices : array-like
vertices_per_cell : array-like
|
---|---|
Returns: | 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: | ndarray :
|
---|
node_at_cell
¶number_of_cells
¶LinkGrid
(link_ends, number_of_nodes, link_ids=None, node_status=None)[source]¶Bases: object
Create a grid of links that enter and leave nodes. __init__((node0, node1), number_of_nodes=None)
Parameters: | node0, node1 : sequence of array-like
number_of_nodes : int, optional
|
---|---|
Returns: | LinkGrid :
|
Examples
>>> from landlab.grid.unstructured.links import LinkGrid
>>> lgrid = LinkGrid([(0, 1, 0, 2, 0), (2, 3, 1, 3, 3)], 4)
>>> lgrid.number_of_links
5
>>> lgrid.number_of_nodes
4
>>> lgrid.number_of_in_links_at_node(0)
0
>>> lgrid.number_of_out_links_at_node(0)
3
>>> lgrid.out_link_at_node(0)
array([0, 2, 4])
>>> lgrid.nodes_at_link_id(1)
array([1, 3])
>>> lgrid = LinkGrid([(0, 1, 0, 2, 0), (2, 3, 1, 3, 3)], 4,
... link_ids=range(1, 6))
>>> lgrid.nodes_at_link
array([[0, 2],
[1, 3],
[0, 1],
[2, 3],
[0, 3]])
>>> lgrid.out_link_at_node(0)
array([1, 3, 5])
>>> lgrid.nodes_at_link_id(1)
array([0, 2])
in_link_at_node
(node)[source]¶Links entering a node.
Parameters: | node : int
|
---|---|
Returns: | ndarray :
|
Examples
>>> from landlab.grid.unstructured.links import LinkGrid
>>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4)
>>> len(lgrid.in_link_at_node(0)) == 0
True
>>> lgrid.in_link_at_node(3)
array([1, 3])
iter_nodes
()[source]¶Iterate of the nodes of the grid.
Returns: | ndarray :
|
---|
Examples
>>> from landlab.grid.unstructured.links import LinkGrid
>>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4)
>>> for link in lgrid.iter_nodes(): link
array([0, 2])
array([2, 1])
array([0, 3])
array([1, 3])
link_id
¶node_at_link_end
¶node_at_link_start
¶node_status_at_link_end
¶node_status_at_link_start
¶nodes_at_link
¶number_of_in_links_at_node
(node)[source]¶Number of links entering a node.
Parameters: | node : int
|
---|---|
Returns: | int :
|
Examples
>>> from landlab.grid.unstructured.links import LinkGrid
>>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4)
>>> [lgrid.number_of_in_links_at_node(node) for node in range(4)]
[0, 1, 1, 2]
number_of_links
¶Number of links in the grid.
number_of_links_at_node
(node)[source]¶Number of links entering and leaving a node.
Parameters: | node : int
|
---|---|
Returns: | int :
|
Examples
>>> from landlab.grid.unstructured.links import LinkGrid
>>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4)
>>> [lgrid.number_of_links_at_node(node) for node in range(4)]
[2, 2, 2, 2]
number_of_nodes
¶Number of nodes in the grid.
number_of_out_links_at_node
(node)[source]¶Number of links leaving a node.
Parameters: | node : int
|
---|---|
Returns: | int :
|
Examples
>>> from landlab.grid.unstructured.links import LinkGrid
>>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4)
>>> [lgrid.number_of_out_links_at_node(node) for node in range(4)]
[2, 1, 1, 0]
out_link_at_node
(node)[source]¶Links leaving a node.
Parameters: | node : int
|
---|---|
Returns: | ndarray :
|
Examples
>>> from landlab.grid.unstructured.links import LinkGrid
>>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4)
>>> lgrid.out_link_at_node(0)
array([0, 2])
>>> len(lgrid.out_link_at_node(3)) == 0
True
find_active_links
(node_status, (node0, node1))[source]¶IDs of active links.
Parameters: | node_status : ndarray
node0, node1 : sequence of array-like
|
---|---|
Returns: | ndarray :
|
Examples
>>> from landlab.grid.unstructured.links import find_active_links
>>> links = [(0, 2), (1, 3), (0, 1), (1, 2), (0, 3)]
>>> status = np.array([0, 0, 0, 0])
>>> find_active_links(status, links)
array([0, 1, 2, 3, 4])
in_link_count_per_node
((node0, node1), number_of_nodes=None)[source]¶Number of links entering nodes.
Parameters: | node0, node1 : sequence of array-like
number_of_nodes : int, optional
|
---|---|
Returns: | ndarray :
|
Examples
>>> from landlab.grid.unstructured.links import in_link_count_per_node
>>> link_ends = [(0, 3), (1, 4), (2, 5), (3, 6), (4, 7), (5, 8)]
>>> in_link_count_per_node(zip(*link_ends))
array([0, 0, 0, 1, 1, 1, 1, 1, 1])
in_link_ids_at_node
((node0, node1), number_of_nodes=None)[source]¶Links entering nodes.
Parameters: | node0, node1 : sequence of array-like
number_of_nodes : int, optional
|
---|---|
Returns: | tuple :
|
Examples
>>> from landlab.grid.unstructured.links import in_link_ids_at_node
>>> (links, count) = in_link_ids_at_node(([0, 1, 2, 3, 4, 5],
... [3, 4, 5, 6, 7, 8]))
>>> links
array([0, 1, 2, 3, 4, 5])
>>> count
array([0, 0, 0, 1, 1, 1, 1, 1, 1])
>>> (links, count) = in_link_ids_at_node(([0, 1, 2, 3, 4, 5],
... [3, 4, 5, 6, 7, 8]),
... link_ids=range(1, 7))
>>> links
array([1, 2, 3, 4, 5, 6])
>>> count
array([0, 0, 0, 1, 1, 1, 1, 1, 1])
link_count_per_node
((node0, node1), number_of_nodes=None)[source]¶Number of links per node.
Parameters: | node0, node1 : sequence of array-like
number_of_nodes : int, optional
|
---|---|
Returns: | ndarray :
|
Examples
>>> from landlab.grid.unstructured.links import link_count_per_node
>>> link_count_per_node(([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]))
array([1, 1, 1, 2, 2, 2, 1, 1, 1])
link_ids_at_node
((node0, node1), number_of_nodes=None)[source]¶Links entering and leaving nodes.
Parameters: | node0, node1 : sequence of array-like
number_of_nodes : int, optional
|
---|---|
Returns: | tuple :
|
Examples
>>> from landlab.grid.unstructured.links import link_ids_at_node
>>> (links, count) = link_ids_at_node(
... ([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]), number_of_nodes=9)
>>> links
array([0, 1, 2, 0, 3, 1, 4, 2, 5, 3, 4, 5])
>>> count
array([1, 1, 1, 2, 2, 2, 1, 1, 1])
link_is_active
((status0, status1))[source]¶Check if a link is active.
Links are inactive if they connect two boundary nodes or touch a closed boundary. Otherwise, the link is active.
Parameters: | status0, status1 : sequence of array-like
|
---|---|
Returns: | ndarray, boolean :
|
out_link_count_per_node
((node0, node1), number_of_nodes=None)[source]¶Number of links leaving nodes.
Parameters: | node0, node1 : sequence of array-like
number_of_nodes : int, optional
|
---|---|
Returns: | ndarray :
|
Examples
>>> from landlab.grid.unstructured.links import out_link_count_per_node
>>> out_link_count_per_node(([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]))
array([1, 1, 1, 1, 1, 1])
>>> out_link_count_per_node(([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]),
... number_of_nodes=9)
array([1, 1, 1, 1, 1, 1, 0, 0, 0])
out_link_ids_at_node
((node0, node1), number_of_nodes=None)[source]¶Links leaving nodes.
Parameters: | node0, node1 : sequence of array-like
number_of_nodes : int, optional
|
---|---|
Returns: | tuple :
|
Examples
>>> from landlab.grid.unstructured.links import out_link_ids_at_node
>>> (links, count) = out_link_ids_at_node(
... ([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]), link_ids=range(-1, 5),
... number_of_nodes=9)
>>> links
array([-1, 0, 1, 2, 3, 4])
>>> count
array([1, 1, 1, 1, 1, 1, 0, 0, 0])
>>> (links, count) = out_link_ids_at_node(
... ([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]), number_of_nodes=9)
>>> links
array([0, 1, 2, 3, 4, 5])
>>> count
array([1, 1, 1, 1, 1, 1, 0, 0, 0])
NodeGrid
((coord0, coord1))[source]¶Bases: object
Create a grid of nodes.
Parameters: | coord0, coord1 : sequence of array-like
|
---|---|
Returns: | 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.])
CLOSED_BOUNDARY
= 4¶Indicates a boundary node is closed
CORE_NODE
= 0¶Indicates a node is core.
FIXED_GRADIENT_BOUNDARY
= 2¶Indicates a boundary node is has a fixed gradient.
FIXED_VALUE_BOUNDARY
= 1¶Indicates a boundary node is has a fixed values.
LOOPED_BOUNDARY
= 3¶Indicates a boundary node is wrap-around.
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.