Model verification¶
In this notebook the model is verified by comparing outcomes of two different examples.
[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
---------------------------------------------------------------------------
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'
[3]:
%load_ext autoreload
%autoreload 2
University of Colorado Boulder example¶
This is the most straightforward example that I could find. It is a simple one segment model. \(k\) and \(x\) are estimated to 2.3h and 0.151559154 respectively.
Loading data¶
The structure is loaded as well as the inflow. On the graph we can see the correct \(k\) and \(x\)
[4]:
structure1 = RiverNetwork('../data/single-segment-boulder.xlsx')
structure1.draw(figsize=(3,3))
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-4-c29742f10cc0> in <module>
----> 1 structure1 = RiverNetwork('../data/single-segment-boulder.xlsx')
2 structure1.draw(figsize=(3,3))
NameError: name 'RiverNetwork' is not defined
[5]:
inflow = np.array(pd.read_excel('../data/example-inflow-boulder.xlsx').Inflow)
structure1.set_shape('S.1',21,inflow-50)
structure1.draw_Qin(only_sources=True,figsize=(7,4))
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-5-f57a4227e509> in <module>
----> 1 inflow = np.array(pd.read_excel('../data/example-inflow-boulder.xlsx').Inflow)
2 structure1.set_shape('S.1',21,inflow-50)
3 structure1.draw_Qin(only_sources=True,figsize=(7,4))
~/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-boulder.xlsx'
Results of flow propagation¶
The flow is calculated for the sink node.
[6]:
structure1.calc_flow_propagation(20)
structure1.draw_Qin(figsize=(7,5))
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-6-36d5c8e4a142> in <module>
----> 1 structure1.calc_flow_propagation(20)
2 structure1.draw_Qin(figsize=(7,5))
NameError: name 'structure1' is not defined
Inflow for node S.1
[7]:
print(structure1.get_Graph().nodes['S.1']['Qin'])
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-7-d7c00ee74e2c> in <module>
----> 1 print(structure1.get_Graph().nodes['S.1']['Qin'])
NameError: name 'structure1' is not defined
Inflow/outflow for sink E.1
[8]:
print(structure1.get_Graph().nodes['E.1']['Qin'])
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-8-f5b40c22ed76> in <module>
----> 1 print(structure1.get_Graph().nodes['E.1']['Qin'])
NameError: name 'structure1' is not defined
These results are then compared to the results of the webpage. The figure shows that the results are almost similar. The small differences in outflow can be explained by rounding errors.

Karahan example¶
In this example the Wilson dataset from the Karahan paper is used. Karahan compared different estimation techniques. It is a simple one segment model. The most interesting difference here is that \(\Delta t\) is not 1 but karahan uses a value of 6. For this dataset the \(x\) is estimated on 0.021 and \(k\) to 29.165. This can also be seen in the figure. The base load is set to 22.
https://onlinelibrary.wiley.com/doi/full/10.1002/cae.20394
Loading data¶
[9]:
structure2 = RiverNetwork('../data/single-segment-karahan.xlsx',dt=6)
structure2.draw(figsize=(3,3))
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-9-ed79ac5bd5f7> in <module>
----> 1 structure2 = RiverNetwork('../data/single-segment-karahan.xlsx',dt=6)
2 structure2.draw(figsize=(3,3))
NameError: name 'RiverNetwork' is not defined
[10]:
inflow = np.array(pd.read_excel('../data/example-inflow-karahan.xlsx').Inflow)
structure2.set_shape('S.1',21,inflow-22)
structure2.draw_Qin(only_sources=True,figsize=(7,4))
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-10-b870641c8db8> in <module>
----> 1 inflow = np.array(pd.read_excel('../data/example-inflow-karahan.xlsx').Inflow)
2 structure2.set_shape('S.1',21,inflow-22)
3 structure2.draw_Qin(only_sources=True,figsize=(7,4))
~/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.xlsx'
Results of flow propagation¶
The flow is calculated for the sink node.
[11]:
structure2.calc_flow_propagation(22)
structure2.draw_Qin(figsize=(7,5))
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-11-f4b55cfcc4cc> in <module>
----> 1 structure2.calc_flow_propagation(22)
2 structure2.draw_Qin(figsize=(7,5))
NameError: name 'structure2' is not defined
The input and output data is shown:
Inflow for node S.1
[12]:
structure2.get_Graph().nodes['S.1']['Qin']
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-12-53da6d4a19e4> in <module>
----> 1 structure2.get_Graph().nodes['S.1']['Qin']
NameError: name 'structure2' is not defined
Inflow/outflow for node E.1
[13]:
structure2.get_Graph().nodes['E.1']['Qin']
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-13-055daccd658f> in <module>
----> 1 structure2.get_Graph().nodes['E.1']['Qin']
NameError: name 'structure2' is not defined
These results are compared to the results of Karahan. And as can be seen in the following figure, the output of the model is the same for Procedure II.

Karahan, H. (2012). Predicting Muskingum flood routing parameters using spreadsheets. Computer Applications in Engineering Education, 20(2), 280-286.
Warning
It should be noted that Karahan seems to use an invalid value for \(\Delta t = 6\). According to theory, the minimum value should be \(2kx = 13\).
Verification of multiple river segments - IJssel¶
The only model known that incorporates multiple river segements is the model of Ciullo. In this paper the IJssel is modelled as multiple muskingum segments in sequence. His code is published on Github: https://github.com/quaquel/epa1361_open.
Ciullo, A., de Bruijn, K. M., Kwakkel, J. H., & Klijn, F. (2019). Accounting for the uncertain effects of hydraulic interactions in optimising embankments heights: Proof of principle for the IJssel River. Journal of Flood Risk Management, e12532. https://onlinelibrary.wiley.com/doi/pdf/10.1111/jfr3.12532
Parts of this code were extracted to understand the techniques used. Then my own code was run on the same data and yielded exactly the same results. These two notebooks are not commented but show the same results. The model is thus verified for multiple segments.
IJssel model verification script