Simulation results are stored in a results object which contains:
Timestamp when the results were created
As shown in the Hydraulic simulation and Water quality simulation sections, simulations results can be generated using the EpanetSimulator as follows (similar methods are used to generate results using the WNTRSimulator):
>>> import wntr >>> wn = wntr.network.WaterNetworkModel('networks/Net3.inp') >>> sim = wntr.sim.EpanetSimulator(wn) >>> results = sim.run_sim()
The node and link results are dictionaries of pandas DataFrames. Each dictionary is a key:value pair, where the key is a result attribute (e.g., node demand, link flowrate) and the value is a DataFrame. DataFrames are indexed by timestep (in seconds from the start of the simulation) with columns that are labeled using node or link names.
The use of pandas facilitates a comprehensive set of time series analysis options that can be used to evaluate results. For more information on pandas, see https://pandas.pydata.org.
Conceptually, DataFrames can be visualized as blocks of data with 2 axis, as shown in Figure 11.
Node results include DataFrames for each of the following attributes:
Leak demand (only when the WNTRSimulator is used)
Quality (only when the EpanetSimulator is used. Water age, tracer percent, or chemical concentration is stored, depending on the mode of water quality analysis)
For example, node results generated with the EpanetSimulator have the following keys:
>>> node_keys = results.node.keys() >>> print(node_keys) dict_keys(['demand', 'head', 'pressure', 'quality'])
Link results include DataFrames for each of the following attributes:
Status (0 indicates closed, 1 indicates open)
Headloss (only when the EpanetSimulator is used)
Setting (only when the EpanetSimulator is used)
Friction factor (only when the EpanetSimulator is used)
Reaction rate (only when the EpanetSimulator is used)
Link quality (only when the EpanetSimulator is used)
The link results that are only accessible from the EpanetSimulator could be included in the WNTRSimulator in a future release. For example, link results generated with the EpanetSimulator have the following keys:
>>> link_keys = results.link.keys() >>> print(link_keys) dict_keys(['flowrate', 'friction_factor', 'headloss', 'quality', 'reaction_rate', 'setting', 'status', 'velocity'])
To access node pressure over all nodes and times:
>>> pressure = results.node['pressure']
DataFrames can be sliced to extract specific information. For example, to access the pressure at node ‘123’ over all times (the “:” notation returns all variables along the specified axis, “head()” returns the first 5 rows, values displayed to 2 decimal places):
>>> pressure_at_node123 = pressure.loc[:,'123'] >>> print(pressure_at_node123.head()) 0 47.08 900 47.13 1800 47.18 2700 47.23 3600 47.94 Name: 123, dtype: float32
To access the pressure at time 3600 over all nodes (values displayed to 2 decimal places):
>>> pressure_at_1hr = pressure.loc[3600,:] >>> print(pressure_at_1hr.head()) name 10 28.25 15 28.89 20 9.10 35 41.52 40 4.18 Name: 3600, dtype: float32
Data can be plotted as a time series, as shown in Figure 12:
>>> ax = pressure_at_node123.plot() >>> text = ax.set_xlabel("Time (s)") >>> text = ax.set_ylabel("Pressure (m)")
Data can also be plotted on the water network model, as shown in Figure 13.
Note that the
plot_network function returns matplotlib objects
for the network nodes and edges, which can be further customized by the user.
In this figure, the node pressure at 1 hr is plotted on the network. Link attributes can be
plotted in a similar manner.
>>> ax = wntr.graphics.plot_network(wn, node_attribute=pressure_at_1hr, ... node_range=[30,55], node_colorbar_label='Pressure (m)')
Network and time series graphics can be customized to add titles, legends, axis labels, and/or subplots.
Pandas includes methods to write DataFrames to the following file formats:
Comma-separated values (CSV)
Hierarchical Data Format (HDF)
Structured Query Language (SQL)
For example, DataFrames can be saved to Excel files using:
The Pandas method
to_excel requires the Python package openpyxl [GaCl18], which is an optional dependency of WNTR.