Getting started

To start using WNTR, open a Python console and import the package:

import wntr

WNTR comes with a simple getting started example, shown below that uses the EPANET Example Network 3 (Net3) INP file. This example demonstrates how to:

  • Import WNTR

  • Generate a water network model

  • Simulate hydraulics

  • Plot simulation results on the network

Note

If WNTR is installed using PyPI or Anaconda, the examples folder is not included. The examples folder can be downloaded by going to https://github.com/USEPA/WNTR, select the “Clone or download” button and then select “Download ZIP.” Uncompress the zip file using standard software tools (e.g., unzip, WinZip) and store them in a folder. The following example assumes the user is running the example from the examples folder.

"""
The following example demonstrates how to import WNTR, generate a water network 
model from an INP file, simulate hydraulics, and plot simulation results on the network.
"""
import wntr

# Create a water network model
inp_file = 'networks/Net3.inp'
wn = wntr.network.WaterNetworkModel(inp_file)

# Graph the network
wntr.graphics.plot_network(wn, title=wn.name)

# Simulate hydraulics
sim = wntr.sim.EpanetSimulator(wn)
results = sim.run_sim()

# Plot results on the network
pressure_at_5hr = results.node['pressure'].loc[5*3600, :]
wntr.graphics.plot_network(wn, node_attribute=pressure_at_5hr, node_size=30, 
                        title='Pressure at 5 hours')

Additional examples are included throughout the WNTR documentation. The examples provided in the documentation assume that a user has experience using EPANET (https://www.epa.gov/water-research/epanet) and Python (https://www.python.org/), including the ability to install and use additional Python packages, such as those listed in Requirements and Optional dependencies.

Several EPANET INP files and example files are also included in the WNTR repository in the examples folder. Example networks range from a simple 9 node network to a 3,000 node network. Additional network models can be downloaded from the University of Kentucky Water Distribution System Research Database at https://uknowledge.uky.edu/wdsrd.

Additional examples

WNTR comes with additional examples that illustrate advanced use cases, including:

  • Pipe leak, stochastic simulation example: This example runs multiple hydraulic simulations of a pipe leak scenario where the location and duration are drawn from probability distributions.

  • Pipe criticality example: This example runs multiple hydraulic simulations to compute the impact that individual pipe closures have on water pressure.

  • Fire flow example: This example runs hydraulic simulations with and without fire fighting flow demand.

  • Sensor placement example: This example uses WNTR with Chama (https://chama.readthedocs.io) to optimize the placement of sensors that minimizes detection time. Note that Chama requires Pyomo and a MIP solver, see Chama installation instructions for more details.