landlab.grid.unstructured.base¶
- class BaseGrid[source]¶
Bases:
object
__init__([coord0, coord1, …], axis_name=None, axis_units=None)
- Parameters:
coord0 (sequence of array-like) – Coordinates of grid nodes
coord1 (sequence of array-like) – Coordinates of grid nodes
... (sequence of array-like) – 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:
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:
coord0 (sequence of array-like) – Coordinates of grid nodes
coord1 (sequence of array-like) – Coordinates of grid nodes
... (sequence of array-like) – 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:
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:
coord0 (sequence of array-like) – Coordinates of grid nodes
coord1 (sequence of array-like) – Coordinates of grid nodes
... (sequence of array-like) – 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:
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])
- __new__(**kwargs)¶
- property 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')
- property 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')
- property cell_at_node¶
- property coord_at_node¶
- length_of_link(link=None)[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
- property ndim¶
- property node_at_cell¶
- property node_at_link_end¶
- property node_at_link_start¶
- 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.])
- property number_of_cells¶
Number of cells.
- property number_of_links¶
Number of links.
- property number_of_nodes¶
Number of nodes.
- property 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, 0.0), [1, 2, 3]) / np.pi array([0. , 0.5 , 0.25]) >>> grid.point_to_node_angle((0.0, 0.0)) / np.pi array([0. , 0. , 0.5 , 0.25]) >>> out = np.empty(4) >>> out is grid.point_to_node_angle((0.0, 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, 0.0), [1, 2, 3]) array([90., 0., 45.]) >>> grid.point_to_node_azimuth((0.0, 0.0)) array([90., 90., 0., 45.]) >>> grid.point_to_node_azimuth((0.0, 0.0), 1) array([90.]) >>> out = np.empty(4) >>> out is grid.point_to_node_azimuth((0.0, 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, 0.0), [1, 2, 3]) array([3., 4., 5.]) >>> grid.point_to_node_distance((0.0, 0.0)) array([0., 3., 4., 5.]) >>> out = np.empty(4) >>> out is grid.point_to_node_distance((0.0, 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, 0.0), [1, 2, 3]) array([[0., 1., 1.], [1., 0., 1.]]) >>> grid.point_to_node_vector((0.0, 0.0)) array([[0., 0., 1., 1.], [0., 1., 0., 1.]]) >>> grid.point_to_node_vector((0.0, 0.0), 1) array([[0.], [1.]]) >>> out = np.empty((2, 1)) >>> out is grid.point_to_node_vector((0.0, 0.0), 1, out=out) True >>> out array([[0.], [1.]])
- property status_at_node¶
- property x_at_node¶
- property y_at_node¶
- point_to_point_angle(point0, point1, out=None)[source]¶
Angle of vector that joins two points.
- Parameters:
- 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:
- 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:
- 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:
- 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]])