landlab

landlab.utils package

Submodules

landlab.utils.count_repeats module

Count repeated values in an array.

count_repeated_values(values)[source]

Count how many times in an array values repeat and where they appear.

Return a list of length n that gives the values and indices of repeated values. The first element of the list will be the values and indices of all values that appear once or the first time repeated values appear. The next element, values that repeat twice or more, and so on. Thus, the length of the returned list will be the maximum number that any value is repeated in x.

Parameters:

values : array_like

Input array to count repeated values.

Returns:

list of tuple

List of tuples of (repeated_values, indices).

Examples

For an array that contains no repeated values, this function just returns a copy of x, and the indices to each element.

>>> import numpy as np
>>> from landlab.utils.count_repeats import count_repeated_values
>>> counts = count_repeated_values(np.array([20, 30, 40], dtype=np.int))
>>> len(counts)
1
>>> counts[0]
(array([20, 30, 40]), array([0, 1, 2]))

If x contains a repeated value, the first element contains all unique values along with their indices. For repeated values, return indices to their first occurance. The second element contains values and indices to values occuring two or more times.

>>> counts = count_repeated_values(np.array([20, 30, 40, 30, 30],
...     dtype=np.int))
>>> len(counts)
3
>>> counts[0]
(array([20, 30, 40]), array([0, 1, 2]))
>>> counts[1]
(array([30]), array([3]))
>>> counts[2]
(array([30]), array([4]))

The input array remains unchanged.

>>> x = np.array([20, 30, 30, 40], dtype=np.int)
>>> counts = count_repeated_values(x)
>>> x
array([20, 30, 30, 40])

landlab.utils.decorators module

General decorators for the landlab library.

General Landlab decorators

use_file_name_or_kwds(func) Decorate a method so that it takes a file name or keywords.
use_field_name_or_array(at_element) Decorate a function so that it accepts a field name or array.
make_return_array_immutable(func) Decorate a function so that its return array is read-only.
deprecated(use, version) Mark a function as deprecated.
deprecated(use, version)[source]

Mark a function as deprecated.

Parameters:

use : str

Name of replacement function to use.

version : str

Version number when function was marked as deprecated.

Returns:

func

A wrapped function that issues a deprecation warning.

make_return_array_immutable(func)[source]

Decorate a function so that its return array is read-only.

Parameters:

func : function

A function that returns a numpy array.

Returns:

func

A wrapped function that returns a read-only view of an array.

read_only_array(func)[source]

Decorate a function so that its return array is read-only.

Parameters:

func : function

A function that returns a numpy array.

Returns:

func

A wrapped function that returns a read-only numpy array.

class store_result_in_grid(name=None)[source]

Bases: object

class use_field_name_or_array(at_element)[source]

Bases: object

Decorate a function so that it accepts a field name or array.

Parameters:

func : function

A function that accepts a grid and array as arguments.

at_element : str

The element type that the field is defined on (‘node’, ‘cell’, etc.)

Returns:

func

A wrapped function that accepts a grid and either a field name or a numpy array.

Examples

>>> from landlab import RasterModelGrid
>>> grid = RasterModelGrid((4, 5), spacing=(1, 2))
>>> def my_func(grid, vals):
...     return grid.area_of_cell * vals
>>> my_func(grid, np.arange(grid.number_of_cells))
array([  0.,   2.,   4.,   6.,   8.,  10.])

Decorate the function so that the second argument can be array-like or the name of a field contained withing the grid. The decorator takes a single argument that is the name (as a str) of the grid element that the values are defined on (“node”, “cell”, etc.).

>>> from landlab.utils.decorators import use_field_name_or_array
>>> @use_field_name_or_array('cell')
... def my_func(grid, vals):
...     return grid.area_of_cell * vals

The array of values now can be list or anything that can be converted to a numpy array.

>>> my_func(grid, [0, 1, 2, 3, 4, 5])
array([  0.,   2.,   4.,   6.,   8.,  10.])

The array of values doesn’t have to be flat.

>>> vals = np.array([[0, 1, 2], [3, 4, 5]])
>>> my_func(grid, vals)
array([  0.,   2.,   4.,   6.,   8.,  10.])

The array of values can be a field name.

>>> _ = grid.add_field('cell', 'elevation', [0, 1, 2, 3, 4, 5])
>>> my_func(grid, 'elevation')
array([  0.,   2.,   4.,   6.,   8.,  10.])
use_file_name_or_kwds(func)[source]

Decorate a method so that it takes a file name or keywords.

Parameters:

func : A function

A method function that accepts a ModelGrid as a first argument.

Returns:

function

A function that takes an optional second argument, a file, from which to read keywords.

Examples

>>> from landlab import RasterModelGrid
>>> from landlab.utils.decorators import use_file_name_or_kwds
>>> class MyClass(object):
...     @use_file_name_or_kwds
...     def __init__(self, grid, kw=0.):
...         self.kw = kw
>>> grid = RasterModelGrid((4, 5))
>>> foo = MyClass(grid)
>>> foo.kw
0.0
>>> foo = MyClass(grid, "kw: 1945")
>>> foo.kw
1945
>>> foo = MyClass(grid, "kw: 1945", kw=1973)
>>> foo.kw
1973
>>> mpd = """
... kw: kw value
... 1e6
... """
>>> foo = MyClass(grid, mpd)
>>> foo.kw
1000000.0

landlab.utils.fault_facet_finder module

This class is designed to provide functions to allow the automated identification of planar facet surfaces above fault traces. Module is SLOW (e.g., minutes+ per full analysis of a “large” data set). It is only intended for model post-analysis or DEM analysis. Do not loop this class!! This is part of the NSF funded project investigating fault scarp degradation, Tucker, Hobley, McCoy.

class find_facets(grid, elev_field='topographic__elevation', fault_azimuth=None)[source]

Bases: object

Note that this class assumes the grid does not change during the model run. Changes to data stored in the grid should (?) update automatically.

If fault_azimuth is supplied, it should be -pi/2 < az <= pi/2 (i.e., we don’t consider fault dip, even if it’s known).

analyse_fault_trace(fault_trace_node_ids)[source]

This method takes the grid and an array listing the (contiguous) node ids of cells that contain a single fault segment trace of interest.

It sets and returns the azimuth of the fault trace, az, -pi/2 < az <= pi/2. (i.e., smallest angle between north and the trace).

define_aspect_node_subset(angle_tolerance=5.0)[source]

This method sets and returns a list of all nodes in the landscape which have an aspect within 5 degrees of perpendicular to the fault trace.

It assumes self.az, the angle between north and the fault trace, has already been set, and also that self.slopes and self.aspect are also set. The returned boolean array is num_core_nodes long. angle_tolerance is the angle in degrees that the aspect must be within from the fault trace angle. NB: this version is too discriminating on the aspect restriction, presumably because we use only a single ft angle for what’s really a 2d trace. Need to work with local aspect.

define_aspect_node_subset_local(dist_tolerance=4.0, angle_tolerance=15.0, dip_dir='E')[source]
define_steep_nodes(threshold_in_degrees=5.0)[source]

This method sets and returns a list of all nodes in the landscape which are “steep” and could be part of a facet. The critical hillslope angle is set by threshold_in_degrees, and defaults to 5.

This assumes you have already called define_aspect_node_subset, in which self.slope is set. The returned boolean array is num_core_nodes long.

find_coherent_facet_patches(tolerance=3.0, threshold_num_px=12)[source]

This method searches the (already determined) possible pixels for patches with coherent slope angles, within a tolerance (in degrees). A patch is only recorded if it consists of at least threshold_num_px.

The method records and returns:

  • a ragged array of lists, where each list is the pixels comprising each facet patch, and
  • a (num_patches, 2) array recording the mean slope and and its stdev for each patch.
find_slope_lines(tolerance=1.0)[source]

This method attempts to find slope-consistent line profiles up facets, perpendicular to the fault. Assumes you used define_aspect_node_subset_local().

fit_slopes_to_facet_lines(polynomial_degree=4, curvature_threshold=0.0004)[source]

Fits (linear) lines of best fit to extracted profiles, already stored as class properties.

set_slopes_aspects()[source]
show_possible_nodes()[source]

Once the subsets by aspect and slope have been set, call this function to see both the whole elevation map, and the subset of nodes that will be searched.

landlab.utils.jaggedarray module

The JaggedArray class to store arrays of variable-length arrays.

Examples

Create a JaggedArray that stores link IDs for the links attached to the nodes of a 3x3 grid.

>>> from landlab.utils.jaggedarray import JaggedArray
>>> links_at_node = JaggedArray([
...     [0, 6],
...     [1, 7, 0],
...     [8, 1],
...     [2, 9, 6],
...     [3, 10, 2, 7],
...     [11, 3, 8],
...     [4, 7],
...     [5, 10, 4],
...     [5, 11]])

Make up some data that provides values at each of the links.

>>> value_at_link = np.arange(12, dtype=float)

Create another JaggedArray. Here we store the values at each of the links attached to nodes of the grid.

>>> values_at_node = JaggedArray.empty_like(links_at_node, dtype=float)
>>> values_at_node.array[:] = value_at_link[links_at_node.array]

Now operate on the link values for each node.

>>> values_at_node.foreach_row(sum)
array([  6.,   8.,   9.,  17.,  22.,  22.,  11.,  19.,  16.])
>>> values_at_node.foreach_row(min)
array([ 0.,  0.,  1.,  2.,  2.,  3.,  4.,  4.,  5.])
>>> values_at_node.foreach_row(np.ptp)
array([ 6.,  7.,  7.,  7.,  8.,  8.,  3.,  6.,  6.])
class JaggedArray(*args)[source]

Bases: object

A container for an array of variable-length arrays.

JaggedArray([row0, row1, ...]) JaggedArray(values, values_per_row)

Examples

Create a JaggedArray with an array of arrays.

>>> from landlab.utils.jaggedarray import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.array
array([0, 1, 2, 3, 4])

Create a JaggedArray as a 1D array and a list or row lengths.

>>> x = JaggedArray([0, 1, 2, 3, 4], (3, 2))
>>> x.array
array([0, 1, 2, 3, 4])
array

The jagged array as a 1D array.

Returns:

array :

A view of the underlying 1D array.

Examples

>>> from landlab.utils.jaggedarray import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.array
array([0, 1, 2, 3, 4])
>>> x.array[0] = 1
>>> x.array
array([1, 1, 2, 3, 4])
static empty_like(jagged, dtype=None)[source]

Create a new JaggedArray that is like another one.

Parameters:

jagged : JaggedArray

A JaggedArray to copy.

dtype : np.dtype

The data type of the new JaggedArray.

Returns:

JaggedArray

A new JaggedArray.

foreach_row(func, out=None)[source]

Apply an operator row-by-row.

Examples

>>> from landlab.utils.jaggedarray import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.foreach_row(sum)
array([3, 7])
>>> out = np.empty(2, dtype=int)
>>> x.foreach_row(sum, out=out) is out
True
>>> out
array([3, 7])
length_of_row(row)[source]

Number of values in a given row.

Parameters:

row : int

Index to a row.

Returns:

int :

Number of values in the row.

Examples

>>> from landlab.utils.jaggedarray import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.length_of_row(0)
3
>>> x.length_of_row(1)
2
number_of_rows

Number of array rows.

Returns:

int :

Number of rows in the array.

Examples

>>> from landlab.utils.jaggedarray import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.number_of_rows
2
offset

The offsets to rows of a 1D array.

Returns:

array :

Offsets into the underlying 1D array.

Examples

>>> from landlab.utils.jaggedarray import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.offset
array([0, 3, 5])

From the offsets you can get values for rows of the jagged array.

>>> x.array[x.offset[0]:x.offset[1]]
array([0, 1, 2])

Once the array is created, you can’t change the offsets.

>>> x.offset[0] = 1
Traceback (most recent call last):
ValueError: assignment destination is read-only
row(row)[source]

Get the values of a row as an array.

Parameters:

row : int

Index to a row.

Returns:

array :

Values in the row as a slice of the underlying array.

Examples

>>> from landlab.utils.jaggedarray import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.row(0)
array([0, 1, 2])
>>> x.row(1)
array([3, 4])
>>> y = x.row(0)
>>> y[0] = 1
>>> x.row(0)
array([1, 1, 2])
size

Number of array elements.

Returns:

int :

Number of values in the array.

Examples

>>> from landlab.utils.jaggedarray import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.size
5
flatten_jagged_array(jagged, dtype=None)[source]

Flatten a list of lists.

Parameters:

jagged : array_like of array_like

An array of arrays of unequal length.

Returns:

(data, offset) : (ndarray, ndarray of int)

A tuple the data, as a flat numpy array, and offsets into that array for every item of the original list.

Examples

