Basic Usage Example

[1]:
from IPython.display import display, HTML
display(HTML('<a target="_blank" href="https://colab.research.google.com/github/WaterFutures/EPyT-Flow/blob/main/docs/examples/basic_usage.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>'))
Open In Colab

This example demonstrates how to create a new scenario based on an .inp file, setting the simulation duration, creating a sensor placement, and retrieving the sensor readings.

EPyT-Flow is available on PyPI and can be installed via pip install epyt-flow:

[2]:
%pip install epyt-flow --quiet
Note: you may need to restart the kernel to use updated packages.
[3]:
from epyt_flow.data.benchmarks import load_leakdb_scenarios
from epyt_flow.simulation import ScenarioSimulator, flowunit_to_str
from epyt_flow.utils import to_seconds

Load first Hanoi scenario of LeakDB by calling load_leakdb_scenarios():

[4]:
network_config, = load_leakdb_scenarios(scenarios_id=["1"], use_net1=False, verbose=False)

Create new scenario simulation by creating a new instance of ScenarioSimulator:

[5]:
sim = ScenarioSimulator(scenario_config=network_config)

Set simulation duration to two days by calling set_general_parameters() – note that all time durations have to be stated in seconds, the function to_seconds() can convert minutes/hours/days to seconds.

[6]:
sim.set_general_parameters(simulation_duration=to_seconds(days=2))

Add some pressure sensors by calling set_pressure_sensors(), and a flow sensor by calling set_flow_sensors():

[7]:
# Place pressure sensors at nodes "13", "16", "22", and "30"
sim.set_pressure_sensors(sensor_locations=["13", "16", "22", "30"])

# Place a flow sensor at link/pipe "1"
sim.set_flow_sensors(sensor_locations=["1"])

Run the entire simulation by calling run_simulation():

[8]:
scada_data = sim.run_simulation()

Get units of hydraulic measurements by checking the flow_unit property of the sensor configuration – note that we can convert the returned integer ID into a human-readable format by calling flowunit_to_str():

[9]:
print(f"Flow units: {flowunit_to_str(scada_data.sensor_config.flow_unit)}")
Flow units: cubic meter/hr

Pressure readings over time.

We can retrieve the pressure readings by calling get_data_pressures() and plot them by utilizing the plot_pressures() function:

[10]:
scada_data.plot_pressures()
../_images/examples_basic_usage_19_0.png
[10]:
<Axes: xlabel='Time (30min steps)', ylabel='Pressure in $meter$'>

Flow readings over time – we can retrieve the flow readings by calling get_data_flows() and plot them by calling plot_flows:

[11]:
scada_data.plot_flows()
../_images/examples_basic_usage_21_0.png
[11]:
<Axes: xlabel='Time (30min steps)', ylabel='Flow rate in $cubic meter/hr$'>

Do not forget to close the simulation by calling close():

[12]:
sim.close()
[ ]: