Skip to content

Commit

Permalink
Merge pull request #30 from OpenWaterAnalytics/dev
Browse files Browse the repository at this point in the history
fix issues in functions getNodeTankData and setNodeCoordinates #29 #28
  • Loading branch information
Mariosmsk authored Aug 23, 2023
2 parents 28c6f1e + fbd8d4c commit aeac686
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 151 deletions.
2 changes: 1 addition & 1 deletion epyt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
__author__ = """KIOS CoE"""
__email__ = "[email protected]"
__version__ = "1.0.6"
__version__ = "1.0.7"
__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"
Expand Down
60 changes: 33 additions & 27 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.6'
self.classversion = '1.0.7'
self.api = epanetapi(version)
print(f'EPANET version {self.getVersion()} '
f'loaded (EPyT version {self.classversion}).')
Expand Down Expand Up @@ -2922,7 +2922,7 @@ def getLinkType(self, *argv):
lTypes = []
if len(argv) > 0:
index = argv[0]
if type(index) is list:
if isinstance(index, list):
for i in index:
lTypes.append(self.TYPELINK[self.api.ENgetlinktype(i)])
else:
Expand Down Expand Up @@ -2950,7 +2950,7 @@ def getLinkTypeIndex(self, *argv):
lTypes = []
if len(argv) > 0:
index = argv[0]
if type(index) is list:
if isinstance(index, list):
for i in index:
lTypes.append(self.api.ENgetlinktype(i))
else:
Expand Down Expand Up @@ -3789,7 +3789,7 @@ def getLinkIndex(self, *argv):
values = []
if len(argv) > 0:
index = argv[0]
if type(index) is list:
if isinstance(index, list):
for i in index:
values.append(self.api.ENgetlinkindex(i))
else:
Expand Down Expand Up @@ -4133,7 +4133,7 @@ def getNodeDemandCategoriesNumber(self, *argv):
value = []
if len(argv) > 0:
index = argv[0]
if type(index) is list:
if isinstance(index, list):
for i in index:
value.append(self.api.ENgetnumdemands(i))
else:
Expand Down Expand Up @@ -4278,7 +4278,7 @@ def getNodeIndex(self, *argv):
values = []
if len(argv) > 0:
index = argv[0]
if type(index) is list:
if isinstance(index, list):
for i in index:
values.append(self.api.ENgetnodeindex(i))
else:
Expand Down Expand Up @@ -4413,7 +4413,7 @@ def getNodeJunctionIndex(self, *argv):
if (len(value) > 0) and (len(argv) > 0):
index = argv[0]
try:
if type(index) is list:
if isinstance(index, list):
jIndices = []
for i in index:
jIndices.append(value[i - 1] + 1)
Expand Down Expand Up @@ -4560,7 +4560,7 @@ def getNodeReservoirIndex(self, *argv):
if (len(value) > 0) and (len(argv) > 0):
index = argv[0]
try:
if type(index) is list:
if isinstance(index, list):
rIndices = []
for i in index:
rIndices.append(value[i - 1] + 1)
Expand Down Expand Up @@ -4668,7 +4668,7 @@ def getNodeNameID(self, *argv):
values = []
if len(argv) > 0:
index = argv[0]
if type(index) is list:
if isinstance(index, list):
for i in index:
values.append(self.api.ENgetnodeid(i))
else:
Expand Down Expand Up @@ -4906,11 +4906,16 @@ def getNodeTankData(self, *argv):
"""
tankData = EpytValues()
tankIndices = self.getNodeTankIndex()

if len(argv) == 1:
if argv[0] in tankIndices:
tankIndices = argv[0]
if isinstance(argv[0], list):
result = [True for c in argv[0] if c in tankIndices]
if result:
tankIndices = argv[0]
else:
tankIndices = self.getNodeTankIndex(argv[0])
else:
tankIndices = self.getNodeTankIndex(argv[0])
tankIndices = argv[0]

tankData.Index = tankIndices
tankData.Elevation = self.getNodeElevations(tankIndices)
Expand Down Expand Up @@ -4963,7 +4968,7 @@ def getNodeTankIndex(self, *argv):
if (len(value) > 0) and (len(argv) > 0):
index = argv[0]
try:
if type(index) is list:
if isinstance(index, list):
tIndices = []
for i in index:
tIndices.append(value[i - 1] + 1)
Expand Down Expand Up @@ -5322,7 +5327,7 @@ def getNodeType(self, *argv):
nTypes = []
if len(argv) > 0:
index = argv[0]
if type(index) is list:
if isinstance(index, list):
for i in index:
nTypes.append(self.TYPENODE[self.api.ENgetnodetype(i)])
else:
Expand All @@ -5345,7 +5350,7 @@ def getNodeTypeIndex(self, *argv):
nTypes = []
if len(argv) > 0:
index = argv[0]
if type(index) is list:
if isinstance(index, list):
for i in index:
nTypes.append(self.api.ENgetnodetype(i))
else:
Expand Down Expand Up @@ -5771,7 +5776,7 @@ def getPatternNameID(self, *argv):
values = []
if len(argv) > 0:
index = argv[0]
if type(index) is list:
if isinstance(index, list):
for i in index:
values.append(self.api.ENgetpatternid(i))
else:
Expand Down Expand Up @@ -7975,7 +7980,8 @@ def setNodeCoordinates(self, value, *argv):
for i in indices:
self.api.ENsetcoord(i, value[0][indices.index(i)], value[1][indices.index(i)])
else:
value = [value]
if len(indices) == 1:
value = [value]
for i in range(len(value)):
x = value[i][0]
y = value[i][1]
Expand Down Expand Up @@ -8700,7 +8706,7 @@ def setNodeTankMixingModelType(self, value, *argv):
_type = value
elif len(argv) == 1:
_type = argv[0]
if type(_type) is list:
if isinstance(_type, list):
code = []
for i in _type:
code.append(self.TYPEMIXMODEL.index(i))
Expand Down Expand Up @@ -10693,13 +10699,13 @@ def __getInitParams(self):

def __getLinkIndices(self, *argv):
if len(argv) > 0:
if type(argv[0]) is list:
if type(argv[0][0]) is str:
if isinstance(argv[0], list):
if isinstance(argv[0][0], str):
return self.getLinkIndex(argv[0])
else:
return argv[0]
else:
if type(argv[0]) is str:
if isinstance(argv[0], str):
return [self.getLinkIndex(argv[0])]
else:
return [argv[0]]
Expand All @@ -10722,13 +10728,13 @@ def __getLinkInfo(self, iCode, *argv):

def __getNodeIndices(self, *argv):
if len(argv) > 0:
if type(argv[0]) is list:
if type(argv[0][0]) is str:
if isinstance(argv[0], list):
if isinstance(argv[0][0], str):
return self.getNodeIndex(argv[0])
else:
return argv[0]
else:
if type(argv[0]) is str:
if isinstance(argv[0], str):
return [self.getNodeIndex(argv[0])]
else:
return [argv[0]]
Expand Down Expand Up @@ -10963,7 +10969,7 @@ def __readEpanetBin(self, f, binfile, *argv):
def __returnValue(self, value):
if isList(value):
try:
if type(value) is list:
if isinstance(value, list):
value = np.array(value)
value = value.astype(int)
except:
Expand All @@ -10982,7 +10988,7 @@ def __setEval(self, func, iCodeStr, Type, value, *argv):
if len(argv) == 1:
index = value
value = argv[0]
if type(index) is list:
if isinstance(index, list):
j = 0
for i in index:
if np.isnan(value[j]):
Expand Down Expand Up @@ -11014,7 +11020,7 @@ def __setEvalLinkNode(self, func, iCodeStr, Type, value, *argv):
value = argv[0]
if isinstance(index, (list, np.ndarray)):
j = 0
if type(value) is list:
if isinstance(value, list):
for i in index:
strFunc = 'self.api.' + func + '(' + str(
i) + ',' + 'self.ToolkitConstants.EN_' + iCodeStr + ',' + str(value[j]) + ')'
Expand Down
117 changes: 0 additions & 117 deletions epyt/tests/testFunctions_2.py

This file was deleted.

2 changes: 1 addition & 1 deletion epyt/tests/testFunctions_ex.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
EPANET Python Toolkit (EPyT) Test Part 5
EPANET Python Toolkit (EPyT) Test Part 4
This file is provided to ensure that all functions can be executed correctly.
Step-by-step execution. You may also use breakpoints.
"""
Expand Down
2 changes: 1 addition & 1 deletion epyt/tests/testGetSetLinks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
EPANET Python Toolkit (EPyT) Test Part 3
EPANET Python Toolkit (EPyT) Test Part 2
This file is provided to ensure that all functions can be executed correctly.
Step-by-step execution. You may also use the breakpoints,
indicated with a short dash (-) on the left of each line number.
Expand Down
2 changes: 1 addition & 1 deletion epyt/tests/testGetSetNodes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
EPANET Python Toolkit (EPyT) Test Part 2
EPANET Python Toolkit (EPyT) Test Part 3
This file is provided to ensure that all functions can be executed correctly.
Step-by-step execution. You may also use the breakpoints,
indicated with a short dash (-) on the left of each line number.
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

setup(
name=module_name,
version="1.0.6",
version="1.0.7",
author="KIOS CoE",
author_email="[email protected]",
description='A Python module for EPANET water distribution simulation libraries. The EPyT is inspired by the '
description='EPyT: An EPANET-Python Toolkit for Smart Water Network Simulations. The EPyT is inspired by the '
'EPANET-Matlab Toolkit.',
long_description=long_description,
long_description_content_type="text/markdown",
Expand All @@ -48,7 +48,7 @@
'(EUPL 1.2)',
'Operating System :: OS Independent',
],
python_requires=">=3.7",
python_requires=">=3.8",
package_data={f'{module_name}': data},
install_requires=['numpy', 'matplotlib', 'pandas', 'xlsxwriter'],
include_package_data=True
Expand Down

0 comments on commit aeac686

Please sign in to comment.