diff --git a/epyt/tutorials/Basic_functionality.ipynb b/epyt/tutorials/Basic_functionality.ipynb index c40a060..51480fb 100644 --- a/epyt/tutorials/Basic_functionality.ipynb +++ b/epyt/tutorials/Basic_functionality.ipynb @@ -62,20 +62,11 @@ { "cell_type": "code", "execution_count": null, - "id": "0b382605-7614-4c97-9b8d-112db55eefc0", - "metadata": { - "ExecuteTime": { - "end_time": "2024-06-20T09:02:19.219738400Z", - "start_time": "2024-06-20T09:02:18.838840Z" - }, - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, + "id": "464f61f7-7ae5-41d5-a5b8-9c467b890c93", + "metadata": {}, "outputs": [], "source": [ - "%pip install epyt" + "%pip install epyt==1.1.8" ] }, { @@ -211,7 +202,7 @@ } }, "source": [ - "![Alt text](images/firstpic.jpg)\n" + "![Alt text](images/epyt_tree.png)" ] }, { @@ -229,6 +220,16 @@ "Just type \"help\" followed by the command\n" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "33b3a878-9bc6-4808-8ce8-fcd097ff561a", + "metadata": {}, + "outputs": [], + "source": [ + "help(G.getLinkDiameter)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -245,7 +246,6 @@ }, "outputs": [], "source": [ - "help(G.getLinkDiameter)\n", "help(G.setNodeBaseDemands)" ] }, @@ -278,20 +278,9 @@ }, "outputs": [], "source": [ - "# write \"G.\" and press \"Tab\" key to find a command" + "# Write \"G.\" and press \"Tab\" key to find a command" ] }, - { - "cell_type": "markdown", - "id": "c09ccf9cc60a4d3c", - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "source": [] - }, { "cell_type": "markdown", "id": "d415f0c0acab549b", @@ -323,29 +312,21 @@ }, "outputs": [], "source": [ - "import matplotlib.pyplot as plt\n", - "from IPython.display import display, clear_output\n", - "\n", "# Assuming G has a plot method\n", "# Simple plot\n", - "G.plot()\n", - "\n", - "# Highlight specific nodes\n", - "G.plot(highlightnode=['n616', 'n281', 'n31'])\n", - "display(plt.gcf())\n", - "plt.close()\n" + "G.plot()" ] }, { - "cell_type": "markdown", - "id": "222c59d52510b9e0", - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "source": [] + "cell_type": "code", + "execution_count": null, + "id": "2506fe6a-d43f-4dfd-986c-a6d839d9e601", + "metadata": {}, + "outputs": [], + "source": [ + "# Highlight specific nodes\n", + "G.plot(highlightnode=['n616', 'n281', 'n31'])" + ] }, { "cell_type": "markdown", @@ -357,7 +338,7 @@ } }, "source": [ - "## Getting information from links (pipes, pumps, valves)\n", + "### Getting information from links (pipes, pumps, valves)\n", "\n", "\n", "![Alt text](images/statistics.jpeg)\n" @@ -425,8 +406,16 @@ "print(\"diameters = \", diameters)\n", "\n", "pipelength = G.getLinkLength([1,2,3])\n", - "print(\"pipelength = \", pipelength)\n", - "\n", + "print(\"pipelength = \", pipelength)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aa5fabe0-9bfc-4a1c-8c5d-b70a4039a5e0", + "metadata": {}, + "outputs": [], + "source": [ "LinkNameID = G.getLinkNameID()\n", "print(\"LinkNameID = \", LinkNameID)\n", "\n", @@ -531,7 +520,7 @@ }, "outputs": [], "source": [ - "## Try it yourself below" + "# Try it yourself below" ] }, { @@ -566,11 +555,27 @@ "outputs": [], "source": [ "demandcategories = G.getNodeDemandCategoriesNumber()\n", - "print(\"demandcategories = \", demandcategories)\n", - "\n", + "print(\"demandcategories = \", demandcategories)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "929f3b2f-33b7-42ff-ad41-fd51f1979e05", + "metadata": {}, + "outputs": [], + "source": [ "demands = G.getNodeBaseDemands()\n", - "print(\"demands = \", demands)\n", - "\n", + "print(\"demands = \", demands)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "65400228-880d-492e-8925-eb36688ef439", + "metadata": {}, + "outputs": [], + "source": [ "demandscategory1 = G.getNodeBaseDemands(1) # Get categories 1\n", "print(\"demandscategory1 = \", demandscategory1)\n", "\n", @@ -612,15 +617,17 @@ }, "outputs": [], "source": [ - "#change pipe diameter\n", - "d4 = G.getLinkDiameter(4)\n", + "# Change pipe diameter\n", + "link_index = 4\n", + "link_index_py = link_index - 1\n", + "d4 = G.getLinkDiameter(link_index)\n", "print(\"d4 = \", d4)\n", "\n", "diameters = G.getLinkDiameter()\n", "print(\"diameters = \", diameters)\n", "\n", - "diameters[4 - 1] = 200 #python starts from 0 \n", - "print(\"diameters[4] = \",diameters[4 - 1])\n", + "diameters[link_index_py] = 200 # Starts from 0 \n", + "print(\"diameters[4] = \",diameters[link_index_py])\n", "\n", "G.setLinkDiameter(diameters)\n", "d4new = G.getLinkDiameter(4)\n", @@ -656,18 +663,20 @@ }, "outputs": [], "source": [ - "#change node elevation\n", - "e4 = G.getNodeElevations(4)\n", + "# Change node elevation\n", + "node_index = 4\n", + "node_index_py = node_index - 1\n", + "e4 = G.getNodeElevations(node_index)\n", "print(\"e4 = \",e4)\n", "\n", "elevations = G.getNodeElevations()\n", "print(\"elevations = \", elevations)\n", "\n", - "elevations[4] = 70\n", - "print(\"elevations[4] = \", elevations[4])\n", + "elevations[node_index_py] = 70\n", + "print(\"elevations[4] = \", elevations[node_index_py])\n", "G.setNodeElevations(elevations)\n", "\n", - "e4new = G.getNodeElevations(5)\n", + "e4new = G.getNodeElevations(node_index)\n", "print(\"e4new = \", e4new)" ] }, @@ -743,7 +752,6 @@ "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", - "import numpy as np\n", "# Create a new figure\n", "fig, ax = plt.subplots()\n", "fig.set_figwidth(7)\n", @@ -754,7 +762,6 @@ "ax.set_ylabel(f'Pattern', fontsize=8)\n", "# Turn on the grid\n", "plt.grid(True)\n", - "\n", "# Show the plot\n", "plt.show()" ] @@ -809,7 +816,6 @@ "fig.set_figwidth(7)\n", "# Plot the first row of Patterns\n", "plt.plot(Patterns[patternIndex-1, :])\n", - "\n", "ax.set_title('Residential pattern', fontsize=8)\n", "ax.set_xlabel('Time', fontsize=8)\n", "ax.set_ylabel(f'Pattern', fontsize=8)\n", @@ -829,6 +835,7 @@ "### Simulation options\n", "\n", "Description and code for simulation options.\n", + "\n", "![Alt text](images/simulationoption.jpeg)" ] }, @@ -848,16 +855,17 @@ }, "outputs": [], "source": [ - "SimulationDuration = G.getTimeSimulationDuration() #in seconds\n", + "# Times in seconds\n", + "SimulationDuration = G.getTimeSimulationDuration() \n", "print(\"SimulationDuration = \", SimulationDuration)\n", "\n", "SimulationDurationHours = SimulationDuration/3600\n", "print(\"SimulationDurationHours = \", SimulationDurationHours)\n", "\n", - "HydraulicStep = G.getTimeHydraulicStep() #in seconds\n", + "HydraulicStep = G.getTimeHydraulicStep() \n", "print(\"HydraulicStep = \", HydraulicStep)\n", "\n", - "QualityStep = G.getTimeQualityStep() #in seconds\n", + "QualityStep = G.getTimeQualityStep()\n", "print(\"QualityStep = \", QualityStep)" ] }, @@ -877,10 +885,10 @@ }, "outputs": [], "source": [ - "PatternStep = G.getTimePatternStep() #in seconds\n", + "PatternStep = G.getTimePatternStep() \n", "print(\"PatternStep = \", PatternStep)\n", "\n", - "ReportingStep = G.getTimeReportingStep() #in seconds\n", + "ReportingStep = G.getTimeReportingStep()\n", "print(\"ReportingStep = \", ReportingStep)\n", "\n", "ReportingStart = G.getTimeReportingStart()\n", @@ -903,6 +911,17 @@ "### Hydraulic options\n" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "eb959b71-67fe-4341-8d8f-4b8cefbe9e02", + "metadata": {}, + "outputs": [], + "source": [ + "Units = G.getUnits()\n", + "print(\"Units = \", G.getAllAttributes(Units))" + ] + }, { "cell_type": "code", "execution_count": null, @@ -919,13 +938,10 @@ }, "outputs": [], "source": [ - "Units = G.getUnits()\n", - "print(\"Units = \", Units)\n", - "\n", "FlowUnits = G.getFlowUnits()\n", "print(\"FlowUnits = \", FlowUnits)\n", "\n", - "PressureUnits = G.NodePressureUnits\n", + "PressureUnits = Units.NodePressureUnits\n", "print(\"PressureUnits = \", PressureUnits)\n", "\n", "HeadLossFormula = G.getOptionsHeadLossFormula()\n", @@ -965,11 +981,22 @@ "\n", "zeroNodes = np.zeros(G.NodeCount)\n", "print(\"zeroNodes = \", zeroNodes)\n", - "G.setNodeInitialQuality(zeroNodes) #setting initial chlorine level at 0 mg/L\n", "\n", + "# Setting initial chlorine level at 0 mg/L\n", + "G.setNodeInitialQuality(zeroNodes) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f8173138-9e9f-4fdc-abbd-a5614ea6f176", + "metadata": {}, + "outputs": [], + "source": [ "brk = -0.3 * np.ones(G.LinkCount)\n", "print(\"brk = \", brk)\n", - "G.setLinkBulkReactionCoeff(brk) #setting Bulk Reaction Coefficient" + "# Setting Bulk Reaction Coefficient\n", + "G.setLinkBulkReactionCoeff(brk) " ] }, { @@ -990,7 +1017,8 @@ "source": [ "wrk = -0.1 * np.ones(G.LinkCount)\n", "print(\"wrk = \", wrk)\n", - "G.setLinkWallReactionCoeff(wrk) #setting Pipe wall Reaction Coefficient\n", + "# Setting Pipe wall Reaction Coefficient\n", + "G.setLinkWallReactionCoeff(wrk)\n", "\n", "BulkReactionOrder = G.getOptionsPipeBulkReactionOrder()\n", "print(\"BulkReactionOrder = \", BulkReactionOrder)\n", @@ -1035,9 +1063,16 @@ "\n", "for i in ReservoirsIndex:\n", " G.setNodeSourceType(i, 'CONCEN')\n", - " G.setNodeSourceQuality(i, 0.8)\n", - "\n", - "\n", + " G.setNodeSourceQuality(i, 0.8)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "42791c53-665a-40e0-ba15-69b47c971e34", + "metadata": {}, + "outputs": [], + "source": [ "NodeSourceQuality = G.getNodeSourceQuality(ReservoirsIndex)\n", "print(\"NodeSourceQuality = \", NodeSourceQuality)" ] diff --git a/epyt/tutorials/Run_First_EPANET_Analysis.ipynb b/epyt/tutorials/Run_First_EPANET_Analysis.ipynb index 103bff3..6425eb7 100644 --- a/epyt/tutorials/Run_First_EPANET_Analysis.ipynb +++ b/epyt/tutorials/Run_First_EPANET_Analysis.ipynb @@ -2,84 +2,117 @@ "cells": [ { "cell_type": "markdown", + "id": "f5e4a1a0ab4123ff", + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "source": [ - "# EpyT Basic Functionalities\n", + "# Basic Usage of EPyT\n", "\n", - "### Table of Contents\n", - "* Initialize EPANET-MATLAB Toolkit\n", + "### Outline\n", + "* Initialize EPANET-Python Toolkit\n", "* Running your first analysis\n", - "* Other methods to run EPANET\n", + "* Other method to run EPANET\n", "* Plot results\n", "* Iteratively (step-by-step) hydraulic analysis\n", "* Iteratively (step-by-step) quality analysis" - ], - "metadata": { - "collapsed": false - }, - "id": "f5e4a1a0ab4123ff" + ] }, { "cell_type": "markdown", + "id": "e66af3efe802e0d3", + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "source": [ "### Initialize EPANET Python Toolkit (EPyT)\n", "\n", "You should always begin with this command to import the toolkit." - ], - "metadata": { - "collapsed": false - }, - "id": "e66af3efe802e0d3" + ] }, { "cell_type": "code", + "execution_count": null, + "id": "af472bf6-58b9-4102-af4c-7de5dd1fe940", + "metadata": {}, "outputs": [], "source": [ - "from epyt import epanet" - ], + "%pip install epyt" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "32dc981b7df58ac2", "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-06-20T09:30:42.530048800Z", "start_time": "2024-06-20T09:30:42.467316100Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false } }, - "id": "32dc981b7df58ac2", - "execution_count": null + "outputs": [], + "source": [ + "from epyt import epanet" + ] }, { "cell_type": "markdown", + "id": "9ab75467312bfab3", + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "source": [ "### Load a benchmark network\n", "Decide which benchmark network to use and load the network" - ], - "metadata": { - "collapsed": false - }, - "id": "9ab75467312bfab3" + ] }, { "cell_type": "code", + "execution_count": null, + "id": "a19a6512998d48e8", + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-20T09:30:43.034397800Z", + "start_time": "2024-06-20T09:30:42.554090700Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, + "scrolled": true + }, "outputs": [], "source": [ - "#decide which network to load from the \"/networks/\" folder \n", - "filename = 'Net1.inp' #you can also try 'net2-cl2.inp', 'Net3.inp', etc.\n", + "# Decide which network to load from the \"/networks/\" folder \n", + "filename = 'net2-cl2.inp' # You can also try 'net2-cl2.inp', 'Net3.inp', etc.\n", "\n", - "#call epanet class and load all data and functions in G structure\n", + "# Call epanet class and load all data and functions in G structure\n", "G = epanet(filename)\n", "G.plot()" - ], + ] + }, + { + "cell_type": "markdown", + "id": "4bf16e38e375972f", "metadata": { "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-20T09:30:43.034397800Z", - "start_time": "2024-06-20T09:30:42.554090700Z" + "jupyter": { + "outputs_hidden": false } }, - "id": "a19a6512998d48e8", - "execution_count": null - }, - { - "cell_type": "markdown", "source": [ "### Running your first analysis\n", "There are 4 ways to run a simulation using the Toolkit:\n", @@ -89,195 +122,236 @@ "3.     Using the ENepanet function binary file\n", "4.     Using the command line and the binary file\n", "\n" - ], - "metadata": { - "collapsed": false - }, - "id": "4bf16e38e375972f" + ] }, { "cell_type": "code", - "outputs": [], - "source": [ - "#set simulation duration at hours \n", - "hrs = 48 \n", - "G.setTimeSimulationDuration(3600*hrs)" - ], + "execution_count": null, + "id": "fc39b8c3f2ce3639", "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-06-20T09:30:43.034397800Z", "start_time": "2024-06-20T09:30:42.943540200Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false } }, - "id": "fc39b8c3f2ce3639", - "execution_count": null + "outputs": [], + "source": [ + "# Set simulation duration at hours \n", + "hrs = 48 \n", + "G.setTimeSimulationDuration(3600*hrs)" + ] }, { "cell_type": "markdown", - "source": [ - "### Execute the simulation using the batch hydraulic analysis method\n" - ], + "id": "f2fa44cf59171470", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, - "id": "f2fa44cf59171470" + "source": [ + "### Execute the simulation using the batch hydraulic analysis method\n" + ] }, { "cell_type": "code", - "outputs": [], - "source": [ - "H = G.getComputedHydraulicTimeSeries()\n", - "G.getAllAttributes(H)" - ], + "execution_count": null, + "id": "b9d405f2d6ba9df7", "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-06-20T09:30:43.170461300Z", "start_time": "2024-06-20T09:30:42.958055700Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false } }, - "id": "b9d405f2d6ba9df7", - "execution_count": null + "outputs": [], + "source": [ + "H = G.getComputedHydraulicTimeSeries()\n", + "G.getAllAttributes(H)" + ] }, { "cell_type": "markdown", - "source": [ - "### Execute the simulation using the batch quality analysis method" - ], + "id": "b605d50d766968db", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, - "id": "b605d50d766968db" + "source": [ + "### Execute the simulation using the batch quality analysis method" + ] }, { "cell_type": "code", - "outputs": [], - "source": [ - "Q = G.getComputedQualityTimeSeries()\n", - "G.getAllAttributes(Q)" - ], + "execution_count": null, + "id": "696f64a1dab4d583", "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-06-20T09:30:43.230144100Z", "start_time": "2024-06-20T09:30:43.058687200Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false } }, - "id": "696f64a1dab4d583", - "execution_count": null + "outputs": [], + "source": [ + "Q = G.getComputedQualityTimeSeries()\n", + "G.getAllAttributes(Q)" + ] }, { "cell_type": "markdown", - "source": [ - "### Other methods to run EPANET" - ], + "id": "b41c10e23d6de09c", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, - "id": "b41c10e23d6de09c" + "source": [ + "### Other methods to run EPANET" + ] }, { "cell_type": "markdown", - "source": [ - "### Method using the EPANET executable" - ], + "id": "58230995827c03ff", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, - "id": "58230995827c03ff" + "source": [ + "#### Method using the EPANET executable" + ] }, { "cell_type": "code", - "outputs": [], - "source": [ - "Hexe = G.getComputedTimeSeries()\n", - "G.getAllAttributes(Hexe)" - ], + "execution_count": null, + "id": "aa79e0a6158ebb8b", "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-06-20T09:30:43.632487300Z", "start_time": "2024-06-20T09:30:43.118354400Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false } }, - "id": "aa79e0a6158ebb8b", - "execution_count": null + "outputs": [], + "source": [ + "Hexe = G.getComputedTimeSeries()\n", + "G.getAllAttributes(Hexe)" + ] }, { "cell_type": "markdown", - "source": [ - "### Method using the ENepanet library function (fastest)" - ], + "id": "6b72020f3f42ebac", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, - "id": "6b72020f3f42ebac" + "source": [ + "### Method using the ENepanet library function" + ] }, { "cell_type": "code", - "outputs": [], - "source": [ - "Hbatch = G.getComputedTimeSeries_ENepanet()\n", - "G.getAllAttributes(Hbatch)" - ], + "execution_count": null, + "id": "c9a3380ec9ad43b", "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-06-20T09:30:43.718249300Z", "start_time": "2024-06-20T09:30:43.626860900Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false } }, - "id": "c9a3380ec9ad43b", - "execution_count": null + "outputs": [], + "source": [ + "Hbatch = G.getComputedTimeSeries_ENepanet()\n", + "G.getAllAttributes(Hbatch)" + ] }, { "cell_type": "markdown", - "source": [ - "### Plot results" - ], + "id": "e2aed1aed9876191", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, - "id": "e2aed1aed9876191" + "source": [ + "### Plot results" + ] }, { "cell_type": "code", + "execution_count": null, + "id": "1bc3158238fd647b", + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-20T09:30:43.764685500Z", + "start_time": "2024-06-20T09:30:43.723949500Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "outputs": [], "source": [ "import datetime\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", - "#Get pressure in meters\n", + "# Get pressure in meters\n", "P = H.Pressure\n", - "print(P)\n", - "\n", + "G.printv(P)\n", "F = H.Flow\n", - "print(F)\n", - "\n", + "G.printv(F)\n", "C = Q.NodeQuality\n", - "print(C)\n", - "#Your turn: Plot Chlorine in node with index 10 " - ], + "G.printv(C)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6ff44fc37f178697", "metadata": { - "collapsed": false, "ExecuteTime": { - "end_time": "2024-06-20T09:30:43.764685500Z", - "start_time": "2024-06-20T09:30:43.723949500Z" + "end_time": "2024-06-20T09:31:30.592780900Z", + "start_time": "2024-06-20T09:31:27.653674500Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false } }, - "id": "1bc3158238fd647b", - "execution_count": null - }, - { - "cell_type": "code", "outputs": [], "source": [ "T = H.Time.astype(float) \n", "Tcl = Q.Time.astype(float) \n", - "TD = [datetime.datetime(2022, 7, 18, 0, 0) + datetime.timedelta(seconds=int(t)) for t in T] \n", - "TQ = [datetime.datetime(2022, 7, 18, 0, 0) + datetime.timedelta(seconds=int(t)) for t in Tcl] \n", + "TD = [datetime.datetime(2024, 7, 1, 0, 0) + datetime.timedelta(seconds=int(t)) for t in T] \n", + "TQ = [datetime.datetime(2024, 7, 1, 0, 0) + datetime.timedelta(seconds=int(t)) for t in Tcl] \n", "\n", "plt.rc('xtick', labelsize=5)\n", "plt.rc('ytick', labelsize=7)\n", @@ -290,13 +364,12 @@ "ax.set_ylabel(\"Pressure (meters)\", fontsize=7)\n", "ax.set_xlabel(\"Time\", fontsize=7)\n", "\n", - "#pipeindex = G.getLinkIndex(['0'])\n", + "pipeindex = G.getLinkIndex('1')\n", "fig, ax = plt.subplots(figsize=(4, 3))\n", "fig.set_figwidth(8)\n", "ax.plot(TD, F[:, pipeindex])\n", "ax.grid(True)\n", - "#ax.set_title(f\"Flow in Pipe {G.getLinkNameID(pipeindex)}\", fontsize=8)\n", - "ax.set_title(f\"Flow in Pipe \", fontsize=8)\n", + "ax.set_title(f\"Flow in Pipe {G.getLinkNameID(pipeindex)}\", fontsize=8)\n", "ax.set_ylabel(\"Flow (CMH)\", fontsize=7)\n", "ax.set_xlabel(\"Time\", fontsize=7)\n", "\n", @@ -308,97 +381,123 @@ "ax.set_ylabel(\"Free Chlorine (mg/L)\", fontsize=7)\n", "ax.set_xlabel(\"Time\", fontsize=7)\n", "\n", - "plt.show()" - ], + "plt.show()\n", + "\n", + "# Your turn: Plot Chlorine in node with index 10 " + ] + }, + { + "cell_type": "markdown", + "id": "bf0a386bfff73b43", "metadata": { "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-20T09:31:30.592780900Z", - "start_time": "2024-06-20T09:31:27.653674500Z" + "jupyter": { + "outputs_hidden": false } }, - "id": "6ff44fc37f178697", - "execution_count": null - }, - { - "cell_type": "markdown", "source": [ "![Alt text](images/pic1.jpeg)" - ], - "metadata": { - "collapsed": false - }, - "id": "bf0a386bfff73b43" + ] }, { "cell_type": "markdown", - "source": [ - "### Plot node pressures for specific nodes " - ], + "id": "326a65e8704563af", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, - "id": "326a65e8704563af" + "source": [ + "### Plot node pressures for specific nodes " + ] }, { "cell_type": "code", + "execution_count": null, + "id": "303d7ef88d9cc6ee", + "metadata": { + "ExecuteTime": { + "start_time": "2024-06-20T09:30:44.461322400Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "outputs": [], "source": [ - "node_indices = [1,2,3] #nodes 1, 2 and 3 \n", + "node_indices = [1,2,3] \n", "print(\"Node_indeces = \",node_indices)\n", - "node_names = [G.getNodeNameID(idx) for idx in node_indices] # Python indexing starts from 0\n", + "node_names = [G.getNodeNameID(idx) for idx in node_indices]\n", "Units = G.getUnits()\n", "FlowUnits = G.getFlowUnits()\n", - "print(\"Flow_Units = \",FlowUnits)\n", + "print(\"Flow_Units = \", FlowUnits)\n", "\n", - "fig, axs = plt.subplots(3, 1, figsize=(8, 6), sharex=True) \n", + "fig, axs = plt.subplots(3, 1, figsize=(8, 6)) \n", "\n", "for k, node_index in enumerate(node_indices):\n", " ax = axs[k] \n", - " ax.plot(TD, P[:, node_index - 1]) # Python indexing starts from 0\n", + " node_index_py = node_index - 1 # Python indexing starts from 0\n", " fig.set_figwidth(7)\n", - " ax.set_title(f'Pressure for the node id \"{node_names[k]}\"', fontsize=11)\n", + " ax.plot(TD, P[:, node_index_py])\n", + " ax.grid(True)\n", + " ax.set_title(f'Pressure for the node id \"{node_names[k]}\"', fontsize=8)\n", + " ax.set_ylabel(f'Pressure ({G.NodePressureUnits})', fontsize=7) \n", " ax.set_xlabel('Time (hrs)', fontsize=7)\n", - " ax.set_ylabel(f'Pressure ({G.NodePressureUnits})', fontsize=9) \n", "\n", + "plt.tight_layout() # Automatically adjusts spacing to fit the subplots\n", "plt.show()" - ], + ] + }, + { + "cell_type": "markdown", + "id": "6f871aec8fb701b4", "metadata": { "collapsed": false, - "ExecuteTime": { - "start_time": "2024-06-20T09:30:44.461322400Z" + "jupyter": { + "outputs_hidden": false } }, - "id": "303d7ef88d9cc6ee", - "execution_count": null - }, - { - "cell_type": "markdown", "source": [ "![Alt text](images/pic2.jpeg)\n" - ], - "metadata": { - "collapsed": false - }, - "id": "6f871aec8fb701b4" + ] }, { "cell_type": "markdown", - "source": [ - "### Iteratively (step-by-step) hydraulic analysis" - ], + "id": "c68e1622a247b31b", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, - "id": "c68e1622a247b31b" + "source": [ + "### Iteratively (step-by-step) hydraulic analysis" + ] }, { "cell_type": "code", + "execution_count": null, + "id": "9fc26765279b1afb", + "metadata": { + "ExecuteTime": { + "start_time": "2024-06-20T09:30:44.464117400Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "outputs": [], "source": [ "# 4 steps to run hydraulics\n", - "G.openHydraulicAnalysis() # Step 1\n", - "G.initializeHydraulicAnalysis() # Step 2\n", + "\n", + "# Step 1\n", + "G.openHydraulicAnalysis() \n", + "\n", + "# Step 2\n", + "G.initializeHydraulicAnalysis() \n", "\n", "tstep = 1\n", "P2 = []\n", @@ -408,76 +507,105 @@ "F2 = []\n", "\n", "while tstep > 0:\n", - " ttmp = G.runHydraulicAnalysis() # Step 3\n", + " \n", + " # Step 3\n", + " ttmp = G.runHydraulicAnalysis() \n", " P2.append(G.getNodePressure())\n", " D2.append(G.getNodeActualDemand())\n", " H2.append(G.getNodeElevations())\n", " #H2.append(G.getNodeHydaulicHead())\n", " F2.append(G.getLinkFlows())\n", " T2.append(ttmp)\n", - " tstep = G.nextHydraulicAnalysisStep() # Step 4\n", + " \n", + " # Step 4\n", + " tstep = G.nextHydraulicAnalysisStep() \n", "\n", "G.closeHydraulicAnalysis()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2024-06-20T09:30:44.464117400Z" - } - }, - "id": "9fc26765279b1afb", - "execution_count": null + ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, + "id": "0961169f-91ae-4976-a9c4-31f187ab7bfb", + "metadata": {}, + "outputs": [], "source": [ - "### Plot figures" - ], + "# Print pressures P2\n", + "print(P2)" + ] + }, + { + "cell_type": "markdown", + "id": "8728521d95df08fe", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, - "id": "8728521d95df08fe" + "source": [ + "#### Plot figures" + ] }, { "cell_type": "code", + "execution_count": null, + "id": "5218adb452387e86", + "metadata": { + "ExecuteTime": { + "start_time": "2024-06-20T09:30:44.465860Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "outputs": [], "source": [ - "#import matplotlib.pyplot as plt\n", + "TD = [datetime.datetime(2024, 7, 1, 0, 0) + datetime.timedelta(seconds=int(t)) for t in T2] \n", "\n", "fig, ax = plt.subplots()\n", "for i, node_index in enumerate(node_indices):\n", - " ax.plot(TD, [row[node_index - 1] for row in P2], label=f'Node {node_index}')\n", - "ax.set_title(f'Pressure for 3 nodes ', fontsize=10)\n", - "ax.set_xlabel('Time', fontsize=8)\n", + " node_index_py = node_index - 1\n", + " ax.plot(TD, [row[node_index_py] for row in P2], label=f'Node {node_index}')\n", + "ax.set_title(f'Pressure for first 3 nodes ', fontsize=10)\n", + "ax.set_xlabel('Time (seconds)', fontsize=9)\n", "ax.set_ylabel(f'Pressure({G.NodePressureUnits})', fontsize=8)\n", "fig.set_figwidth(7)\n", "ax.legend(loc='upper right', fontsize=7)\n", "plt.show()" - ], + ] + }, + { + "cell_type": "markdown", + "id": "2f0900f6cfded80f", "metadata": { "collapsed": false, - "ExecuteTime": { - "start_time": "2024-06-20T09:30:44.465860Z" + "jupyter": { + "outputs_hidden": false } }, - "id": "5218adb452387e86", - "execution_count": null - }, - { - "cell_type": "markdown", "source": [ "### Iteratively (step-by-step) quality analysis" - ], - "metadata": { - "collapsed": false - }, - "id": "2f0900f6cfded80f" + ] }, { "cell_type": "code", + "execution_count": null, + "id": "659f766bd479d64", + "metadata": { + "ExecuteTime": { + "start_time": "2024-06-20T09:30:44.468038400Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "outputs": [], "source": [ - "# requires solveCompleteHydraulics\n", + "# Requires solveCompleteHydraulics - ignored because we run hydraulic analysis beforehand.\n", + "\n", "G.openQualityAnalysis()\n", "G.initializeQualityAnalysis()\n", "tleft = 1\n", @@ -493,28 +621,34 @@ " tleft = G.stepQualityAnalysisTimeLeft()\n", "\n", "G.closeQualityAnalysis()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2024-06-20T09:30:44.468038400Z" - } - }, - "id": "659f766bd479d64", - "execution_count": null + ] }, { "cell_type": "markdown", - "source": [ - "### Plot figures" - ], + "id": "6ed7b9f7a9f860e5", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, - "id": "6ed7b9f7a9f860e5" + "source": [ + "#### Plot figures" + ] }, { "cell_type": "code", + "execution_count": null, + "id": "ac2a65193b177584", + "metadata": { + "ExecuteTime": { + "start_time": "2024-06-20T09:30:44.470424Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "outputs": [], "source": [ "fig, ax = plt.subplots()\n", @@ -526,47 +660,42 @@ "\n", "fig.set_figwidth(6)\n", "plt.show()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2024-06-20T09:30:44.470424Z" - } - }, - "id": "ac2a65193b177584", - "execution_count": null + ] }, { "cell_type": "code", - "outputs": [], - "source": [], + "execution_count": null, + "id": "86de5a2a71f2e85d", "metadata": { - "collapsed": false, "ExecuteTime": { "start_time": "2024-06-20T09:30:44.472728800Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false } }, - "id": "86de5a2a71f2e85d", - "execution_count": null + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", - "language": "python", + "display_name": "Python 3 (Spyder)", + "language": "python3", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" + "pygments_lexer": "ipython3", + "version": "3.10.14" } }, "nbformat": 4, diff --git a/epyt/tutorials/images/epyt_tree.png b/epyt/tutorials/images/epyt_tree.png new file mode 100644 index 0000000..f82fc6e Binary files /dev/null and b/epyt/tutorials/images/epyt_tree.png differ diff --git a/epyt/tutorials/images/firstpic.jpg b/epyt/tutorials/images/firstpic.jpg deleted file mode 100644 index 7945ac7..0000000 Binary files a/epyt/tutorials/images/firstpic.jpg and /dev/null differ