Network 2: adding a bifurcation

This simple network contains confluences and a single bifurcations.

[1]:
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
[2]:
from context import RiverNetwork
from RiverNetwork import RiverNetwork

Loading network structure

An extra file containing wave shapes is loaded as well. This file makes it possible to select arbitrary wave shapes as input flows.

[3]:
structure1 = RiverNetwork('../data/network-structure-2.xlsx',wave_shapes_location='../data/wave_shapes.xls')
[4]:
structure1.draw()
/home/docs/checkouts/readthedocs.org/user_builds/rna/envs/latest/lib/python3.7/site-packages/networkx/drawing/nx_pylab.py:579: MatplotlibDeprecationWarning:
The iterable function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use np.iterable instead.
  if not cb.iterable(width):
/home/docs/checkouts/readthedocs.org/user_builds/rna/envs/latest/lib/python3.7/site-packages/networkx/drawing/nx_pylab.py:676: MatplotlibDeprecationWarning:
The iterable function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use np.iterable instead.
  if cb.iterable(node_size):  # many node sizes
_images/B-network-structure-2_7_1.svg
[5]:
structure1.draw_base_loads(figsize=(7,4))
_images/B-network-structure-2_8_0.svg

Determining calculation order

The procedure for determining calculation order with multiple sinks is slight different. In that case a virtual sink is added to the system and all other sinks are connected to this node. Then a the same procedure is repeated: reversed BFS starting at this virtual sink. The resulting list is reversed and the result is a calculation order that guarantees that always all upstream flows are already calculated.

Calculation order

Example of the calculation order determining. In the left graph a temporary node and edges are added in red. From this node the reversed breadth-first search algorithm finds edges in a certain order. The order is indicated with numbers next to the edges. In the right graph the order of these edges is reversed and the temporary edges and node are removed. The order now corresponds to the calculation order that guarantees that all upstream parts are calculated before traversing downstream. This can be seen best at node A.3: all upstream edges are traversed before going downstream.

Experiment 1

[6]:
structure1.set_constant_flow('S.1',31)
structure1.set_wave('S.2',shape_number=5,strength=5)
structure1.set_wave('S.3',shape_number=90,strength=5)
structure1.set_constant_flow('S.4',31)
structure1.draw_Qin(only_sources=True,figsize=(7,4))
[6]:
(<Figure size 672x384 with 1 Axes>,
 <matplotlib.axes._subplots.AxesSubplot at 0x7fa974633a20>)
_images/B-network-structure-2_14_1.svg
[7]:
structure1.calc_flow_propagation(30)
structure1.draw_Qin(figsize=(7,5))
[7]:
(<Figure size 672x480 with 1 Axes>,
 <matplotlib.axes._subplots.AxesSubplot at 0x7fa97468d4a8>)
_images/B-network-structure-2_15_1.svg

Warning

Coloring should change to improve readability. E.g. cluster nodes and give similar colors.

Experiment 2

Now it is possible to add any other extra inflow. In the following experiment a peak flow is added to S.1.

[8]:
shape = np.zeros(30)
shape[4] = 1
shape[5] = 3
shape[6] = 10
shape[7] = 3
shape[8] = 1
structure1.set_shape('S.1',30,shape)
structure1.set_wave('S.2',shape_number=5,strength=5)
structure1.set_wave('S.3',shape_number=90,strength=5)
structure1.set_constant_flow('S.4',30)
structure1.draw_Qin(only_sources=True,figsize=(7,4))
[8]:
(<Figure size 672x384 with 1 Axes>,
 <matplotlib.axes._subplots.AxesSubplot at 0x7fa97467cdd8>)
_images/B-network-structure-2_19_1.svg
[9]:
structure1.calc_flow_propagation(30)
structure1.draw_Qin(figsize=(7,5))
[9]:
(<Figure size 672x480 with 1 Axes>,
 <matplotlib.axes._subplots.AxesSubplot at 0x7fa974768b70>)
_images/B-network-structure-2_20_1.svg