landlab.graph.hex package#

Subpackages#

Submodules#

landlab.graph.hex.dual_hex module#

class DualHexGraph(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0), orientation='horizontal', node_layout='rect', sort=False)[source]#

Bases: DualGraph, TriGraph

Graph of a structured grid of triangles.

Examples

>>> import numpy as np
>>> from landlab.graph import DualHexGraph
>>> graph = DualHexGraph((3, 2), node_layout='hex')
>>> graph.number_of_nodes
7
>>> graph.number_of_corners
6
>>> np.round(graph.y_of_node * 2. / np.sqrt(3))
...     
array([ 0.,  0.,  1.,  1.,  1.,  2.,  2.])
>>> graph.x_of_node 
array([ 0.5,  1.5,  0. ,  1. ,  2. ,  0.5,  1.5])

Create a structured grid of triangles.

Parameters
  • shape (tuple of int) – Number of rows and columns of the hex grid. The first value is the number of nodes in the first column and the second the number of nodes in the first column.

  • spacing (float, optional) – Length of links.

  • xy_of_lower_left (tuple of float, optional) – Coordinates of lower-left corner of the grid.

  • orientation ({'horizontal', 'vertical'}) – Specify if triangles should be laid out in rows or columns.

  • node_layout ({'rect', 'hex'}) – Specify the overall layout of the nodes. Use rect for the layout to approximate a rectangle and hex for a hexagon.

__init__(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0), orientation='horizontal', node_layout='rect', sort=False)[source]#

Create a structured grid of triangles.

Parameters
  • shape (tuple of int) – Number of rows and columns of the hex grid. The first value is the number of nodes in the first column and the second the number of nodes in the first column.

  • spacing (float, optional) – Length of links.

  • xy_of_lower_left (tuple of float, optional) – Coordinates of lower-left corner of the grid.

  • orientation ({'horizontal', 'vertical'}) – Specify if triangles should be laid out in rows or columns.

  • node_layout ({'rect', 'hex'}) – Specify the overall layout of the nodes. Use rect for the layout to approximate a rectangle and hex for a hexagon.

property adjacent_corners_at_corner#

Get adjacent corners.

See also

Graph.adjacent_nodes_at_node

property adjacent_faces_at_face#
property angle_of_face#

Get the angle of each face.

See also

Graph.angle_of_link

property area_of_cell#

Get the area of each cell.

See also

Graph.area_of_patch

property cells_at_corner#

Get the cells that touch each corner.

See also

Graph.patches_at_node

property cells_at_face#

Get the cells on either side of each face.

See also

Graph.patches_at_link

property corner_at_face_head#

Get corners at face head.

See also

Graph.node_at_link_head

property corner_at_face_tail#

Get corners at face tail.

See also

Graph.node_at_link_tail

property corner_layout#
property corner_x#
property corner_y#
property corners#

Get identifier for each corner.

See also

Graph.nodes

property corners_at_bottom_edge#

Get corners along the bottom edge.

See also

Graph.nodes_at_bottom_edge

property corners_at_cell#

Get the corners that define a cell.

See also

Graph.nodes_at_patch

property corners_at_face#

Get corners at either end of faces.

See also

Graph.nodes_at_link

property corners_at_left_edge#

Get corners along the left edge.

See also

Graph.nodes_at_left_edge

property corners_at_right_edge#

Get corners along the right edge.

See also

Graph.nodes_at_right_edge

property corners_at_top_edge#

Get corners along the top edge.

See also

Graph.nodes_at_top_edge

property face_dirs_at_corner#

Get directions of faces touching a corner.

See also

Graph.link_dirs_at_node

property faces_at_cell#

Get the faces that define a cell.

See also

Graph.links_at_patch

property faces_at_corner#

Get faces touching a corner.

See also

Graph.links_at_node

property length_of_face#
property midpoint_of_face#

Get the middle of faces.

See also

Graph.midpoint_of_link

property number_of_cells#

Get the number of cells.

See also

Graph.number_of_patches

property number_of_corners#

Get total number of corners.

See also

Graph.number_of_nodes