>>> from landlab.utils.jaggedarray import flatten_jagged_array
>>> data, offset = flatten_jagged_array([[1, 2], [], [3, 4, 5]], dtype=int)
>>> data
array([1, 2, 3, 4, 5])
>>> offset
array([0, 2, 2, 5])
unravel(data, offset, out=None, pad=None)[source]

Unravel a jagged array.

Parameters:

data : ndarray

Flattened-array of the data.

offset : ndarray of int

Offsets to the start of rows of the jagged array.

out : ndarray

Buffer into which to place the unravelled data.

pad : number

Value to use to pad rows of the jagged array.

Returns:

ndarray

Matrix that holds the unravelled jagged array.

landlab.utils.jaggedarray_ma module

Store arrays of variable-length arrays implemented with masked arrays.

Implements a JaggedArray class using numpy masked arrays.

Examples

Create a JaggedArray that stores link IDs for the links attached to the nodes of a 3x3 grid.

>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> links_at_node = JaggedArray([
...     [0, 6],
...     [1, 7, 0],
...     [8, 1],
...     [2, 9, 6],
...     [3, 10, 2, 7],
...     [11, 3, 8],
...     [4, 7],
...     [5, 10, 4],
...     [5, 11]])

Make up some data that provides values at each of the links.

>>> value_at_link = np.arange(12, dtype=float)

Create another JaggedArray. Here we store the values at each of the links attached to nodes of the grid.

>>> values_at_node = JaggedArray.empty_like(links_at_node, dtype=float)
>>> values_at_node.array = value_at_link[links_at_node.array]

Now operate on the link values for each node.

>>> values_at_node.foreach_row(np.sum)
array([  6.,   8.,   9.,  17.,  22.,  22.,  11.,  19.,  16.])
>>> values_at_node.foreach_row(np.min)
array([ 0.,  0.,  1.,  2.,  2.,  3.,  4.,  4.,  5.])
>>> values_at_node.foreach_row(np.ptp)
array([ 6.,  7.,  7.,  7.,  8.,  8.,  3.,  6.,  6.])
class JaggedArray(*args)[source]

Bases: object

A container for an array of variable-length arrays.

JaggedArray([row0, row1, ...]) JaggedArray(values, values_per_row)

Examples

Create a JaggedArray with an array of arrays.

>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.array
array([0, 1, 2, 3, 4])

Create a JaggedArray as a 1D array and a list or row lengths.

>>> x = JaggedArray([0, 1, 2, 3, 4], (3, 2))
>>> x.array
array([0, 1, 2, 3, 4])
array

The jagged array as a 1D array.

Returns:

array :

A view of the underlying 1D array.

Examples

>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.array
array([0, 1, 2, 3, 4])
>>> x.array = np.array([1, 1, 2, 3, 4])
>>> x.array
array([1, 1, 2, 3, 4])
static empty_like(jagged, dtype=None)[source]

Create a new JaggedArray that is like another one.

Parameters:

jagged : JaggedArray

A JaggedArray to copy.

dtype : np.dtype

The data type of the new JaggedArray.

Returns:

JaggedArray

A new JaggedArray.

foreach_row(func, out=None)[source]

Apply an operator row-by-row.

Examples

>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.foreach_row(np.sum)
array([3, 7])
>>> out = np.empty(2, dtype=int)
>>> x.foreach_row(np.sum, out=out) is out
True
>>> out
array([3, 7])
length_of_row(row)[source]

Number of values in a given row.

Parameters:

row : int

Index to a row.

Returns:

int :

Number of values in the row.

Examples

>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.length_of_row(0)
3
>>> x.length_of_row(1)
2
static ma_from_flat_array(array, values_per_row)[source]

Create a masked array from a flat array.

Parameters:

array : array_like

Values of the jagged array.

values_per_row : array_like of int

Number of values in each row of the jagged array.

Returns:

np.masked_array

A new masked array.

static ma_from_list_of_lists(rows, dtype=None)[source]

Create a masked array from a list of lists.

Parameters:

rows : array_like or array_like

Rows of the jagged array.

dtype : np.dtype, optional

The data type of the new masked array.

Returns:

np.masked_array

A new masked array.

masked_array

The jagged array as a masked array.

Returns:

np.masked_array :

The underlying masked array.

number_of_rows

Number of array rows.

Returns:

int :

Number of rows in the array.

Examples

>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.number_of_rows == 2
True
row(row)[source]

Get the values of a row as an array.

Parameters:

row : int

Index to a row.

Returns:

array :

Values in the row as a slice of the underlying array.

Examples

>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.row(0)
array([0, 1, 2])
>>> x.row(1)
array([3, 4])
size

Number of array elements.

Returns:

int :

Number of values in the array.

Examples

>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.size
5

landlab.utils.structured_grid module

Utility functions for structured grid of elements with four neighbors.

active_cell_count(shape)[source]

Number of active cells.

Number of active cells. By default, all cells are active so this is the same as cell_count. (active = core+open boundary)

active_cell_index(shape)[source]

Array of active cells.

Note

deprecated

For many instances, core_cell_index() may be preferred. Ordered indices of the active (core+open boundary) cells of a structured grid.

active_cell_index_at_nodes(shape, boundary_node_index=-1)[source]

Array of active cells at nodes.

Deprecated since version 0.6.

Up to date, unambiguous terminology core_cell_index_at_nodes() preferred. Indices of the active cells associated with the nodes of the structured grid. For nodes that don’t have a cell (that is, boundary nodes) set indices to BAD_INDEX_VALUE. Use the boundary_node_index keyword to change the value of indices to boundary nodes.

Note that all three functions [X]_cell_index_at_nodes are equivalent.

>>> from landlab.utils.structured_grid import active_cell_index_at_nodes
>>> active_cell_index_at_nodes((3, 4), boundary_node_index=-1)
...     
array([-1, -1, -1, -1,
       -1,  0,  1, -1,
       -1, -1, -1, -1])
active_cell_node(shape)[source]

Array of nodes at cells.

Note

deprecated

For many instances, core_cell_node() may be preferred. Indices of the nodes belonging to each active (core + open boundary) cell. Since all cells are active in the default case, this is the same as node_at_cell.

Examples

>>> from landlab.utils.structured_grid import active_cell_node
>>> active_cell_node((4,3))
array([4, 7])

Array of active links pointing to the the east.

Examples

>>> from landlab.utils.structured_grid import active_east_links
>>> active_east_links((3, 4))
array([[-1, -1, -1, -1],
       [ 4,  5,  6, -1],
       [-1, -1, -1, -1]])
active_east_links2(shape, node_status=None)[source]

Array of active links pointing to the the east.

Examples

