Tree

class rameau.core.Tree(watersheds, connection=None)[source]

Watershed connection tree.

Parameters:
  • watersheds (list or dict) – If provided as a list, identifiers of each Watershed are deduced from their positions in the list, starting from 1. If provided as a dictionary, keys correspond to the user-defined identifiers. Identifiers needs to be consistent with the ones provided for the connection keyword.

  • connection (dict, optional) – Dictionary of key/value integer pairs representing a watershed identifier starting from 1. Dictionary elements describe the connection between upstream watersheds and downstream watersheds. A 0 downstream value means that the corresponding upstream watershed is the watershed outlet.

Returns:

Tree

Examples

Creation of three watersheds with default dummy parameters:

>>> b1 = rm.Watershed()
>>> b2 = rm.Watershed()
>>> b3 = rm.Watershed()

Creation of a watershed connection tree. Here b1 is connected to b3, b2 to b3, and b3 is the watershed outlet.

>>> t = rm.Tree(watersheds=[b1, b2, b3], connection={1: 3, 2: 3, 3: 0})
>>> for w in t.watersheds:
...     print(f"Watershed {w.id}: {w.strahler_order}")
Watershed 1: 1
Watershed 2: 1
Watershed 3: 2

The watersheds keyword argument can be a dictionary with user-defined identifiers.

>>> t = rm.Tree(
...     watersheds={9: b1, 1: b2, 2: b3}, connection={9: 2, 1: 2, 2: 0}
... )
>>> for w in t.watersheds:
...     print(f"Watershed {w.id}: {w.strahler_order}")
Watershed 1: 1
Watershed 2: 2
Watershed 9: 1

Methods

from_csv(path, watersheds)

Import connections between upstream and downstream watersheds from a CSV file.

to_csv(path)

Export a watershed connection dictionary to a CSV file.

Attributes

connection

Dictionary of key/value integer pairs representing a watershed identifier starting from 1.

watersheds

List of Watershed.