{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Basic Usage Example" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "hide_input": true }, "outputs": [], "source": [ "from IPython.display import display, HTML\n", "display(HTML('\"Open'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[EPyT-Flow](https://github.com/WaterFutures/EPyT-Flow) is available on [PyPI](https://pypi.org/project/epyt-flow/) and can be installed via `pip install epyt-flow`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install epyt-flow --quiet" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from epyt_flow.data.benchmarks import load_leakdb_scenarios\n", "from epyt_flow.simulation import ScenarioSimulator, flowunit_to_str\n", "from epyt_flow.utils import to_seconds" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load first Hanoi scenario of [LeakDB](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.data.benchmarks.html#module-epyt_flow.data.benchmarks.leakdb) by calling [load_leakdb_scenarios()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.data.benchmarks.html#epyt_flow.data.benchmarks.leakdb.load_scenarios):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "network_config, = load_leakdb_scenarios(scenarios_id=[\"1\"], use_net1=False, verbose=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create new scenario simulation by creating a new instance of [ScenarioSimulator](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.html#epyt_flow.simulation.scenario_simulator.ScenarioSimulator):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim = ScenarioSimulator(scenario_config=network_config)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set simulation duration to two days by calling [set_general_parameters()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.html#epyt_flow.simulation.scenario_simulator.ScenarioSimulator.set_general_parameters) -- note that all time durations have to be stated in seconds, the function [to_seconds()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.html#epyt_flow.utils.to_seconds) can convert minutes/hours/days to seconds." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.set_general_parameters(simulation_duration=to_seconds(days=2))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add some pressure sensors by calling [set_pressure_sensors()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.html#epyt_flow.simulation.scenario_simulator.ScenarioSimulator.set_pressure_sensors), and a flow sensor by calling [set_flow_sensors()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.html#epyt_flow.simulation.scenario_simulator.ScenarioSimulator.set_flow_sensors):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Place pressure sensors at nodes \"13\", \"16\", \"22\", and \"30\"\n", "sim.set_pressure_sensors(sensor_locations=[\"13\", \"16\", \"22\", \"30\"])\n", "\n", "# Place a flow sensor at link/pipe \"1\"\n", "sim.set_flow_sensors(sensor_locations=[\"1\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run the entire simulation by calling [run_simulation()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.html#epyt_flow.simulation.scenario_simulator.ScenarioSimulator.run_simulation):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "scada_data = sim.run_simulation()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get units of hydraulic measurements by checking the [flow_unit](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.html#epyt_flow.simulation.sensor_config.SensorConfig.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()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.html#epyt_flow.simulation.sensor_config.flowunit_to_str):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(f\"Flow units: {flowunit_to_str(scada_data.sensor_config.flow_unit)}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pressure readings over time.\n", "\n", "We can retrieve the pressure readings by calling [get_data_pressures()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.scada.html#epyt_flow.simulation.scada.scada_data.ScadaData.get_data_pressures) and plot them by utilizing the [plot_pressures()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.scada.html#epyt_flow.simulation.scada.scada_data.ScadaData.plot_pressures) function:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "scada_data.plot_pressures()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Flow readings over time -- we can retrieve the flow readings by calling [get_data_flows()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.scada.html#epyt_flow.simulation.scada.scada_data.ScadaData.get_data_flows) and plot them by calling [plot_flows](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.scada.html#epyt_flow.simulation.scada.scada_data.ScadaData.plot_flows()):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "scada_data.plot_flows()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Do not forget to close the simulation by calling [close()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.html#epyt_flow.simulation.scenario_simulator.ScenarioSimulator.close):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.close()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.20" } }, "nbformat": 4, "nbformat_minor": 2 }