>>> from landlab.utils.structured_grid import active_east_links2
>>> active_east_links2((3, 4))
array([[-1, -1, -1, -1],
       [ 7,  8,  9, -1],
       [-1, -1, -1, -1]])
active_face_count(shape)[source]

Number of active faces.

Total number of active faces in a structured grid with dimensions, shape. Each cell has four faces, and shared faces only count once. An active face is one that has a corresponing active link.

>>> from landlab.utils.structured_grid import active_face_count
>>> active_face_count((3, 4))
7
active_face_index(shape)[source]

Array of face indices.

Number of active links entering each node.

Array of active links entering nodes.

active_inlinks2(shape, node_status=None)[source]

Array of active links entering nodes.

Finds and returns the link IDs of active links coming in to each node (that is, active links for which the node is the link head).

Parameters:

shape : 2-element tuple of ints

Number of rows and columns in the grid

node_status (optional) : numpy array of bool (x # of nodes)

False where node is a closed boundary; True elsewhere

Returns:

2d numpy array of int (2 x number of grid nodes)

Link ID of incoming links to each node

Notes

There are at most two inlinks for each node. The first row in the returned array gives the ID of the vertical incoming link from below (south), or -1 if there is none. The second row gives the link ID of the horizontal link coming in from the left (or -1).

Examples

>>> from landlab.utils.structured_grid import active_inlinks2
>>> active_inlinks2((3,4))
array([[-1, -1, -1, -1, -1,  4,  5, -1, -1, 11, 12, -1],
       [-1, -1, -1, -1, -1,  7,  8,  9, -1, -1, -1, -1]])

Number of active links.

Number of active links in a structured grid with dimensions, shape. A link is active if it connects to at least one active node.

>>> from landlab.utils.structured_grid import link_count, active_link_count
>>> link_count((3, 2))
7
>>> active_link_count((3, 2))
0
>>> active_link_count((3, 4))
7

Link IDs for active links of a structured quad grid.

Return the link IDs for links that are active in a structured grid of quadrilaterals. Use the node_status_array keyword to specify the status for each of the grid’s nodes. If not given, each of the perimeter nodes is assumed to be FIXED_VALUE_BOUNDARY.

Use the link_nodes keyword to provide, as a tuple of arrays, that give the from-node and the to-node for each for each link in the grid.

Parameters:

shape : tuple

Shape of grid as number of node rows and columns.

node_status_array : array_like, optional

Status of each grid node.

link_nodes : array_like, optional

Examples

Because, by default, the perimeter nodes are FIXED_VALUE_BOUNDARY nodes, only links attached to the interior nodes are active.

>>> from landlab.utils.structured_grid import active_links
>>> from landlab import CLOSED_BOUNDARY, CORE_NODE
>>> active_links((3, 4))
array([ 1,  2,  5,  6, 11, 12, 13])

If all the perimeter nodes CLOSED_BOUNDARY nodes, the only active link is between the two core nodes.

>>> node_status = np.ones(3 * 4) * CLOSED_BOUNDARY
>>> node_status[5:7] = CORE_NODE
>>> active_links((3, 4), node_status_array=node_status)
array([12])

You can also provide a list of all the from_nodes and to_nodes for the grid. The following describes a grid with only a single link (between nodes 5 and 6).

>>> active_links((3, 4), link_nodes=(np.array([5]), np.array([6])))
array([0])

Array of active links pointing to the the north.

active_north_links2(shape, node_status=None)[source]

Array of active links pointing to the the north.

>>> from landlab.utils.structured_grid import active_north_links2
>>> active_north_links2((3, 4))
array([[-1,  4,  5, -1],
       [-1, 11, 12, -1],
       [-1, -1, -1, -1]])

Number of active links leaving each node.

Array of active links leaving nodes.

active_outlinks2(shape, node_status=None)[source]

Array of active links leaving nodes.

Finds and returns the link IDs of active links going out of each node (that is, active links for which the node is the link tail).

Parameters:

shape : 2-element tuple of ints

Number of rows and columns in the grid

node_status (optional) : numpy array of bool (x # of nodes)

False where node is a closed boundary; True elsewhere

Returns:

2d numpy array of int (2 x number of grid nodes)

Link ID of outgoing links from each node

Notes

There are at most two outlinks for each node. The first row in the returned array gives the ID of the vertical outgoing link to above (north), or -1 if there is none. The second row gives the link ID of the horizontal link going out to the right (east) (or -1).

Examples

>>> from landlab.utils.structured_grid import active_outlinks2
>>> active_outlinks2((3,4))
array([[-1,  4,  5, -1, -1, 11, 12, -1, -1, -1, -1, -1],
       [-1, -1, -1, -1,  7,  8,  9, -1, -1, -1, -1, -1]])

Array of active links pointing to the the south.

active_south_links2(shape, node_status=None)[source]

Array of active links pointing to the the south.

Finds and returns link IDs of active links that enter each node from the south (bottom), or -1 where no such active link exists.

Parameters:

shape : 2-element tuple of int

number of rows and columns in grid

node_status (optional) : 1d numpy array of bool

False where node is a closed boundary, True otherwise

Returns:

2d numpy array of int

Link ID of active link connecting to a node from the south, or -1

Notes

Like active_south_links, but returns link IDs rather than (now deprecated) active-link IDs.

Examples

>>> from landlab.utils.structured_grid import active_south_links2
>>> active_south_links2((3, 4))
array([[-1, -1, -1, -1],
       [-1,  4,  5, -1],
       [-1, 11, 12, -1]])

Array of active links pointing to the the west.

Examples

>>> from landlab.utils.structured_grid import active_west_links
>>> active_west_links((3, 4))
array([[-1, -1, -1, -1],
       [-1,  4,  5,  6],
       [-1, -1, -1, -1]])
active_west_links2(shape, node_status=None)[source]

Array of active links pointing to the the west.

Examples

>>> from landlab.utils.structured_grid import active_west_links2
>>> active_west_links2((3, 4))
array([[-1, -1, -1, -1],
       [-1,  7,  8,  9],
       [-1, -1, -1, -1]])
bottom_edge_node_ids(shape)[source]

Array of nodes on the bottom edge.

bottom_index_iter(shape)[source]

Iterator for the bottom boundary indices of a structured grid.

bottom_top_iter(shape)[source]

Iterator for bottom then top indices of a structured grid.

Examples

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

Number of boundary cells.

Deprecated since version 0.6.

Deprecated due to imprecise terminology; this function makes little sense. Use perimeter_node_count() instead. Number of cells that are on the perimeter of a structured grid with dimensions, shape, and thus boundary cells. In fact, cells centered on boundary nodes are not really cells. If they were, though, this is how many there would be.

Note

SN 30-Nov-14 Shouldn’t be deprecated. This routine returns the cells on the boundary. Not the cells surrounding boundary nodes because there aren’t cells around boundary nodes by definition as previously understood.

Examples

>>> from landlab.utils.structured_grid import boundary_cell_count
>>> boundary_cell_count((3, 4))
10
boundary_iter(shape)[source]

Iterator for perimeter nodes.

Deprecated since version 0.6: Deprecated due to imprecise terminology. This is really perimeter_iter (see below). Iterates over all of the boundary node indices of a structured grid in order.

Examples

>>> import numpy as np
>>> from landlab.utils.structured_grid import boundary_iter
>>> np.fromiter(boundary_iter((4, 3)), dtype=np.int)
array([ 0,  1,  2,  3,  5,  6,  8,  9, 10, 11])
boundary_nodes(shape)[source]

Array of perimeter nodes.

Deprecated since version 0.6: Deprecated due to imprecise terminology. This is really perimeter_iter (see below).

An array of the indices of the boundary nodes.

Examples

>>> from landlab.utils.structured_grid import boundary_nodes
>>> boundary_nodes((3, 4))
array([ 0,  1,  2,  3,  4,  7,  8,  9, 10, 11])
cell_count(shape)[source]

Total number of cells.

The total number of cells in a structured grid with dimensions, shape. Where shape is a tuple that gives the dimensions of the grid as number of rows of nodes followed by number of columns of nodes.

>>> from landlab.utils.structured_grid import cell_count
>>> cell_count((3, 4))
2
>>> cell_count((1, 4))
0
cell_index_at_nodes(shape, boundary_node_index=-1)[source]

Array of cells at nodes.

Note

deprecated

Indices of the core cells associated with the nodes of the structured grid. For nodes that don’t have a cell (that is, boundary nodes) set indices to BAD_INDEX_VALUE. Use the boundary_node_index keyword to change the value of indices to boundary nodes.

Note that all three functions [X]_cell_index_at_nodes are equivalent.

Examples

>>> from landlab.utils.structured_grid import cell_index_at_nodes
>>> cell_index_at_nodes((3, 4), boundary_node_index=-1)
...     
array([-1, -1, -1, -1,
       -1,  0,  1, -1,
       -1, -1, -1, -1])
cell_index_with_halo(shape, halo_indices=-1, inactive_indices=None)[source]

Array of cells with a halo of no-data values.

Examples

>>> from landlab.utils.structured_grid import cell_index_with_halo
>>> cell_index_with_halo((2, 3), halo_indices=-1)
array([[-1, -1, -1, -1, -1],
       [-1,  0,  1,  2, -1],
       [-1,  3,  4,  5, -1],
       [-1, -1, -1, -1, -1]])
>>> cell_index_with_halo((2, 3), halo_indices=-1, inactive_indices=-1)
array([[-1, -1, -1, -1, -1],
       [-1, -1, -1, -1, -1],
       [-1, -1, -1, -1, -1],
       [-1, -1, -1, -1, -1]])
core_cell_count(shape)[source]

Number of core cells.

Number of core cells. By default, all cells are core so this is the same as cell_count.

core_cell_index(shape)[source]

Array of core cells.

Note

deprecated

Ordered indices of the core cells of a structured grid.

core_cell_index_at_nodes(shape, boundary_node_index=-1)[source]

Array of core cells at nodes.

Note

deprecated

Indices of the core cells associated with the nodes of the structured grid. For nodes that don’t have a cell (that is, boundary nodes) set indices to BAD_INDEX_VALUE. Use the boundary_node_index keyword to change the value of indices to boundary nodes.

Note that all three functions [X]_cell_index_at_nodes are equivalent.

Examples

>>> from landlab.utils.structured_grid import core_cell_index_at_nodes
>>> core_cell_index_at_nodes((3, 4), boundary_node_index=-1)
...     
array([-1, -1, -1, -1,
       -1,  0,  1, -1,
       -1, -1, -1, -1])
core_cell_node(shape)[source]

Array of nodes at core cells.

Note

deprecated

Indices of the nodes belonging to each core cell. Since all cells are core in the default case, this is the same as node_at_cell.

>>> from landlab.utils.structured_grid import core_cell_node
>>> core_cell_node((4,3))
array([4, 7])
corners(shape)[source]

Array of the indices of the grid corner nodes.

diagonal_array_slow(shape)[source]

Array of diagonal cells (the slow way).

Note

deprecated

diagonal_cell_array(shape, out_of_bounds=-1, contiguous=True)[source]

Array of diagonal cells.

Construct a matrix of cell indices to each diagonally adjacent cell of a structured grid. If a cell does not have a diagonal neighbor, set the index for that neighbor to out_of_bounds.

Examples

A grid without any cells returns an empty array.

>>> from landlab.utils.structured_grid import diagonal_cell_array
>>> diags = diagonal_cell_array((2, 3), out_of_bounds=-1)
>>> len(diags) == 0
True

A grid that has only one cell does not have any neighbors so all of its diagonals are set to out_of_bounds. >>> diags = diagonal_cell_array((3, 3), out_of_bounds=-1) >>> diags array([[-1, -1, -1, -1]])

>>> diags = diagonal_cell_array((4, 4), out_of_bounds=-1)
>>> diags 
array([[ 3, -1, -1, -1], [-1,  2, -1, -1],
       [-1, -1, -1,  1], [-1, -1,  0, -1]])
>>> diags = diagonal_cell_array((4, 5), out_of_bounds=-1)
>>> diags 
array([[ 4, -1, -1, -1], [ 5,  3, -1, -1], [-1,  4, -1, -1],
       [-1, -1, -1,  1], [-1, -1,  0,  2], [-1, -1,  1, -1]])
diagonal_node_array(shape, out_of_bounds=-1, contiguous=True, boundary_node_mask=None)[source]

Array of diagonal nodes.

Creates a list of IDs of the diagonal cells to each cell, as a 2D array. Only interior cells are assigned neighbors; boundary cells get -1 for each neighbor. The order of the diagonal cells is [topright, topleft, bottomleft, bottomright].

Examples

>>> from landlab.utils.structured_grid import diagonal_node_array
>>> diags = diagonal_node_array((2, 3), out_of_bounds=-1)
>>> diags
array([[ 4, -1, -1, -1],
       [ 5,  3, -1, -1],
       [-1,  4, -1, -1],
       [-1, -1, -1,  1],
       [-1, -1,  0,  2],
       [-1, -1,  1, -1]])
>>> diags.flags['C_CONTIGUOUS']
True
>>> diags = diagonal_node_array((2, 3), out_of_bounds=-1, contiguous=False)
>>> diags.flags['C_CONTIGUOUS']
False

Array of links pointing to the the east.

Examples

>>> from landlab.utils.structured_grid import east_links
>>> east_links((3, 4))
array([[ 0,  1,  2, -1],
       [ 7,  8,  9, -1],
       [14, 15, 16, -1]])

Array of faces associated with links.

Returns an array that maps link ids to face ids. For inactive links, which do not have associated faces, set their ids to inactive_link_index. Use the actives keyword to specify an array that contains the ids of all active links in the grid. The default assumes that only the perimeter nodes are inactive.

Examples

>>> from landlab.utils.structured_grid import face_at_link
>>> faces = face_at_link((3, 4), inactive_link_index=-1)
>>> faces 
array([-1,  0,  1, -1, -1,  2,  3,
       -1, -1, -1, -1,  4,  5,  6, -1, -1, -1])
face_count(shape)[source]

Total number of faces.

Total number of faces in a structured grid with dimensions, shape. Each cell has four faces, and shared faces only count once.

Examples

>>> from landlab.utils.structured_grid import face_count
>>> face_count((3, 4))
7

Number of active links oriented horizontally.

Array of active links oriented horizontally.

Array of active links oriented horizontally.

Returns the link IDs of horizontal active links as an (R-2) x (C-1) array.

Parameters:

shape : 2-element tuple of int

number of rows and columns in grid

node_status (optional) : 1d numpy array (x number of nodes) of bool

False where node is a closed boundary, True otherwise

Returns:

2d numpy array of int

Link IDs of horizontal active links, not including horizontal links on top and bottom grid edges. If a horizontal link is inactive, its ID is given as -1.

Notes

Same as horizontal_active_link_ids() but returns “link IDs” for active links rather than “active link IDs” for active links. Designed to ultimately replace the original horizontal_active_link_ids().

Examples

>>> from landlab.utils.structured_grid import horizontal_active_link_ids2
>>> horizontal_active_link_ids2((3,4))
array([[7, 8, 9]])
>>> ns = np.ones(12, dtype=bool)
>>> ns[4] = False
>>> ns[7] = False
>>> horizontal_active_link_ids2((3,4), ns)
array([[-1,  8, -1]])

Array mask of horizontal links that are inactive.

Number of horizontal links.

Array of links oriented horizontally.

Number of links entering each node.

Array of links entering nodes.

Array of links entering nodes.

interior_cell_count(shape)[source]

Number of interior cells.

Number of interior cells. Since cells are only defined on interior nodes, this is the same as cell_count.

interior_iter(shape)[source]

Iterator for the interior nodes of a structured grid.

Examples

>>> import numpy as np
>>> from landlab.utils.structured_grid import interior_iter
>>> np.fromiter(interior_iter((4, 3)), dtype=np.int)
array([4, 7])
interior_node_count(shape)[source]

Number of interior nodes.

Return the count of the number of interior nodes of a structured grid of dimensions, shape.

>>> from landlab.utils.structured_grid import (node_count,
...                                            interior_node_count)
>>> node_count((2, 4))
8
>>> interior_node_count((2, 4))
0
>>> interior_node_count((1, 4))
0
>>> interior_node_count((3, 4))
2
interior_node_id_to_node_id(shape, core_node_ids)[source]

Map interior nodes to nodes.

Note

deprecated

Converts the id of an interior node ID (i.e., if just the interior nodes were numbered) to a node ID.

interior_nodes(shape)[source]

Array of interior nodes.

left_edge_node_ids(shape)[source]

Array of nodes on the left edge.

left_index_iter(shape)[source]

Iterator for the left boundary indices of a structured grid.

left_right_iter(shape, *args)[source]

Iterator for the left and right boundary indices of a structured grid.

This iterates over the indices in order rather than iterating all of the left boundary and then all of the right boundary.

Examples

>>> import numpy as np
>>> from landlab.utils.structured_grid 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])