property number_of_faces#

Get corners at face head.

See also

Graph.number_of_links

property perimeter_corners#

Get corners on the convex hull of a Graph.

See also

Graph.perimeter_nodes

property unit_vector_at_corner#

Get a unit vector for each corner.

See also

Graph.unit_vector_at_node

property unit_vector_at_face#

Make arrays to store the unit vectors associated with each face.

See also

Graph.unit_vector_at_link

property x_of_corner#

Get x-coordinate of corner.

See also

Graph.x_of_node

property xy_of_cell#

Get the centroid of each cell.

See also

Graph.xy_of_patch

property xy_of_corner#

Get x and y-coordinates of corner.

See also

Graph.xy_of_node

property xy_of_face#
property y_of_corner#

Get y-coordinate of corner.

See also

Graph.y_of_node

landlab.graph.hex.hex module#

Examples

    * - *
   / \ / \
  * - * - *
 / \ / \ / \
* - * - * - *
 \ / \ / \ /
  * - * - *
   \ / \ /
    * - *
>>> from landlab.graph import TriGraph
>>> graph = TriGraph((5, 2), node_layout="hex", sort=True)
>>> graph.number_of_nodes
14
>>> graph.x_of_node
array([ 1. ,  2. ,
        0.5,  1.5,  2.5,
        0. ,  1. ,  2. ,  3. ,
        0.5,  1.5, 2.5,
        1. ,  2. ])
>>> graph.number_of_links
29
>>> graph.number_of_patches
16
* - * - * - *
 \ / \ / \ / \
  * - * - * - *
 / \ / \ / \ /
* - * - * - *
>>> from landlab.graph import TriGraph
>>> graph = TriGraph((3, 4), orientation="horizontal", node_layout="rect", sort=True)
>>> graph.number_of_nodes
12
>>> graph.x_of_node.reshape((3, 4))
array([[ 0. ,  1. ,  2. ,  3. ],
       [ 0.5,  1.5,  2.5,  3.5],
       [ 0. ,  1. ,  2. ,  3. ]])
>>> graph.number_of_links
23
>>> graph.number_of_patches
12
class HexGraphExtras[source]#

Bases: object

property nodes_at_bottom_edge#

Get nodes along the bottom edge.

Examples

>>> import numpy as np
>>> from landlab.graph import TriGraph
>>> graph = TriGraph((3, 4), node_layout='rect')
>>> graph.nodes_at_bottom_edge
array([0, 1, 2, 3])
property nodes_at_left_edge#

Get nodes along the left edge.

Examples

>>> import numpy as np
>>> from landlab.graph import TriGraph
>>> graph = TriGraph((3, 4), node_layout='rect')
>>> graph.nodes_at_left_edge
array([0, 4, 8])
property nodes_at_right_edge#

Get nodes along the right edge.

Examples

>>> import numpy as np
>>> from landlab.graph import TriGraph
>>> graph = TriGraph((3, 4), node_layout='rect')
>>> graph.nodes_at_right_edge
array([ 3,  7, 11])
property nodes_at_top_edge#

Get nodes along the top edge.

Examples

>>> import numpy as np
>>> from landlab.graph import TriGraph
>>> graph = TriGraph((3, 4), node_layout='rect')
>>> graph.nodes_at_top_edge
array([ 8,  9, 10, 11])
class HorizontalHexTriGraph[source]#

Bases: object

static corner_nodes(shape)[source]#

Examples

>>> from landlab.graph.hex.hex import HorizontalHexTriGraph
>>> HorizontalHexTriGraph.corner_nodes((3, 2))
(4, 6, 5, 2, 0, 1)
>>> HorizontalHexTriGraph.corner_nodes((7, 1))
(9, 15, 15, 6, 0, 0)
>>> HorizontalHexTriGraph.corner_nodes((6, 1))
(9, 14, 13, 6, 0, 0)
>>> HorizontalHexTriGraph.corner_nodes((4, 2))
(8, 11, 9, 5, 0, 1)
static nodes_at_edge(shape)[source]#

Examples

