landlab.components.hand_calculator.hand_calculator

Landlab component to calculate height above nearest drainage.

@author: D Litwin

class HeightAboveDrainageCalculator[source]

Bases: Component

Calculate the elevation difference between each node and its nearest drainage node in a DEM.

This component implements the method described by Nobre et al (2011). A single direction flow director (D8 or steepest descent) must be run prior to HeightAboveDrainageCalculator to supply the flow directions. This component does not fill depressions in a DEM, but rather it treats them as drainage nodes. For best results, please run one of the available pit filling components prior to HeightAboveDrainageCalculator.

Examples

>>> import numpy as np
>>> from numpy.testing import assert_equal
>>> from landlab import RasterModelGrid
>>> from landlab.components import HeightAboveDrainageCalculator, FlowAccumulator
>>> mg = RasterModelGrid((4, 5))
>>> z = mg.add_zeros("topographic__elevation", at="node")
>>> mg.set_status_at_node_on_edges(
...     right=mg.BC_NODE_IS_CLOSED,
...     bottom=mg.BC_NODE_IS_FIXED_VALUE,
...     left=mg.BC_NODE_IS_CLOSED,
...     top=mg.BC_NODE_IS_CLOSED,
... )
>>> elev = np.array(
...     [[2, 1, 0, 1, 2], [3, 2, 1, 2, 3], [4, 3, 2, 3, 4], [5, 4, 4, 4, 5]]
... )
>>> z[:] = elev.reshape(len(z))
>>> elev
array([[2, 1, 0, 1, 2],
       [3, 2, 1, 2, 3],
       [4, 3, 2, 3, 4],
       [5, 4, 4, 4, 5]])
>>> fa = FlowAccumulator(mg, flow_director="D8")
>>> fa.run_one_step()
>>> channel__mask = mg.zeros(at="node")
>>> channel__mask[[2, 7]] = 1
>>> channel__mask.reshape(elev.shape)
array([[0., 0., 1., 0., 0.],
       [0., 0., 1., 0., 0.],
       [0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0.]])
>>> hd = HeightAboveDrainageCalculator(mg, channel_mask=channel__mask)
>>> hd.run_one_step()
>>> mg.at_node["height_above_drainage__elevation"].reshape(elev.shape)
array([[2., 0., 0., 0., 0.],
       [3., 2., 0., 2., 3.],
       [4., 2., 1., 2., 4.],
       [5., 4., 4., 4., 5.]])

References

Required Software Citation(s) Specific to this Component

None Listed

Additional References

Nobre, A. D., Cuartas, L. A., Hodnett, M., Rennó, C. D., Rodrigues, G., Silveira, A., et al. (2011). Height Above the Nearest Drainage – a hydrologically relevant new terrain model. Journal of Hydrology, 404(1), 13–29. https://doi.org/10.1016/j.jhydrol.2011.03.051

Parameters:
  • grid (ModelGrid) – Landlab ModelGrid object

  • channel_mask (field name, array of uint8) – Logical map of nodes where drainage is present

__init__(grid, channel_mask='channel__mask')[source]
Parameters:
  • grid (ModelGrid) – Landlab ModelGrid object

  • channel_mask (field name, array of uint8) – Logical map of nodes where drainage is present

static __new__(cls, *args, **kwds)
property channel_mask
cite_as = ''
property coords

Return the coordinates of nodes on grid attached to the component.

property current_time

Current time.

Some components may keep track of the current time. In this case, the current_time attribute is incremented. Otherwise it is set to None.

Return type:

current_time

definitions = (('channel__mask', 'Logical map of at which grid nodes channels are present'), ('flow__receiver_node', 'Node array of receivers (node that receives flow from current node)'), ('flow__upstream_node_order', 'Node array containing downstream-to-upstream ordered list of node IDs'), ('height_above_drainage__elevation', 'Elevation above the nearest channel node'), ('topographic__elevation', 'Land surface topographic elevation'))
classmethod from_path(grid, path)

Create a component from an input file.

Parameters:
  • grid (ModelGrid) – A landlab grid.

  • path (str or file_like) – Path to a parameter file, contents of a parameter file, or a file-like object.

Returns:

A newly-created component.

Return type:

Component

property grid

Return the grid attached to the component.

initialize_optional_output_fields()

Create fields for a component based on its optional field outputs, if declared in _optional_var_names.

This method will create new fields (without overwrite) for any fields output by the component as optional. New fields are initialized to zero. New fields are created as arrays of floats, unless the component also contains the specifying property _var_type.

initialize_output_fields(values_per_element=None)

Create fields for a component based on its input and output var names.

This method will create new fields (without overwrite) for any fields output by, but not supplied to, the component. New fields are initialized to zero. Ignores optional fields. New fields are created as arrays of floats, unless the component specifies the variable type.

Parameters:

values_per_element (int (optional)) – On occasion, it is necessary to create a field that is of size (n_grid_elements, values_per_element) instead of the default size (n_grid_elements,). Use this keyword argument to acomplish this task.

input_var_names = ('flow__receiver_node', 'flow__upstream_node_order', 'topographic__elevation')
name = 'HeightAboveDrainageCalculator'
optional_var_names = ('channel__mask',)
output_var_names = ('height_above_drainage__elevation',)
run_one_step()[source]
property shape

Return the grid shape attached to the component, if defined.

unit_agnostic = True
units = (('channel__mask', '-'), ('flow__receiver_node', '-'), ('flow__upstream_node_order', '-'), ('height_above_drainage__elevation', 'm'), ('topographic__elevation', 'm'))
classmethod var_definition(name)

Get a description of a particular field.

Parameters:

name (str) – A field name.

Returns:

A description of each field.

Return type:

tuple of (name, *description*)

classmethod var_help(name)

Print a help message for a particular field.

Parameters:

name (str) – A field name.

classmethod var_loc(name)

Location where a particular variable is defined.

Parameters:

name (str) – A field name.

Returns:

The location (‘node’, ‘link’, etc.) where a variable is defined.

Return type:

str

var_mapping = (('channel__mask', 'node'), ('flow__receiver_node', 'node'), ('flow__upstream_node_order', 'node'), ('height_above_drainage__elevation', 'node'), ('topographic__elevation', 'node'))
classmethod var_type(name)

Returns the dtype of a field (float, int, bool, str…).

Parameters:

name (str) – A field name.

Returns:

The dtype of the field.

Return type:

dtype

classmethod var_units(name)

Get the units of a particular field.

Parameters:

name (str) – A field name.

Returns:

Units for the given field.

Return type:

str