Single Confluence

[1]:
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
[2]:
from context import RiverNetwork
from RiverNetwork import RiverNetwork
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-34661278ac7e> in <module>
----> 1 from context import RiverNetwork
      2 from RiverNetwork import RiverNetwork

~/checkouts/readthedocs.org/user_builds/rna/checkouts/stable/docs/context.py in <module>
      5 sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
      6
----> 7 import RiverNetwork
      8 import fit_muskingum

ModuleNotFoundError: No module named 'RiverNetwork'

Loading network structure

[3]:
structure1 = RiverNetwork('../data/single-confluence.xlsx')
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-98aede9ba8eb> in <module>
----> 1 structure1 = RiverNetwork('../data/single-confluence.xlsx')

NameError: name 'RiverNetwork' is not defined
[4]:
structure1.draw(figsize=(4,4))
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-152852ac211e> in <module>
----> 1 structure1.draw(figsize=(4,4))

NameError: name 'structure1' is not defined

Here we see the network structure as defined with its nodes and edges. Each edge shows its corresponding \(k\) and \(x\). The incoming reaches have an \(x\) of 0.5 such that only a delay occurs and no attenuation. The numbers next to the nodes show the base loads, which is a static flow based on a long term average or can be an initial value. These base loads can also be plotted:

[5]:
structure1.draw_base_loads(figsize=(7,2.5))
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-5-86d24af1fd1f> in <module>
----> 1 structure1.draw_base_loads(figsize=(7,2.5))

NameError: name 'structure1' is not defined

Setting the inflows

We load a basic waveform from an excel file. Then this wave is translated to create a second waveform.

[6]:
I = pd.read_excel('../data/example-inflow-karahan-adjusted.xlsx').Inflow
t = pd.read_excel('../data/example-inflow-karahan-adjusted.xlsx').Time
I2 = I*0.4
I2 = np.append(I2[28:37],I2[0:28])
inflow = pd.DataFrame({'Q1':I,'Q2':I2},index=t)
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-6-d0fd3c62ef03> in <module>
----> 1 I = pd.read_excel('../data/example-inflow-karahan-adjusted.xlsx').Inflow
      2 t = pd.read_excel('../data/example-inflow-karahan-adjusted.xlsx').Time
      3 I2 = I*0.4
      4 I2 = np.append(I2[28:37],I2[0:28])
      5 inflow = pd.DataFrame({'Q1':I,'Q2':I2},index=t)

~/checkouts/readthedocs.org/user_builds/rna/envs/stable/lib/python3.7/site-packages/pandas/util/_decorators.py in wrapper(*args, **kwargs)
    206                 else:
    207                     kwargs[new_arg_name] = new_arg_value
--> 208             return func(*args, **kwargs)
    209
    210         return wrapper

~/checkouts/readthedocs.org/user_builds/rna/envs/stable/lib/python3.7/site-packages/pandas/io/excel/_base.py in read_excel(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, verbose, parse_dates, date_parser, thousands, comment, skip_footer, skipfooter, convert_float, mangle_dupe_cols, **kwds)
    308
    309     if not isinstance(io, ExcelFile):
--> 310         io = ExcelFile(io, engine=engine)
    311     elif engine and engine != io.engine:
    312         raise ValueError(

~/checkouts/readthedocs.org/user_builds/rna/envs/stable/lib/python3.7/site-packages/pandas/io/excel/_base.py in __init__(self, io, engine)
    817         self._io = _stringify_path(io)
    818
--> 819         self._reader = self._engines[engine](self._io)
    820
    821     def __fspath__(self):

~/checkouts/readthedocs.org/user_builds/rna/envs/stable/lib/python3.7/site-packages/pandas/io/excel/_xlrd.py in __init__(self, filepath_or_buffer)
     19         err_msg = "Install xlrd >= 1.0.0 for Excel support"
     20         import_optional_dependency("xlrd", extra=err_msg)
---> 21         super().__init__(filepath_or_buffer)
     22
     23     @property

~/checkouts/readthedocs.org/user_builds/rna/envs/stable/lib/python3.7/site-packages/pandas/io/excel/_base.py in __init__(self, filepath_or_buffer)
    357             self.book = self.load_workbook(filepath_or_buffer)
    358         elif isinstance(filepath_or_buffer, str):
--> 359             self.book = self.load_workbook(filepath_or_buffer)
    360         else:
    361             raise ValueError(

~/checkouts/readthedocs.org/user_builds/rna/envs/stable/lib/python3.7/site-packages/pandas/io/excel/_xlrd.py in load_workbook(self, filepath_or_buffer)
     34             return open_workbook(file_contents=data)
     35         else:
---> 36             return open_workbook(filepath_or_buffer)
     37
     38     @property

~/checkouts/readthedocs.org/user_builds/rna/envs/stable/lib/python3.7/site-packages/xlrd/__init__.py in open_workbook(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows)
    109     else:
    110         filename = os.path.expanduser(filename)
--> 111         with open(filename, "rb") as f:
    112             peek = f.read(peeksz)
    113     if peek == b"PK\x03\x04": # a ZIP file

FileNotFoundError: [Errno 2] No such file or directory: '../data/example-inflow-karahan-adjusted.xlsx'

The inflows are plotted:

[7]:
fig = plt.figure(figsize=(7,2.5),dpi=150)
fig.patch.set_alpha(0)
ax = fig.add_subplot(111)
for axis in ['top','bottom','left','right']:
    ax.spines[axis].set_linewidth(0.5)
plt.rcParams.update({'font.size': 8, 'pgf.rcfonts' : False})

sns.lineplot(data = inflow);
plt.ylabel('Flow, $Q$ [m$^3$/s]');
plt.xlabel('Timesteps');
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-7-70989f6cf1ab> in <module>
      6 plt.rcParams.update({'font.size': 8, 'pgf.rcfonts' : False})
      7
----> 8 sns.lineplot(data = inflow);
      9 plt.ylabel('Flow, $Q$ [m$^3$/s]');
     10 plt.xlabel('Timesteps');

NameError: name 'inflow' is not defined
_images/single-confluence_12_1.svg

Then the inflows are set to the sourcenodes

[8]:
structure1.set_shape('S.1',36,I - min(I))
structure1.set_shape('S.2',36,I2 - min(I2))
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-8-646e97457fca> in <module>
----> 1 structure1.set_shape('S.1',36,I - min(I))
      2 structure1.set_shape('S.2',36,I2 - min(I2))

NameError: name 'structure1' is not defined

Note

The minimum flow is subtracted from the input because set_shape adds flow relative to the defined baseload. This behaviour might change in the future.

Calculating wave propagation

[9]:
structure1.calc_flow_propagation(36)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-9-1ad55afd81f7> in <module>
----> 1 structure1.calc_flow_propagation(36)

NameError: name 'structure1' is not defined
[10]:
structure1.draw_Qin(figsize=(7,4))
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-10-15aff4fd4c31> in <module>
----> 1 structure1.draw_Qin(figsize=(7,4))

NameError: name 'structure1' is not defined

In the graph we can see that A.1 is a superposition of S.1 and S.2. and is shifted one timestep to the right. E.1 the outflow of the last reach is than a muskingum transformation of A.1 with \(k = 5\) and \(x = 0.1\). This behaviour is as expected.