>>> from landlab.graph.hex.hex import HorizontalHexTriGraph
>>> HorizontalHexTriGraph.nodes_at_edge((5, 3))
(array([11, 15]), array([18, 17]), array([16, 12]), array([7, 3]), array([0, 1]), array([2, 6]))
>>> HorizontalHexTriGraph.nodes_at_edge((4, 3))
(array([11]), array([15, 14, 13]), array([12]), array([7, 3]), array([0, 1]), array([2, 6]))
static number_of_nodes(shape)[source]#
static number_of_perimeter_nodes(shape)[source]#
static perimeter_nodes(shape)[source]#

Examples

>>> from landlab.graph.hex.hex import HorizontalHexTriGraph
>>> HorizontalHexTriGraph.perimeter_nodes((3, 2))
array([4, 6, 5, 2, 0, 1])
>>> HorizontalHexTriGraph.perimeter_nodes((1, 3))
array([2, 1, 0])
static xy_of_node(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0))[source]#
class HorizontalHexTriGraphCython[source]#

Bases: object

static xy_of_node(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0))[source]#
class HorizontalRectTriGraph[source]#

Bases: object

static corner_nodes(shape)[source]#

Examples

>>> from landlab.graph.hex.hex import HorizontalRectTriGraph
>>> HorizontalRectTriGraph.corner_nodes((3, 4))
(11, 8, 0, 3)
>>> HorizontalRectTriGraph.corner_nodes((3, 2))
(5, 4, 0, 1)
>>> HorizontalRectTriGraph.corner_nodes((7, 1))
(6, 6, 0, 0)
>>> HorizontalRectTriGraph.corner_nodes((1, 3))
(2, 0, 0, 2)
static nodes_at_edge(shape)[source]#
static number_of_nodes(shape)[source]#
static number_of_perimeter_nodes(shape)[source]#
static perimeter_nodes(shape)[source]#

Examples

>>> from landlab.graph.hex.hex import HorizontalRectTriGraph
>>> HorizontalRectTriGraph.perimeter_nodes((3, 2))
array([1, 3, 5, 4, 2, 0])
static xy_of_node(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0))[source]#
class HorizontalRectTriGraphCython[source]#

Bases: object

static xy_of_node(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0))[source]#
class TriGraph(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0), orientation='horizontal', node_layout='rect', sort=False)[source]#

Bases: HexGraphExtras, DelaunayGraph

Graph of a structured grid of triangles.

Examples

>>> import numpy as np
>>> from landlab.graph import TriGraph
>>> graph = TriGraph((3, 2))
>>> graph.number_of_nodes == 6
True
>>> np.round(graph.y_of_node * 2. / np.sqrt(3))
...     
array([ 0.,  0.,  1.,  1.,  2.,  2.])
>>> graph.x_of_node 
array([ 0. ,  1. ,  0.5,  1.5,  0. ,  1. ])

Create a structured grid of triangles.

Parameters
  • shape (tuple of int) – Number of rows and columns of the hex grid. The first value is the number of nodes in the first column and the second the number of nodes in the first column.

  • spacing (float, optional) – Length of links.

  • xy_of_lower_left (tuple of float, optional) – Coordinates of lower-left corner of the grid.

  • orientation ({'horizontal', 'vertical'}) – Specify if triangles should be laid out in rows or columns.

  • node_layout ({'rect', 'hex'}) – Specify the overall layout of the nodes. Use rect for the layout to approximate a rectangle and hex for a hexagon.

__init__(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0), orientation='horizontal', node_layout='rect', sort=False)[source]#

Create a structured grid of triangles.

Parameters
  • shape (tuple of int) – Number of rows and columns of the hex grid. The first value is the number of nodes in the first column and the second the number of nodes in the first column.

  • spacing (float, optional) – Length of links.

  • xy_of_lower_left (tuple of float, optional) – Coordinates of lower-left corner of the grid.

  • orientation ({'horizontal', 'vertical'}) – Specify if triangles should be laid out in rows or columns.

  • node_layout ({'rect', 'hex'}) – Specify the overall layout of the nodes. Use rect for the layout to approximate a rectangle and hex for a hexagon.