Total number of links.

Total (active and inactive) number of links in a structured grid with dimensions, shape. This is the number of to-links and from-links, not the total of the two.

>>> from landlab.utils.structured_grid import link_count
>>> link_count((3,2))
7
linked_neighbor_node_ids(shape, closed_boundary_nodes, open_boundary_nodes=None, inactive=-1)[source]

Matrix of four neighbor nodes for each node.

neighbor_cell_array(shape, out_of_bounds=-1, contiguous=True)[source]

Array of neighbor cells.

Examples

>>> from landlab.utils.structured_grid import neighbor_cell_array
>>> neighbors = neighbor_cell_array((2, 3), out_of_bounds=-1)
>>> len(neighbors) == 0
True
>>> neighbors = neighbor_cell_array((3, 3), out_of_bounds=-1)
>>> neighbors
array([[-1, -1, -1, -1]])
>>> neighbors = neighbor_cell_array((5, 4), out_of_bounds=-1)
>>> neighbors 
array([[ 1,  2, -1, -1], [-1,  3,  0, -1],
       [ 3,  4, -1,  0], [-1,  5,  2,  1],
       [ 5, -1, -1,  2], [-1, -1,  4,  3]])
neighbor_node_array(shape, **kwds)[source]

Array of neighbor nodes.

