Codebase¶
Notes:
ArcGIS is not required to use cascade.py - it is a standard Python library.
All code has been checked using pylint and conforms to the PEP8 Python standards.
There are unit tests that ensure correct output.
Orderer¶
- class cascade.orderer.Orderer(code_field: str = 'SEG_CD')[source]¶
- assign_order(net: DiGraph | MultiDiGraph, selected_keys: list[str | int] | None = None) dict [source]¶
The new braided version can also easily deal with multiple drainage outlets. To address such cases, the procedure must be executed separately for each pour point (outlet) present in the network. When the proce- dure first reaches the ‘split node,’ where the network splits into multiple drainage paths, it will not follow the other paths, since they do not flow into that split node, but rather out of it. Then, in successive calls for other outlets, the procedure can use already deter- mined stream orders of the split node’s upstream arcs instead of repeating that upstream part’s traversal. Of course, all external dictionaries should be shared among the calls to maintain consistency among them
- get_strahler_order(up_orders: list[tuple[int, int]]) tuple[int, int, int] [source]¶
up_orders is a list of tuples containing (order, origin_node)
e.g. [(2, 3), (1, 6)]
Returns:
max_order_origin - the id of the node max_order_count - the number of tuples with the maximum order max_order - the maximum order in the list
- make_dicts(net: DiGraph | MultiDiGraph, code_field: str | None = None) tuple[dict, dict, dict] [source]¶
For braided networks the preprocessing procedure should create an InflowingArcsPerNode dictionary (instead of an ArcsPerNode dictionary) that would contain for every node only those arcs that flow into that same node. It should also create a FromNodesPerArc dictionary (instead of a NodesPerArc dictionary) to contain the from- nodes of each arc.
- order_network(arc_id: int, from_nodes_per_arc: dict, inflowing_arcs_per_node: dict, originating_node: dict, count: int = 0) tuple[int, int] [source]¶
Based on create_file.py (BSD license) See PyTOPKAPI Documentation for more details
Calculate the Strahler stream order
This function recursively computes the Strahler stream order using the algorithm described by Gleyzer et al. (2004). The sequence of stream orders for the starting arc and each upstream arc is returned in the dictionary stream_orders.
This also introduces the concept of river segments - collections of arcs of the same order
originating_node is used to keep track of the node at the top of the path
segments - an empty Segments dictionary, global to the procedure, is assumed to be created before execution of the procedure. This dictionary will hold the actual segment ID for each network arc.