landlab.components.flow_director.flow_director_d8¶
flow_director_d8.py: provides the component FlowDirectorsD8.
This components finds the steepest single-path steepest descent flow directions and considers diagonal links between nodes on a raster grid. It is not implemented for irregular grids. For a method that works for irregular grids and does not consider diagonal links for rasters, use FlowDirectorSteepest instead.
- class FlowDirectorD8[source]¶
Bases:
_FlowDirectorToOne
Single-path (steepest direction) flow direction with diagonals on rasters.
Single-path (steepest direction) flow direction finding on raster grids by the D8 method. This method considers flow on all eight links such that flow is possible on orthogonal and on diagonal links.
The method that considers only orthogonal links (D4 method) for raster grids is FlowDirectorSteepest.
This method is not implemented for Voroni grids, use FlowDirectorSteepest instead.
Stores as ModelGrid fields:
Node array of receivers (nodes that receive flow), or ITS OWN ID if there is no receiver: ‘flow__receiver_node’
Node array of steepest downhill slopes: ‘topographic__steepest_slope’
Node array containing ID of link that leads from each node to its receiver, or BAD_INDEX_VALUE if no link: ‘flow__link_to_receiver_node’
Boolean node array of all local lows: ‘flow__sink_flag’
The primary method of this class is
run_one_step
.Examples
>>> import numpy as np >>> from landlab import RasterModelGrid >>> from landlab.components import FlowDirectorD8 >>> mg = RasterModelGrid((3, 3), xy_spacing=(1, 1)) >>> mg.set_closed_boundaries_at_grid_edges(True, True, True, False) >>> _ = mg.add_field( ... "topographic__elevation", ... mg.node_x + mg.node_y, ... at="node", ... ) >>> fd = FlowDirectorD8(mg, "topographic__elevation") >>> fd.surface_values array([0., 1., 2., 1., 2., 3., 2., 3., 4.]) >>> fd.run_one_step() >>> mg.at_node["flow__receiver_node"] array([0, 1, 2, 3, 0, 5, 6, 7, 8]) >>> mg.at_node["topographic__steepest_slope"] array([0. , 0. , 0. , 0. , 1.41421356, 0. , 0. , 0. , 0. ]) >>> mg.at_node["flow__link_to_receiver_node"] array([-1, -1, -1, -1, 12, -1, -1, -1, -1]) >>> mg.at_node["flow__sink_flag"].astype(int) array([1, 1, 1, 1, 0, 1, 1, 1, 1]) >>> mg_2 = RasterModelGrid((5, 4), xy_spacing=(1, 1)) >>> topographic__elevation = [ ... [0.0, 0.0, 0.0, 0.0], ... [0.0, 21.0, 10.0, 0.0], ... [0.0, 31.0, 20.0, 0.0], ... [0.0, 32.0, 30.0, 0.0], ... [0.0, 0.0, 0.0, 0.0], ... ] >>> _ = mg_2.add_field( ... "topographic__elevation", ... topographic__elevation, ... at="node", ... ) >>> mg_2.set_closed_boundaries_at_grid_edges(True, True, True, False) >>> fd_2 = FlowDirectorD8(mg_2) >>> fd_2.run_one_step() >>> mg_2.at_node["flow__receiver_node"].reshape(mg_2.shape) array([[ 0, 1, 2, 3], [ 4, 1, 2, 7], [ 8, 6, 6, 11], [12, 10, 10, 15], [16, 17, 18, 19]])
The flow directors also have the ability to return the flow receiver nodes
>>> receiver = fd.direct_flow() >>> receiver array([0, 1, 2, 3, 0, 5, 6, 7, 8])
References
Required Software Citation(s) Specific to this Component
None Listed
Additional References
O’Callaghan, J., Mark, D. (1984). The extraction of drainage networks from digital elevation data. Computer Vision, Graphics, and Image Processing 28(3), 323 - 344. https://dx.doi.org/10.1016/s0734-189x(84)80011-0
- Parameters:
grid (ModelGrid) – A grid of type RasterModelGrid.
surface (field name at node or array of length node, optional) – The surface to direct flow across, default is field at node: topographic__elevation,.
- __init__(grid, surface='topographic__elevation')[source]¶
- Parameters:
grid (ModelGrid) – A grid of type RasterModelGrid.
surface (field name at node or array of length node, optional) – The surface to direct flow across, default is field at node: topographic__elevation,.
- static __new__(cls, *args, **kwds)¶
- 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 = (('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__sink_flag', 'Boolean array, True at local lows'), ('topographic__elevation', 'Land surface topographic elevation'), ('topographic__steepest_slope', 'The steepest *downhill* slope'))¶
- direct_flow()[source]¶
Find flow directions, save to the model grid, and return receivers.
direct_flow() checks for updated boundary conditions, calculates slopes on links, finds baselevel nodes based on the status at node, calculates flow directions, saves results to the grid, and returns a at-node array of receiver nodes. This array is stored in the grid at: grid[‘node’][‘flow__receiver_node’]
an alternative to direct_flow() is run_one_step() which does the same things but also returns a at-node array of receiver nodes. This array is stored in the grid at: grid[‘node’][‘flow__receiver_node’]
- classmethod from_path(grid, path)¶
Create a component from an input file.
- 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 = ()¶
- property link_to_flow_receiving_node¶
Return the link id along the link transporting flow.
- property links_to_receiver¶
ID of link downstream of each node, which carries the discharge.
- name = 'FlowDirectorD8'¶
- property node_receiving_flow¶
Return the node id of the node receiving flow.
Examples
>>> from landlab import RasterModelGrid >>> from landlab.components import FlowDirectorSteepest >>> mg = RasterModelGrid((3, 3)) >>> mg.set_closed_boundaries_at_grid_edges(True, True, True, False) >>> _ = mg.add_field( ... "topographic__elevation", ... mg.node_x + mg.node_y, ... at="node", ... ) >>> fd = FlowDirectorSteepest(mg, "topographic__elevation") >>> fd.run_one_step() >>> fd.node_receiving_flow array([0, 1, 2, 3, 1, 5, 6, 7, 8])
- property node_steepest_slope¶
Return the steepest link slope at a node.
- optional_var_names = ('topographic__elevation',)¶
- output_var_names = ('flow__link_to_receiver_node', 'flow__receiver_node', 'flow__sink_flag', 'topographic__steepest_slope')¶
- run_one_step()[source]¶
Find flow directions and save to the model grid.
run_one_step() checks for updated boundary conditions, calculates slopes on links, finds baselevel nodes based on the status at node, calculates flow directions, and saves results to the grid.
an alternative to direct_flow() is direct_flow() which does the same things but also returns the receiver nodes not return values.
- property shape¶
Return the grid shape attached to the component, if defined.
- property sink_flag¶
Return the array with sink flags.
- property surface_values¶
Values of the surface over which flow is directed.
- unit_agnostic = True¶
- units = (('flow__link_to_receiver_node', '-'), ('flow__receiver_node', '-'), ('flow__sink_flag', '-'), ('topographic__elevation', 'm'), ('topographic__steepest_slope', '-'))¶
- updated_boundary_conditions()[source]¶
Method to update FlowDirectorD8 when boundary conditions change.
Call this if boundary conditions on the grid are updated after the component is instantiated.
- 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.
- var_mapping = (('flow__link_to_receiver_node', 'node'), ('flow__receiver_node', 'node'), ('flow__sink_flag', 'node'), ('topographic__elevation', 'node'), ('topographic__steepest_slope', 'node'))¶