Examples

>>> from landlab.utils.structured_grid import neighbor_node_array
>>> neighbors = neighbor_node_array((2, 3), inactive=-1)
>>> neighbors.T
array([[ 1,  3, -1, -1],
       [ 2,  4,  0, -1],
       [-1,  5,  1, -1],
       [ 4, -1, -1,  0],
       [ 5, -1,  3,  1],
       [-1, -1,  4,  2]])
neighbor_node_ids(shape, inactive=-1)[source]

Matrix of four neighbor nodes for each node.

node_at_cell(shape)[source]

Array of nodes at cells.

Indices of the nodes belonging to each cell.

Examples

>>> from landlab.utils.structured_grid import node_at_cell
>>> node_at_cell((4, 3))
array([4, 7])

Array of nodes at the end of links.

Array of nodes at the start of links.

node_coords(shape, *args)[source]

Get node x and y coordinates.

Get x, y coordinates for nodes in a structured grid with dimensions, shape. Use the optional argument spacing to give the spacing in each dimension, and origin the start of the coordinates in each dimension.

Parameters:

shape : tuple of int

Number of node rows and columns.

spacing : tuple, optional

Row and column spacing.

origin : tuple, optional

Coordinate of lower-left node.

Examples

>>> from landlab.utils.structured_grid import node_coords
>>> (cols, rows) = node_coords((3, 2))
>>> rows
array([ 0.,  0.,  1.,  1.,  2.,  2.])
>>> cols
array([ 0.,  1.,  0.,  1.,  0.,  1.])
node_count(shape)[source]