property node_layout#
property orientation#
property perimeter_nodes#

Get nodes on the convex hull of a Graph.

Examples

>>> import numpy as np
>>> from landlab.graph import Graph
>>> node_x, node_y = [0, 1, 2, 0, 1, 2], [0, 0, 0, 1, 1, 1]
>>> graph = Graph((node_y, node_x))
>>> np.sort(graph.perimeter_nodes)
array([0, 2, 3, 5])
property shape#
property spacing#
class VerticalHexTriGraph[source]#

Bases: object

static corner_nodes(shape)[source]#

Examples

>>> from landlab.graph.hex.hex import VerticalHexTriGraph
>>> VerticalHexTriGraph.corner_nodes((2, 5))
(10, 13, 8, 3, 0, 5)
>>> VerticalHexTriGraph.corner_nodes((2, 3))
(5, 6, 4, 1, 0, 2)
>>> VerticalHexTriGraph.corner_nodes((2, 4))
(10, 11, 7, 3, 0, 2)
>>> VerticalHexTriGraph.corner_nodes((2, 2))
(4, 4, 3, 1, 0, 0)
>>> VerticalHexTriGraph.corner_nodes((3, 1))
(2, 2, 2, 0, 0, 0)
>>> VerticalHexTriGraph.corner_nodes((1, 3))
(2, 3, 1, 1, 0, 2)
static nodes_at_edge(shape)[source]#

Examples

>>> from landlab.graph.hex.hex import VerticalHexTriGraph
>>> VerticalHexTriGraph.nodes_at_edge((3, 7))
(array([ 9, 16]), array([23, 26, 28]), array([29, 27, 24]), array([20, 13]), array([6, 3, 1]), array([0, 2, 5]))
>>> VerticalHexTriGraph.nodes_at_edge((2, 3))
(array([2]), array([5]), array([6]), array([4]), array([1]), array([0]))
>>> VerticalHexTriGraph.nodes_at_edge((2, 4))
(array([2, 6]), array([10]), array([11, 9]), array([7]), array([3, 1]), array([0]))
static number_of_nodes(shape)[source]#
static number_of_perimeter_nodes(shape)[source]#

Examples

>>> from landlab.graph.hex.hex import VerticalHexTriGraph
>>> VerticalHexTriGraph.number_of_perimeter_nodes((2, 3))
6
>>> VerticalHexTriGraph.number_of_perimeter_nodes((2, 2))
5
static perimeter_nodes(shape)[source]#

Examples

>>> from landlab.graph.hex.hex import VerticalHexTriGraph
>>> VerticalHexTriGraph.perimeter_nodes((3, 7))
array([ 9, 16, 23, 26, 28, 29, 27, 24, 20, 13,  6,  3,  1,  0,  2,  5])
>>> VerticalHexTriGraph.perimeter_nodes((2, 3))
array([2, 5, 6, 4, 1, 0])
>>> VerticalHexTriGraph.perimeter_nodes((2, 4))
array([ 2, 6, 10, 11, 9, 7, 3, 1, 0])
>>> VerticalHexTriGraph.perimeter_nodes((2, 2))
array([0, 2, 4, 3, 1])
>>> VerticalHexTriGraph.perimeter_nodes((3, 1))
array([0, 1, 2])
static xy_of_node(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0))[source]#
class VerticalHexTriGraphCython[source]#

Bases: object

static xy_of_node(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0))[source]#
class VerticalRectTriGraph[source]#

Bases: object

static corner_nodes(shape)[source]#

Examples

>>> from landlab.graph.hex.hex import VerticalRectTriGraph
>>> VerticalRectTriGraph.corner_nodes((4, 3))
(10, 9, 0, 1)
>>> VerticalRectTriGraph.corner_nodes((4, 4))
(15, 12, 0, 3)
>>> VerticalRectTriGraph.corner_nodes((3, 2))
(5, 4, 0, 1)
>>> VerticalRectTriGraph.corner_nodes((7, 1))
(6, 6, 0, 0)
>>> VerticalRectTriGraph.corner_nodes((1, 3))
(1, 0, 0, 1)
>>> VerticalRectTriGraph.corner_nodes((2, 3))
(4, 3, 0, 1)
static nodes_at_edge(shape)[source]#
static number_of_nodes(shape)[source]#
static number_of_perimeter_nodes(shape)[source]#
static perimeter_nodes(shape)[source]#

