Skip to content

Commit

Permalink
update tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariosmsk committed Jun 20, 2024
1 parent 161176b commit 414934e
Show file tree
Hide file tree
Showing 4 changed files with 490 additions and 326 deletions.
193 changes: 114 additions & 79 deletions epyt/tutorials/Basic_functionality.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -211,7 +202,7 @@
}
},
"source": [
"![Alt text](images/firstpic.jpg)\n"
"![Alt text](images/epyt_tree.png)"
]
},
{
Expand All @@ -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,
Expand All @@ -245,7 +246,6 @@
},
"outputs": [],
"source": [
"help(G.getLinkDiameter)\n",
"help(G.setNodeBaseDemands)"
]
},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -531,7 +520,7 @@
},
"outputs": [],
"source": [
"## Try it yourself below"
"# Try it yourself below"
]
},
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)"
]
},
Expand Down Expand Up @@ -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",
Expand All @@ -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()"
]
Expand Down Expand Up @@ -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",
Expand All @@ -829,6 +835,7 @@
"### Simulation options\n",
"\n",
"Description and code for simulation options.\n",
"\n",
"![Alt text](images/simulationoption.jpeg)"
]
},
Expand All @@ -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)"
]
},
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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) "
]
},
{
Expand All @@ -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",
Expand Down Expand Up @@ -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)"
]
Expand Down
Loading

0 comments on commit 414934e

Please sign in to comment.