Total number of nodes.

The total number of nodes in a structured grid with dimensions given by the tuple, shape. Where shape is the number of node rows and node columns.

>>> from landlab.utils.structured_grid import node_count
>>> node_count((3, 4))
12
node_has_boundary_neighbor(neighbors, diagonals, out_of_bounds=-1)[source]

Array of booleans that indicate if a node has a boundary neighbor.

Note

DEJH thinks this method is broken since terminology update: it returns closed neighbors, not boundary neighbors.

node_has_boundary_neighbor_slow(neighbors, diagonals, out_of_bounds=-1)[source]

Array of booleans that indicate if a node has a boundary neighbor.

Note

deprecated

node_id_to_interior_node_id(shape, node_ids)[source]

Map nodes to interior nodes.

Note

deprecated

Converts a node ID to the id of an interior node ID (i.e., if just the interior nodes were numbered)

Array of nodes at each end of links.

node_index_with_halo(shape, halo_indices=-1)[source]

Array of links with a halo of no-data values.

Examples

>>> from landlab.utils.structured_grid import node_index_with_halo
>>> node_index_with_halo((2, 3), halo_indices=-1)
array([[-1, -1, -1, -1, -1],
       [-1,  0,  1,  2, -1],
       [-1,  3,  4,  5, -1],
       [-1, -1, -1, -1, -1]])
nodes_around_point(shape, coords, spacing=(1.0, 1.0))[source]

Array of nodes around a single point on a grid of non-unit spacing.

nodes_around_points(shape, coords, spacing=(1.0, 1.0), origin=(0.0, 0.0))[source]

Array of nodes around x, y points on a grid of non-unit spacing.

Returns the nodes around a point on a structured grid with row and column spacing, and origin.

Examples

>>> from landlab.utils.structured_grid import nodes_around_points
>>> x = np.array([.9, 1.])
>>> y = np.array([.1, 1.])
>>> nodes_around_points((3, 3), (y, x))
array([[0, 3, 4, 1],
       [4, 7, 8, 5]])
>>> nodes_around_points((3, 3), (2., 1.))
Traceback (most recent call last):
    ...
ValueError: invalid entry in coordinates array
nodes_around_points_on_unit_grid(shape, coords, mode='raise')[source]

Array of nodes around x, y points on a grid of unit spacing.

Returns the nodes around a point on a structured grid with unit spacing and zero origin.

Examples

>>> from landlab.utils.structured_grid import (
...     nodes_around_points_on_unit_grid)
>>> nodes_around_points_on_unit_grid((3, 3), (.1, .1))
array([0, 3, 4, 1])
>>> nodes_around_points_on_unit_grid((3, 3), (1., 1.))
array([4, 7, 8, 5])

Array of links pointing to the north.

Examples

>>> from landlab.utils.structured_grid import north_links
>>> north_links((3, 4))
array([[ 3,  4,  5,  6],
       [10, 11, 12, 13],
       [-1, -1, -1, -1]])

Number of links leaving each node.

Array of links leaving nodes.

Array of links leaving nodes.

perimeter_iter(shape)[source]

Iterator for perimeter nodes.

Iterates over all of the perimeter node indices of a structured grid in order.

Examples

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

Number of perimeter nodes.

Number of nodes that are on the perimeter of a structured grid with dimensions, shape, and thus boundary nodes.

Examples

>>> from landlab.utils.structured_grid import perimeter_node_count
>>> perimeter_node_count((3, 4))
10
perimeter_nodes(shape)[source]

Array of perimeter nodes.

An array of the indices of the perimeter nodes of a structured grid.

Examples

>>> from landlab.utils.structured_grid import perimeter_nodes
>>> perimeter_nodes((3, 4))
array([ 0,  1,  2,  3,  4,  7,  8,  9, 10, 11])
reshape_array(shape, array, flip_vertically=False, copy=False)[source]

Reshape a flat array.

Examples

>>> from landlab.utils.structured_grid import reshape_array
>>> x = np.arange(12.)
>>> y = reshape_array((3, 4), x)
>>> y.shape == (3, 4)
True
>>> y
array([[  0.,   1.,   2.,   3.],
       [  4.,   5.,   6.,   7.],
       [  8.,   9.,  10.,  11.]])
>>> y.flags['C_CONTIGUOUS']
True
>>> x[0] = -1
>>> y[0, 0]
-1.0
>>> x = np.arange(12.)
>>> y = reshape_array((3, 4), x, flip_vertically=True)
>>> y
array([[  8.,   9.,  10.,  11.],
       [  4.,   5.,   6.,   7.],
       [  0.,   1.,   2.,   3.]])
>>> y.flags['C_CONTIGUOUS']
False
>>> x[0] = -1
>>> y[-1, 0]
-1.0
right_edge_node_ids(shape)[source]

Array of nodes on the right edge.

right_index_iter(shape)[source]

Iterator for the right boundary indices of a structured grid.

Create a matrix of active links entering each node.

Return the IDs of the active links that enter each node of a grid. The shape of the returned array is (2, N) where N is the number of nodes in the grid. The first row contains the link ID entering the node from the bottom, and the second row the link entering the node from the left.

Use the return_count keyword to, in addition to the link IDs, return the number of active links attached to each grid node.

Use the node_status_array keyword to specify the status for each of the grid’s nodes. If not given, each of the perimeter nodes is assumed to be FIXED_VALUE_BOUNDARY.

Parameters:

shape : tuple

Shape of the structured grid

node_status : array_like, optional

Status of each node in the grid.

return_count : boolean, optional

If True, also return an array of active link counts per node.

Returns:

links : (2, N) ndarray

Active link IDs for each node.

count : ndarray

Number of active links per node.

Examples

Get the active link IDs for a grid of 3 nodes by 4 nodes. The first row list links entering nodes from the bottom, and the second links entering from the left.

>>> from landlab.utils.structured_grid import setup_active_inlink_matrix
>>> setup_active_inlink_matrix((3, 4), return_count=False)
array([[-1, -1, -1, -1, -1,  0,  1, -1, -1,  2,  3, -1],
       [-1, -1, -1, -1, -1,  4,  5,  6, -1, -1, -1, -1]])