Examples

>>> from landlab.graph.hex.hex import VerticalRectTriGraph
>>> VerticalRectTriGraph.perimeter_nodes((3, 2))
array([1, 3, 5, 4, 2, 0])
>>> VerticalRectTriGraph.perimeter_nodes((2, 3))
array([1, 4, 5, 3, 0, 2])
>>> VerticalRectTriGraph.perimeter_nodes((2, 4))
array([3, 7, 5, 6, 4, 0, 2, 1])
static xy_of_node(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0))[source]#
class VerticalRectTriGraphCython[source]#

Bases: object

static xy_of_node(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0))[source]#

Module contents#

class DualHexGraph(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0), orientation='horizontal', node_layout='rect', sort=False)[source]#

Bases: DualGraph, TriGraph

Graph of a structured grid of triangles.

Examples

>>> import numpy as np
>>> from landlab.graph import DualHexGraph
>>> graph = DualHexGraph((3, 2), node_layout='hex')
>>> graph.number_of_nodes
7
>>> graph.number_of_corners
6
>>> np.round(graph.y_of_node * 2. / np.sqrt(3))
...     
array([ 0.,  0.,  1.,  1.,  1.,  2.,  2.])
>>> graph.x_of_node 
array([ 0.5,  1.5,  0. ,  1. ,  2. ,  0.5,  1.5])

Create a structured grid of triangles.

Parameters
  • shape (tuple of int) – Number of rows and columns of the hex grid. The first value is the number of nodes in the first column and the second the number of nodes in the first column.

  • spacing (float, optional) – Length of links.

  • xy_of_lower_left (tuple of float, optional) – Coordinates of lower-left corner of the grid.

  • orientation ({'horizontal', 'vertical'}) – Specify if triangles should be laid out in rows or columns.

  • node_layout ({'rect', 'hex'}) – Specify the overall layout of the nodes. Use rect for the layout to approximate a rectangle and hex for a hexagon.

__init__(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0), orientation='horizontal', node_layout='rect', sort=False)[source]#

Create a structured grid of triangles.

Parameters
  • shape (tuple of int) – Number of rows and columns of the hex grid. The first value is the number of nodes in the first column and the second the number of nodes in the first column.

  • spacing (float, optional) – Length of links.

  • xy_of_lower_left (tuple of float, optional) – Coordinates of lower-left corner of the grid.

  • orientation ({'horizontal', 'vertical'}) – Specify if triangles should be laid out in rows or columns.

  • node_layout ({'rect', 'hex'}) – Specify the overall layout of the nodes. Use rect for the layout to approximate a rectangle and hex for a hexagon.

property adjacent_corners_at_corner#

Get adjacent corners.

See also

Graph.adjacent_nodes_at_node

property adjacent_faces_at_face#
property angle_of_face#

Get the angle of each face.

See also

Graph.angle_of_link

property area_of_cell#

Get the area of each cell.

See also

Graph.area_of_patch

property cells_at_corner#

Get the cells that touch each corner.

See also

Graph.patches_at_node

property cells_at_face#

Get the cells on either side of each face.

See also

Graph.patches_at_link

property corner_at_face_head#

Get corners at face head.

See also

Graph.node_at_link_head

property corner_at_face_tail#

Get corners at face tail.

See also

Graph.node_at_link_tail

property corner_layout#
property corner_x#
property corner_y#
property corners#

Get identifier for each corner.

See also

Graph.nodes

property corners_at_bottom_edge#

Get corners along the bottom edge.

See also

Graph.nodes_at_bottom_edge

property corners_at_cell#

Get the corners that define a cell.

See also

Graph.nodes_at_patch

property corners_at_face#

Get corners at either end of faces.

See also

Graph.nodes_at_link

property corners_at_left_edge#

