landlab.components.hack_calculator.hack_calculator

Calculate Hack parameters.

class HackCalculator[source]

Bases: Component

This component calculates Hack’s law parameters for drainage basins.

Hacks law is given as

..:math:

L = C * A**h

Where \(L\) is the distance to the drainage divide along the channel, \(A\) is the drainage area, and \(C`and :math:`h\) are parameters.

The HackCalculator uses a ChannelProfiler to determine the nodes on which to calculate the parameter fit.

Examples

>>> import pandas as pd
>>> pd.set_option("display.max_columns", None)
>>> import numpy as np
>>> from landlab import RasterModelGrid
>>> from landlab.components import FlowAccumulator, FastscapeEroder, HackCalculator
>>> np.random.seed(42)
>>> mg = RasterModelGrid((50, 100), xy_spacing=100)
>>> z = mg.add_zeros("node", "topographic__elevation")
>>> z[mg.core_nodes] += np.random.randn(mg.core_nodes.size)
>>> fa = FlowAccumulator(mg)
>>> fs = FastscapeEroder(mg, K_sp=0.001)
>>> for i in range(100):
...     fa.run_one_step()
...     fs.run_one_step(1000)
...     z[mg.core_nodes] += 0.01 * 1000
...
>>> hc = HackCalculator(mg)
>>> hc.calculate_hack_parameters()
>>> largest_outlet = mg.boundary_nodes[
...     np.argsort(mg.at_node["drainage_area"][mg.boundary_nodes])[-1:]
... ][0]
>>> largest_outlet
4978
>>> hc.hack_coefficient_dataframe.loc[largest_outlet, "A_max"]
2830000.0
>>> hc.hack_coefficient_dataframe.round(2)
A_max     C          h     basin_outlet_id
4978      2830000.0  0.31  0.62
>>> hc = HackCalculator(
...     mg, number_of_watersheds=3, main_channel_only=False, save_full_df=True
... )
>>> hc.calculate_hack_parameters()
>>> hc.hack_coefficient_dataframe.round(2)
A_max     C          h     basin_outlet_id
39        2170000.0  0.13  0.69
4929      2350000.0  0.13  0.68
4978      2830000.0  0.23  0.64
>>> hc.full_hack_dataframe.head().round(2)
basin_outlet_id    A     L_obs      L_est   node_id
39                 39.0  2170000.0  3200.0  2903.43
139                39.0  2170000.0  3100.0  2903.43
238                39.0    10000.0     0.0    71.61
239                39.0  2160000.0  3000.0  2894.22
240                39.0    10000.0     0.0    71.61

References

Required Software Citation(s) Specific to this Component

None Listed

Additional References

Hack, J. T. Studies of longitudinal stream profiles in Virginia and Maryland (Vol. 294). U.S. Geological Survey Professional Paper 294-B (1957). https://doi.org/10.3133/pp294B

Parameters:
  • grid (Landlab Model Grid instance, required)

  • save_full_df (bool) – Flag indicating whether to create the full_hack_dataframe.

  • **kwds – Values to pass to the ChannelProfiler.

__init__(grid, save_full_df=False, **kwds)[source]
Parameters:
  • grid (Landlab Model Grid instance, required)

  • save_full_df (bool) – Flag indicating whether to create the full_hack_dataframe.

  • **kwds – Values to pass to the ChannelProfiler.

static __new__(cls, *args, **kwds)
calculate_hack_parameters()[source]

Calculate Hack parameters for desired watersheds.

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 = (('distance_to_divide', 'Distance from drainage divide.'), ('drainage_area', "Upstream accumulated surface area contributing to the node's discharge"), ('flow__link_to_receiver_node', 'ID of link downstream of each node, which carries the discharge'), ('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'), ('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 full_hack_dataframe

Full Hack calculation dataframe.

This dataframe is optionally created and stored on the component when the keyword argument full_hack_dataframe=True is passed to the component init.

It is pandas dataframe with a row for every model grid cell used to estimate the Hack parameters. It has the following index and columns.

  • Index
    • node_id*: The node ID of the model grid cell.

  • Columns
    • basin_outlet_id: The node IDs of watershed outlet

    • A: The drainage are of the model grid cell.

    • L_obs: The observed distance to the divide.

    • L_est: The predicted distance to divide based on the Hack coefficient fit.

property grid

Return the grid attached to the component.

property hack_coefficient_dataframe

Hack coefficient dataframe.

This dataframe is created and stored on the component.

It is a pandas dataframe with one row for each basin for which Hack parameters are calculated. Thus, there are as many rows as the number of watersheds identified by the ChannelProfiler.

The dataframe has the following index and columns.

  • Index
    • basin_outlet_id: The node ID of the watershed outlet where each set of Hack parameters was estimated.

  • Columns
    • A_max: The drainage area of the watershed outlet.

    • C: The Hack coefficient as defined in the equations above.

    • h: The Hack exponent as defined in the equations above.

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 = ('drainage_area', 'flow__link_to_receiver_node', 'flow__receiver_node', 'flow__upstream_node_order', 'topographic__elevation')
name = 'HackCalculator'
optional_var_names = ()
output_var_names = ('distance_to_divide',)
property shape

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

unit_agnostic = True
units = (('distance_to_divide', 'm'), ('drainage_area', 'm**2'), ('flow__link_to_receiver_node', '-'), ('flow__receiver_node', '-'), ('flow__upstream_node_order', '-'), ('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 = (('distance_to_divide', 'node'), ('drainage_area', 'node'), ('flow__link_to_receiver_node', 'node'), ('flow__receiver_node', 'node'), ('flow__upstream_node_order', '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