>>> _, count = setup_active_inlink_matrix((3, 4))
>>> count
array([0, 0, 0, 0, 0, 2, 2, 1, 0, 1, 1, 0])

Create a matrix of active links entering each node.

Return the link IDs of the active links that enter each node of a grid. The shape of the returned array is (2, N) where N is the number of nodes in the grid. The first row contains the link ID entering the node from the bottom, and the second row the link entering the node from the left.

Use the return_count keyword to, in addition to the link IDs, return the number of active links attached to each grid node.

Use the node_status_array keyword to specify the status for each of the grid’s nodes. If not given, each of the perimeter nodes is assumed to be FIXED_VALUE_BOUNDARY.

Parameters:

shape : tuple

Shape of the structured grid

node_status : array_like, optional

Status of each node in the grid.

return_count : boolean, optional

If True, also return an array of active link counts per node.

Returns:

links : (2, N) ndarray

Active link IDs for each node.

count : ndarray

Number of active links per node.

Examples

Get the active link IDs for a grid of 3 nodes by 4 nodes. The first row lists links entering nodes from the bottom, and the second links entering from the left.

>>> from landlab.utils.structured_grid import setup_active_inlink_matrix2
>>> setup_active_inlink_matrix2((3, 4), return_count=False)
array([[-1, -1, -1, -1, -1,  4,  5, -1, -1, 11, 12, -1],
       [-1, -1, -1, -1, -1,  7,  8,  9, -1, -1, -1, -1]])
>>> _, count = setup_active_inlink_matrix2((3, 4))
>>> count
array([0, 0, 0, 0, 0, 2, 2, 1, 0, 1, 1, 0])

Create a matrix of active links leaving each node.

Create a matrix of active links leaving each node.

Return the link IDs of the active links that leave each node of a grid. The shape of the returned array is (2, N) where N is the number of nodes in the grid. The first row contains the link ID exiting the node to the top, and the second row the link exiting the node to the right.

Use the return_count keyword to, in addition to the link IDs, return the number of active links attached to each grid node.

Use the node_status_array keyword to specify the status for each of the grid’s nodes. If not given, each of the perimeter nodes is assumed to be FIXED_VALUE_BOUNDARY.

Parameters:

shape : tuple

Shape of the structured grid

node_status : array_like, optional

Status of each node in the grid.

return_count : boolean, optional

If True, also return an array of active link counts per node.

Returns:

links : (2, N) ndarray

Active link IDs for each node.

count : ndarray

Number of active links per node.

Examples

Get the active link IDs for a grid of 3 nodes by 4 nodes. The first row lists links entering nodes from the bottom, and the second links entering from the left.

>>> from landlab.utils.structured_grid import setup_active_outlink_matrix2
>>> setup_active_outlink_matrix2((3, 4), return_count=False)
array([[-1,  4,  5, -1, -1, 11, 12, -1, -1, -1, -1, -1],
       [-1, -1, -1, -1,  7,  8,  9, -1, -1, -1, -1, -1]])
>>> _, count = setup_active_outlink_matrix2((3, 4))
>>> count
array([0, 1, 1, 0, 1, 2, 2, 0, 0, 0, 0, 0])

Create a matrix of links entering each node.

Create a matrix of links leaving each node.

Array of links pointing to the the south.

Examples

>>> from landlab.utils.structured_grid import south_links
>>> south_links((3, 4))
array([[-1, -1, -1, -1],
       [ 3,  4,  5,  6],
       [10, 11, 12, 13]])
status_at_node(shape, boundary_status=1)[source]

Array of the statuses of nodes.

The statuses of the nodes in a structured grid with dimensions, shape. Use the boundary_status keyword to specify the status of the top, bottom, left and right boundary nodes.

top_edge_node_ids(shape)[source]

Array of nodes on the top edge.

top_index_iter(shape)[source]

Iterator for the top boundary indices of a structured grid.

Number of active links oriented vertically.

Array of active links oriented vertically.

Array of active links oriented vertically.

Returns the link IDs of vertical active links as an (R-1) x (C-2) array.

Parameters:

shape : 2-element tuple of int

number of rows and columns in grid

node_status (optional) : 1d numpy array (x number of nodes) of bool

False where node is a closed boundary, True otherwise

Returns:

2d numpy array of int

Link IDs of vertical active links, not including vertical links on the left and right grid edges. If a vertical link is inactive, its ID is given as -1.

Notes

Same as vertical_active_link_ids() but returns “link IDs” for active links rather than “active link IDs” for active links. Designed to ultimately replace the original vertical_active_link_ids().

Examples

>>> from landlab.utils.structured_grid import vertical_active_link_ids2
>>> vertical_active_link_ids2((3,4))
array([[ 4,  5],
       [11, 12]])
>>> ns = np.ones(12, dtype=bool)
>>> ns[1] = False
>>> ns[10] = False
>>> vertical_active_link_ids2((3,4), ns)
array([[-1,  5],
       [11, -1]])

Array mask of vertical links that are inactive.

Creates and returns a boolean 2D array dimensioned as the number of vertical links in the grid, not including the left and right boundaries.

Parameters:

shape : 2-element tuple of ints

Number of rows and columns in the grid

node_status : numpy array of bool (x # of nodes)

False where node is a closed boundary; True elsewhere

Returns:

(NR-1,NC-2) array of bool (NR=# of rows, NC=# of columns)

Flags indicating whether the corresponding vertical link is inactive

Examples

>>> import numpy as np
>>> from landlab.utils.structured_grid import vertical_inactive_link_mask
>>> ns = np.ones(12, dtype=bool)  # case of no closed boundary nodes
>>> vertical_inactive_link_mask((3,4), ns)
array([[False, False],
       [False, False]], dtype=bool)
>>> ns[2] = False    # node 2 is a closed boundary
>>> vertical_inactive_link_mask((3,4), ns)
array([[False,  True],
       [False, False]], dtype=bool)
>>> ns[9] = False    # node 9 is also a closed boundary
>>> vertical_inactive_link_mask((3,4), ns)
array([[False,  True],
       [ True, False]], dtype=bool)

Number of vertical links.

Array of links oriented vertically.

Array of links pointing to the west.

Examples

>>> from landlab.utils.structured_grid import west_links
>>> west_links((3, 4))
array([[-1,  0,  1,  2],
       [-1,  7,  8,  9],
       [-1, 14, 15, 16]])

Module contents