{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Sensor Fault Example" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import display, HTML\n", "display(HTML('\"Open'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This example demonstrates how add sensor faults to a scenario -- more information can be found in the [documentation](https://epyt-flow.readthedocs.io/en/stable/tut.events.html#sensor-faults)." ] }, { "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.networks import load_hanoi\n", "from epyt_flow.simulation import ScenarioSimulator, SENSOR_TYPE_NODE_PRESSURE\n", "from epyt_flow.simulation.events import SensorFaultStuckZero\n", "from epyt_flow.utils import to_seconds" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load the [Hanoi network](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.data.html#epyt_flow.data.networks.load_hanoi) with default sensor configuration:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hanoi_network_config = load_hanoi(include_default_sensor_placement=True, verbose=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a new simulation:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim = ScenarioSimulator(scenario_config=hanoi_network_config)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set simulaton duration to two days:" ] }, { "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 a pressure sensor fault (i.e. power failure, sensor readings are set to zero) at node \"16\" that is active for 90min (i.e. starts at 150min after simulation begin and ends at 240min after simulation start).\n", "\n", "This is done by creating a new instance of the [SensorFaultStuckZero](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.events.html#epyt_flow.simulation.events.sensor_faults.SensorFaultStuckZero) class and adding this sensor fault to the scenario by calling [add_sensor_fault()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.html#epyt_flow.simulation.scenario_simulator.ScenarioSimulator.add_sensor_fault):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sensor_fault = SensorFaultStuckZero(sensor_id=\"16\",\n", " sensor_type=SENSOR_TYPE_NODE_PRESSURE,\n", " start_time=to_seconds(minutes=150),\n", " end_time=to_seconds(minutes=240))\n", "\n", "sim.add_sensor_fault(sensor_fault)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run the entire simulation:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "scada_data = sim.run_simulation()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Retrieve pressure readings at node \"16\":" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "scada_data.plot_pressures(sensor_locations=[\"16\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Do not forget to close the simulator!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.close()" ] } ], "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 }