Single Reach

In this notebook the effect of different parameter settings of \(x\) and \(k\) is shown.

Note

This is written in old code and will be replaced later using the network model class. The other parts already use the network model class.

Initialising model

[1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
[2]:
from context import fit_muskingum
from fit_muskingum import getParams
from fit_muskingum import calc_Out
from fit_muskingum import calc_C
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-f10bf430f4fd> in <module>
----> 1 from context import fit_muskingum
      2 from fit_muskingum import getParams
      3 from fit_muskingum import calc_Out
      4 from fit_muskingum import calc_C

~/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'
[3]:
df = pd.read_excel('../data/example-inflow-karahan-adjusted.xlsx')
df = df.set_index('Time')
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-3-eec210afa4a4> in <module>
----> 1 df = pd.read_excel('../data/example-inflow-karahan-adjusted.xlsx')
      2 df = df.set_index('Time')

~/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'
[4]:
t = df.index.values
I = np.array(df['Inflow'])
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.plot(t,I,linewidth = 1 , label = 'inflow')
plt.rcParams.update({'font.size': 8, 'pgf.rcfonts' : False})

x = 0.2
k = 2
dt = 1

C0 = calc_C(k,x,dt) # k,x,dt
O0 = calc_Out(I,C0)
plt.plot(t, O0 ,'g',linewidth = 1, label = 'outflow')

plt.ylabel('Flow, $Q$ [m$^3$/s]')
plt.xlabel('Time [h]')
plt.legend();
# save to file
#plt.savefig('../thesis/report/figs/1reach.pdf', bbox_inches = 'tight')
#plt.savefig('../thesis/report/figs/1reach.pgf', bbox_inches = 'tight')
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-6e8c9438bf21> in <module>
----> 1 t = df.index.values
      2 I = np.array(df['Inflow'])
      3 fig = plt.figure(figsize=(7,2.5),dpi=150)
      4 fig.patch.set_alpha(0)
      5

NameError: name 'df' is not defined

The blue line is the inflow to the reach. The reach has parameters \(x = 0.2\), \(k = 2\) and \(\Delta t = 1\) The resulting outflow is shown in green.

Understanding \(k\)

To understand what happens the effect is of \(k\), it is varied while keeping \(x\) constant. \(x\) is fixed to 0.01 while \(k\) takes the values: 1, 3, 5, 10, 25, 50. Again \(\Delta t\) is set to 1.

[5]:
t = df.index.values
I = np.array(df['Inflow'])

length = 50
t = range(0,length,1)
I = np.append(I,np.full((1,length - len(I)),22))

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})

plt.plot(t,I,linewidth = 1 , label = 'inflow')

klist = [1,3,5,10,25,50]
for k in klist:
    x = 0.01
    dt = 1
    out = calc_Out(I,calc_C(k,x,dt))
    plt.plot(t, out,linewidth = 1, label = 'outflow $k$ = ' + '{:02d}'.format(k))

plt.ylabel('Flow, $Q$ [m$^3$/s]')
plt.xlabel('Time [h]')
plt.legend();
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-5-842f2a25259a> in <module>
----> 1 t = df.index.values
      2 I = np.array(df['Inflow'])
      3
      4 length = 50
      5 t = range(0,length,1)

NameError: name 'df' is not defined

It is clear that k is related to the delay or lag of the peak. The peaks shift to the right with increasing \(k\). While the peaks shift, also the attenuation increases. Meanwhile, flow the total volume passed by, the area under the graph, remains the same.

Understanding \(x\)

In the following section we do the same for \(x\). It will take the values: 0, 0.25, 0.5. Both \(k\) and \(\Delta t\) are kept constant at 1

[6]:
t = df.index.values
I = np.array(df['Inflow'])

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})

plt.plot(t,I,linewidth = 1 , label = 'inflow')

for x in [0,0.25,0.5]:
    k = 1
    dt = 1
    out = calc_Out(I,calc_C(k,x,dt))
    plt.plot(t, out,linewidth = 1, label = 'outflow $x$ = ' + '{:01.1f}'.format(x))


plt.ylabel('Flow, $Q$ [m$^3$/s]')
plt.xlabel('Time [h]')
plt.legend()
plt.xlim(2,20);
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-6-3b2d5c3a149c> in <module>
----> 1 t = df.index.values
      2 I = np.array(df['Inflow'])
      3
      4 fig = plt.figure(figsize=(7,2.5),dpi=150)
      5 fig.patch.set_alpha(0)

NameError: name 'df' is not defined

As a result we can see that the \(x\) behaves as the attenuation parameter. For all graphs have the peak at the same timestep, so no shift in time has occured. What differs is the height of each peak. For \(x = 0.5\) no attenuation occurs, while for \(x = 0\) maximum attenuation occurs.