Get corners along the left edge.

See also

Graph.nodes_at_left_edge

property corners_at_right_edge#

Get corners along the right edge.

See also

Graph.nodes_at_right_edge

property corners_at_top_edge#

Get corners along the top edge.

See also

Graph.nodes_at_top_edge

property face_dirs_at_corner#

Get directions of faces touching a corner.

See also

Graph.link_dirs_at_node

property faces_at_cell#

Get the faces that define a cell.

See also

Graph.links_at_patch

property faces_at_corner#

Get faces touching a corner.

See also

Graph.links_at_node

property length_of_face#
property midpoint_of_face#

Get the middle of faces.

See also

Graph.midpoint_of_link

property number_of_cells#

Get the number of cells.

See also

Graph.number_of_patches

property number_of_corners#

Get total number of corners.

See also

Graph.number_of_nodes

property number_of_faces#

Get corners at face head.

See also

Graph.number_of_links

property perimeter_corners#

Get corners on the convex hull of a Graph.

See also

Graph.perimeter_nodes

property unit_vector_at_corner#

Get a unit vector for each corner.

See also

Graph.unit_vector_at_node

property unit_vector_at_face#

Make arrays to store the unit vectors associated with each face.

See also

Graph.unit_vector_at_link

property x_of_corner#

Get x-coordinate of corner.

See also

Graph.x_of_node

property xy_of_cell#

Get the centroid of each cell.

See also

Graph.xy_of_patch

property xy_of_corner#

Get x and y-coordinates of corner.

See also

Graph.xy_of_node

property xy_of_face#
property y_of_corner#

Get y-coordinate of corner.

See also

Graph.y_of_node

class TriGraph(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0), orientation='horizontal', node_layout='rect', sort=False)[source]#

Bases: HexGraphExtras, DelaunayGraph

Graph of a structured grid of triangles.

Examples

>>> import numpy as np
>>> from landlab.graph import TriGraph
>>> graph = TriGraph((3, 2))
>>> graph.number_of_nodes == 6
True
>>> np.round(graph.y_of_node * 2. / np.sqrt(3))
...     
array([ 0.,  0.,  1.,  1.,  2.,  2.])
>>> graph.x_of_node 
array([ 0. ,  1. ,  0.5,  1.5,  0. ,  1. ])

Create a structured grid of triangles.

Parameters
  • shape (tuple of int) – Number of rows and columns of the hex grid. The first value is the number of nodes in the first column and the second the number of nodes in the first column.

  • spacing (float, optional) – Length of links.

  • xy_of_lower_left (tuple of float, optional) – Coordinates of lower-left corner of the grid.

  • orientation ({'horizontal', 'vertical'}) – Specify if triangles should be laid out in rows or columns.

  • node_layout ({'rect', 'hex'}) – Specify the overall layout of the nodes. Use rect for the layout to approximate a rectangle and hex for a hexagon.

__init__(shape, spacing=1.0, xy_of_lower_left=(0.0, 0.0), orientation='horizontal', node_layout='rect', sort=False)[source]#

Create a structured grid of triangles.

Parameters
  • shape (tuple of int) – Number of rows and columns of the hex grid. The first value is the number of nodes in the first column and the second the number of nodes in the first column.

  • spacing (float, optional) – Length of links.

  • xy_of_lower_left (tuple of float, optional) – Coordinates of lower-left corner of the grid.

  • orientation ({'horizontal', 'vertical'}) – Specify if triangles should be laid out in rows or columns.

  • node_layout ({'rect', 'hex'}) – Specify the overall layout of the nodes. Use rect for the layout to approximate a rectangle and hex for a hexagon.

property node_layout#
property orientation#
property perimeter_nodes#

Get nodes on the convex hull of a Graph.

Examples

>>> import numpy as np
>>> from landlab.graph import Graph
>>> node_x, node_y = [0, 1, 2, 0, 1, 2], [0, 0, 0, 1, 1, 1]
>>> graph = Graph((node_y, node_x))
>>> np.sort(graph.perimeter_nodes)
array([0, 2, 3, 5])
property shape#
property spacing#