Skip to content

Commit

Permalink
Merge pull request #26 from OpenWaterAnalytics/dev
Browse files Browse the repository at this point in the history
v1.0.5
  • Loading branch information
Mariosmsk authored May 31, 2023
2 parents cc174fc + b2ef9d1 commit b1891e2
Show file tree
Hide file tree
Showing 66 changed files with 24,280 additions and 41,684 deletions.
8 changes: 8 additions & 0 deletions epyt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# -*- coding: utf-8 -*-
__author__ = """KIOS CoE"""
__email__ = "[email protected]"
__version__ = "1.0.5"
__copyright__ = """Copyright 2022, KIOS Research and Innovation Center of Excellence (KIOS CoE),
University of Cyprus (www.kios.org.cy)."""
__license__ = "EUPL License, Version 1.2"


from epyt.epanet import epanet
98 changes: 47 additions & 51 deletions epyt/epanet.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def __init__(self, *argv, version=2.2, loadfile=False):
'NOT', 'BELOW', 'ABOVE']

# Initial attributes
self.classversion = '1.0.4'
self.classversion = '1.0.5'
self.api = epanetapi(version)
print(f'EPANET version {self.getVersion()} '
f'loaded (EPyT version {self.classversion}).')
Expand Down Expand Up @@ -2869,7 +2869,7 @@ def getLinkComment(self, *argv):
See also setLinkComment, getLinkNameID, getLinksInfo.
"""
value = []
indices = self.__getNodeIndices(*argv)
indices = self.__getLinkIndices(*argv)
for i in indices:
value.append(self.api.ENgetcomment(self.ToolkitConstants.EN_LINK, i))
return value
Expand Down Expand Up @@ -3809,7 +3809,7 @@ def getLinkNodesIndex(self, *argv):
See also getNodesConnectingLinksID.
"""
indices = self.__getlinkIndices(*argv)
indices = self.__getLinkIndices(*argv)
value: list[list[int]] = []
for i in indices:
value.append(self.api.ENgetlinknodes(i))
Expand Down Expand Up @@ -4605,7 +4605,7 @@ def getNodesConnectingLinksID(self, *argv):
See also getLinkNodesIndex.
"""
indices = self.__getlinkIndices(*argv)
indices = self.__getLinkIndices(*argv)
values = self.getLinkNodesIndex(indices)
conn_vals = []
for value in values:
Expand Down Expand Up @@ -7131,7 +7131,7 @@ def setLinkNameID(self, value, *argv):
indices = value
value = argv[0]
else:
indices = self.__getlinkIndices()
indices = self.__getLinkIndices()
if isList(indices):
for i in value:
self.api.ENsetlinkid(indices[value.index(i)], i)
Expand Down Expand Up @@ -7386,7 +7386,7 @@ def setLinkPumpHeadCurveIndex(self, value, *argv):
indices = value
value = argv[0]
else:
indices = self.getNodeIndices(*argv)
indices = self.__getLinkIndices(*argv)
if isList(indices):
j = 0
for i in indices:
Expand Down Expand Up @@ -9878,9 +9878,10 @@ def openHydraulicAnalysis(self):

def plot(self, title=None, line=None, point=None, nodesID=None,
nodesindex=None, linksID=None, linksindex=None, highlightlink=None,
highlightnode=None, legend=True, fontsize=5, figure=True,
highlightnode=None, legend=True, fontsize=5, figure=True, fig_size=[3, 2], dpi=300,
node_values=None, node_text=False, link_values=None, link_text=False, colorbar='turbo',
min_colorbar=None, max_colorbar=None, colors=None, colorbar_label=None, *argv):
min_colorbar=None, max_colorbar=None, colors=None, colorbar_label=None, highligthlink_linewidth=1,
highligthnode_linewidth=3.5, *argv):
""" Plot Network, show all components, plot pressure/flow/elevation/waterage/anyvalue
Example 1:
Expand Down Expand Up @@ -9993,10 +9994,11 @@ def plot(self, title=None, line=None, point=None, nodesID=None,
resindex = self.getNodeReservoirIndex()
tankindex = self.getNodeTankIndex()
nodecoords = self.getNodeCoordinates()
linkvertices = self.getLinkVerticesCount()

# Create figure
plt.rcParams["figure.figsize"] = [3, 2]
plt.rcParams['figure.dpi'] = 300
plt.rcParams["figure.figsize"] = fig_size
plt.rcParams['figure.dpi'] = dpi
if figure:
figure = plt.figure()
plt.axis('off')
Expand All @@ -10005,6 +10007,10 @@ def plot(self, title=None, line=None, point=None, nodesID=None,
xV = 0
yV = 0
if plot_links:
lindex = [0]
if highlightlink is not None:
lindex = self.__getLinkIndices(highlightlink)
lNodesInd = self.getLinkNodesIndex(lindex)
x, y = [0, 0], [0, 0]
for i in links_ind:
fromNode = nodeconlinkIndex[i - 1][0]
Expand Down Expand Up @@ -10033,18 +10039,27 @@ def plot(self, title=None, line=None, point=None, nodesID=None,
if link_text:
plt.text((x[0] + x[1]) / 2, (y[0] + y[1]) / 2, "{:.2f}".format(link_values[i - 1]),
{'fontsize': fontsize})

if i in lindex:
plt.plot(x, y, 'r-', linewidth=highligthlink_linewidth, zorder=0)

else:
xV_old = x[0]
yV_old = y[0]

for j in range(len(nodecoords['x_vert'][i])):
xV = nodecoords['x_vert'][i][j]
yV = nodecoords['y_vert'][i][j]
if fix_colorbar and link_values is not None:
plt.plot([xV_old, xV], [yV_old, yV], '-', linewidth=1, zorder=0, color=colors[i])
if i in lindex:
plt.plot([xV_old, xV], [yV_old, yV], 'r-', linewidth=highligthlink_linewidth, zorder=0)
else:
plt.plot([xV_old, xV], [yV_old, yV], color='steelblue', linewidth=0.2, zorder=0)
if fix_colorbar and link_values is not None:
plt.plot([xV_old, xV], [yV_old, yV], '-', linewidth=1, zorder=0, color=colors[i])
else:
plt.plot([xV_old, xV], [yV_old, yV], color='steelblue', linewidth=0.2, zorder=0)
xV_old = xV
yV_old = yV

if fix_colorbar and link_values is not None:
plt.plot([xV, x[1]], [yV, y[1]], '-', linewidth=1, zorder=0, color=colors[i])
else:
Expand All @@ -10066,7 +10081,6 @@ def plot(self, title=None, line=None, point=None, nodesID=None,
nodecoords['x_vert'][i][int(len(nodecoords['x_vert'][i]) / 2)],
nodecoords['y_vert'][i][int(len(nodecoords['x_vert'][i]) / 2)],
"{:.2f}".format(link_values[i - 1]), {'fontsize': fontsize})

if not line:
# Plot Pumps
x, y = [0, 0], [0, 0]
Expand Down Expand Up @@ -10111,34 +10125,11 @@ def plot(self, title=None, line=None, point=None, nodesID=None,
if node_text:
plt.text(xx, yy, "{:.2f}".format(node_values[i - 1]), {'fontsize': fontsize})

if highlightlink is not None:
if type(highlightlink) == str:
lindex = self.getLinkIndex(highlightlink)
else:
lindex = highlightlink
lNodesInd = self.getLinkNodesIndex(lindex)
xy = self.getNodeCoordinates(lNodesInd)
x_from_to = list(xy['x'].values())
y_from_to = list(xy['y'].values())
if self.getLinkVerticesCount(lindex) == 0:
plt.plot(x_from_to, y_from_to, 'r-', linewidth=1, zorder=0)
else:
vertXY = self.getLinkVertices(lindex)
x = [x_from_to[0]]
x.extend(list(vertXY['x'].values())[0])
x.append(x_from_to[1])
y = [y_from_to[0]]
y.extend(list(vertXY['y'].values())[0])
y.append(y_from_to[1])
xV_old = x[0]
yV_old = y[0]
for i in range(len(x)):
plt.plot([xV_old, x[i]], [yV_old, y[i]], 'r-',
linewidth=1.5, zorder=0)
xV_old = x[i]
yV_old = y[i]

if plot_nodes:
highlight_nodeIndices = [0]
if highlightnode is not None:
highlight_nodeIndices = self.__getNodeIndices(highlightnode)

# Plot Tanks
for i in tankindex:
x = nodecoords['x'][i]
Expand All @@ -10153,6 +10144,8 @@ def plot(self, title=None, line=None, point=None, nodesID=None,
plt.text(x, y, i, {'fontsize': fontsize})
if node_text:
plt.text(x, y, "{:.2f}".format(node_values[i - 1]), {'fontsize': fontsize})
if i in highlight_nodeIndices:
plt.plot(nodecoords['x'][i], nodecoords['y'][i], '.r', markersize=highligthnode_linewidth)

# Plot Reservoirs
for i in resindex:
Expand All @@ -10169,6 +10162,8 @@ def plot(self, title=None, line=None, point=None, nodesID=None,
plt.text(x, y, i, {'fontsize': fontsize})
if node_text:
plt.text(x, y, "{:.2f}".format(node_values[i - 1]), {'fontsize': fontsize})
if i in highlight_nodeIndices:
plt.plot(nodecoords['x'][i], nodecoords['y'][i], '.r', markersize=highligthnode_linewidth)

# Plot Junctions
for i in juncind:
Expand All @@ -10185,6 +10180,9 @@ def plot(self, title=None, line=None, point=None, nodesID=None,
if node_text:
plt.text(x, y, "{:.2f}".format(node_values[i - 1]), {'fontsize': fontsize})

if i in highlight_nodeIndices:
plt.plot(nodecoords['x'][i], nodecoords['y'][i], '.r', markersize=highligthnode_linewidth)

if node_values is not None:
# Plot node values
x = list(nodecoords['x'].values())
Expand All @@ -10198,12 +10196,6 @@ def plot(self, title=None, line=None, point=None, nodesID=None,
bar.outline.set_visible(False)
bar.set_label(label=colorbar_label, size=fontsize)

if highlightnode is not None:
nodeIndices = self.__getNodeIndices(highlightnode)
for i in nodeIndices:
temp_coords = self.getNodeCoordinates(i)
plt.plot(temp_coords['x'][i], temp_coords['y'][i], '.r', markersize=3.5)

if legend:
leg = plt.legend(loc=0, fontsize=fontsize, markerscale=1)
frame = leg.get_frame()
Expand Down Expand Up @@ -10234,7 +10226,7 @@ def plot_show(self):

def plot_ts(self, X=None, Y=None, title='', xlabel='', ylabel='', color=None, marker='x',
figure_size=[3, 2.5], constrained_layout=True, fontweight='normal', fontsize=12, labels=None,
save_fig=False, filename='temp', dpi=300, filetype='png', legend_location='best'):
save_fig=False, filename='temp', tight_layout=False, dpi=300, filetype='png', legend_location='best'):
""" Plot X Y data
"""
num_points = np.atleast_2d(Y).shape[1]
Expand All @@ -10253,9 +10245,12 @@ def plot_ts(self, X=None, Y=None, title='', xlabel='', ylabel='', color=None, ma
random.uniform(0, 1))
try:
values = Y[:, i]
label = labels[i]
except:
values = Y

if labels is not None:
label = labels[i]
else:
label = None

if marker:
Expand All @@ -10271,7 +10266,8 @@ def plot_ts(self, X=None, Y=None, title='', xlabel='', ylabel='', color=None, ma
plt.xlabel(xlabel, fontsize=fontsize)
plt.ylabel(ylabel, fontsize=fontsize)
plt.title(title, fontsize=fontsize, fontweight=fontweight)
# plt.tight_layout()
if tight_layout:
plt.tight_layout()
if labels is not None:
plt.legend(loc=legend_location, fontsize=fontsize, markerscale=1)
plt.show(block=False)
Expand Down Expand Up @@ -10692,7 +10688,7 @@ def __getInitParams(self):
# (long/lat & intermediate pipe coordinates)
self.Version = self.getVersion()

def __getlinkIndices(self, *argv):
def __getLinkIndices(self, *argv):
if len(argv) > 0:
if type(argv[0]) is list:
if type(argv[0][0]) is str:
Expand Down
33 changes: 21 additions & 12 deletions epyt/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,27 @@ EPANET Python Toolkit (EPyT) - Examples
- Example 9: Compares hydraulics and quality analysis functions ([ipynb](./EX9_compare_simulations.ipynb), [py](./EX9_compare_simulations.py)).
- Example 10: Close pipes during simulation ([ipynb](./EX10_close_pipes_during_sim.ipynb), [py](./EX10_close_pipes_during_sim.py)).
- Example 11: Assign a new curve to a pump ([ipynb](./EX11_assing_new_curve_pump.ipynb), [py](./EX11_assing_new_curve_pump.py)).
- Example 13: Adds a CV Pipe in a network ([ipynb](./EX13c_add_cvpipe.ipynb), [py](./EX13c_add_cvpipe.py)).
- Example 14: Hydraulic and Quality analysis ([ipynb](./EX14_hydraulic_and_quality_analysis.ipynb), [py](./EX14_hydraulic_and_quality_analysis.py)).
- Example 16: Create multiple scenarios ([ipynb](./EX16_create_multiple_scenarios.ipynb), [py](./EX16_create_multiple_scenarios.py)).
- Example 17b: Add controls via normal functions ([ipynb](./EX17b_add_multiple_controls_pipestatus.ipynb), [py](./EX17b_add_multiple_controls_pipestatus.py)).
- Example 18: Change status of pipe during simulation ([ipynb](./EX18_change_status_pipes.ipynb), [py](./EX18_change_status_pipes.py)).
- Example 20a: Change of external Controls ([ipynb](./EX20a_external_controls.ipynb), [py](./EX20a_external_controls.py)).
- Example 20b: Addition of external Controls ([ipynb](./EX20b_external_controls.ipynb), [py](./EX20b_external_controls.py)).
- Example 21: Pressure driven analysis ([ipynb](./EX21_Pressure_driven_analysis_option.ipynb), [py](./EX21_Pressure_driven_analysis_option.py)).
- Example 22: Overflow of tanks ([ipynb](./EX22_Overflow_option_for_tanks.ipynb), [py](./EX22_Overflow_option_for_tanks.py)).
- Example 23: Change connection of the links ([ipynb](./EX23_Change_connection_links.ipynb), [py](./EX23_Change_connection_links.py)).
- Example 24: Delete all patterns ([ipynb](./EX24_delete_all_patterns.ipynb), [py](./EX24_delete_all_patterns.py)).
- Example 25: Set node name IDs ([ipynb](./EX25_set_node_name_ids.ipynb), [py](./EX25_set_node_name_ids.py)).
- Example 12: Adds a CV Pipe in a network ([ipynb](./EX12_add_cvpipe.ipynb), [py](./EX12_add_cvpipe.py)).
- Example 13: Hydraulic and Quality analysis ([ipynb](./EX13_hydraulic_and_quality_analysis.ipynb), [py](.
/EX13_hydraulic_and_quality_analysis.py)).
- Example 14: Create multiple scenarios ([ipynb](./EX14_create_multiple_scenarios.ipynb), [py](.
/EX14_create_multiple_scenarios.py)).
- Example 15: Add controls via normal functions ([ipynb](./EX15_add_multiple_controls_pipestatus.ipynb), [py](.
/EX15_add_multiple_controls_pipestatus.py)).
- Example 16: Change status of pipe during simulation ([ipynb](./EX16_change_status_pipes.ipynb), [py](.
/EX16_change_status_pipes.py)).
- Example 17a: Change of external Controls ([ipynb](./EX17a_external_controls.ipynb), [py](./EX17a_external_controls.
py)).
- Example 17b: Addition of external Controls ([ipynb](./EX17b_external_controls.ipynb), [py](.
/EX17b_external_controls.py)).
- Example 18: Pressure driven analysis ([ipynb](./EX18_Pressure_driven_analysis_option.ipynb), [py](.
/EX18_Pressure_driven_analysis_option.py)).
- Example 19: Overflow of tanks ([ipynb](./EX19_Overflow_option_for_tanks.ipynb), [py](.
/EX19_Overflow_option_for_tanks.py)).
- Example 20: Change connection of the links ([ipynb](./EX20_Change_connection_links.ipynb), [py](.
/EX20_Change_connection_links.py)).
- Example 21: Delete all patterns ([ipynb](./EX21_delete_all_patterns.ipynb), [py](./EX21_delete_all_patterns.py)).
- Example 22: Set node name IDs ([ipynb](./EX22_set_node_name_ids.ipynb), [py](./EX22_set_node_name_ids.py)).
- Plt Example 1: Create a gif with the flows of Net1. ([ipynb](./Plt_EX1_Create_Flow_gif.ipynb), [py](./Plt_EX1_Create_Flow_gif.py)).
- Plt Example 2: Create a gif with the pressure of net2-cl2 ([ipynb](./Plt_EX2_Create_Pressure_gif.ipynb), [py](./Plt_EX2_Create_Pressure_gif.py)).
- API EN Example 1: Create a network with EN functions, eliminitating the need to an EPANET formatted input file ([ipynb](./Toolkit_api_EX1_using_EN_functions.ipynb), [py](./Toolkit_api_EX1_using_EN_functions.py)).
Expand Down
4 changes: 2 additions & 2 deletions epyt/examples/notebooks/EX10_close_pipes_during_sim.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"EPANET version 20200 loaded (EPyT version 0.0.3).\n",
"EPANET version 20200 loaded (EPyT version 1.0.5).\n",
"Input File Net1.inp loaded successfully.\n",
"\n"
]
Expand Down Expand Up @@ -77,7 +77,7 @@
"23 0.000000 0\n",
"24 0.000000 0\n",
"25 -0.000064 1\n",
"26 -358.364820 1\n",
"26 -358.364816 1\n",
"\n"
]
}
Expand Down
2 changes: 1 addition & 1 deletion epyt/examples/notebooks/EX11_assing_new_curve_pump.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"EPANET version 20200 loaded (EPyT version 0.0.3).\n",
"EPANET version 20200 loaded (EPyT version 1.0.5).\n",
"Input File Net1.inp loaded successfully.\n",
"\n"
]
Expand Down
149 changes: 149 additions & 0 deletions epyt/examples/notebooks/EX12_add_cvpipe.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit b1891e2

Please sign in to comment.