Skip to content

Commit

Permalink
Update uncertainty example
Browse files Browse the repository at this point in the history
  • Loading branch information
andreArtelt committed May 31, 2024
1 parent e1f2fcb commit 25434ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
14 changes: 10 additions & 4 deletions docs/examples/uncertainties.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from epyt_flow.data.networks import load_ltown\n",
"from epyt_flow.simulation import ScenarioSimulator, ModelUncertainty, \\\n",
" RelativeUniformUncertainty\n",
Expand Down Expand Up @@ -98,7 +99,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Add uncertainty (i.e. randomness) with respect to the demand pattern -- i.e. demand pattern values can deviate up to 25% from their original value."
"Add uncertainty (i.e. randomness) with respect to the demand pattern -- i.e. demand pattern values can deviate up to 25% from their original value.\n",
"Consequently, the simulation is no longer deterministic and the results vary from run to run."
]
},
{
Expand All @@ -116,7 +118,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Run simulation and retrieve sensor readings at node \"n105\""
"Run simulation three times and retrieve sensor readings at node \"n105\""
]
},
{
Expand All @@ -125,9 +127,13 @@
"metadata": {},
"outputs": [],
"source": [
"scada_data = sim.run_simulation()\n",
"measurements = []\n",
"for _ in range(3):\n",
" scada_data = sim.run_simulation()\n",
" measurements.append(scada_data.get_data_pressures(sensor_locations=[\"n105\"]).\n",
" flatten().tolist())\n",
"\n",
"plot_timeseries_data(scada_data.get_data_pressures(sensor_locations=[\"n105\"]).T,\n",
"plot_timeseries_data(np.array(measurements),\n",
" x_axis_label=\"Time (5min steps)\", y_axis_label=\"Pressure in $m$\")"
]
},
Expand Down
17 changes: 12 additions & 5 deletions examples/uncertainties.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Example of adding uncertainty with respect to WDN parameters (e.g. demand pattern).
"""
import numpy as np
from epyt_flow.data.networks import load_ltown
from epyt_flow.simulation import ScenarioSimulator, ModelUncertainty, RelativeUniformUncertainty
from epyt_flow.utils import to_seconds
Expand All @@ -12,14 +13,20 @@

# Create scenario
with ScenarioSimulator(scenario_config=network_config) as sim:
# Set simulation duration to five hours
sim.set_general_parameters(simulation_duration=to_seconds(hours=5))
# Set simulation duration to three hours
sim.set_general_parameters(simulation_duration=to_seconds(hours=3))

# Add uncertainty (i.e. randomness) with respect to the demand pattern --
# i.e. demand pattern values can deviate up to 25% from their original value.
# Consequently, the simulation is no longer deterministic and the results vary
# from run to run.
uc = RelativeUniformUncertainty(low=0.75, high=1.25)
sim.set_model_uncertainty(ModelUncertainty(demand_pattern_uncertainty=uc))

# Run simulation and retrieve sensor readings at node "n105"
scada_data = sim.run_simulation()
print(scada_data.get_data_pressures(sensor_locations=["n105"]))
# Run simulation three times and retrieve sensor readings at node "n105"
measurements = []
for _ in range(3):
scada_data = sim.run_simulation()
measurements.append(scada_data.get_data_pressures(sensor_locations=["n105"]).
flatten().tolist())
print(np.mean(measurements, axis=0), np.var(measurements, axis=0))

0 comments on commit 25434ba

Please sign in to comment.