Skip to main content

EPANET 2.0 calls from python

Project description

Python interface for the popular urban drainage model EPANET 2.0 engine. EPANET2 is realeased by United States Environmental Protection Agency to public domain. This python package is copyrighted by Assela Pathirana and released under GNU General Public License version 3.

README.txt

Epanet 2.0 Python calling interface

Since version 0.4.0.1 the library is compatible with Python 3.0

What is it?

A python package enabling user to call all the epanet programmers toolkit functions within python scripts.

Installation

Windows:

Use a Python ditribution that comes with a c copiler (use WinPython or PythonXY)

pip install epanettools
POSIX (e.g. Linux, OS-X):

Download source archive (zip file), extract and run (as root)

[sudo] python setup.py install

or just type

[sudo]  pip install epanettools

Usage:

>>> import os
>>> from epanettools import epanet2 as et
>>> from epanettools.examples import simple
>>> file = os.path.join(os.path.dirname(simple.__file__),'Net3.inp')
>>> ret=et.ENopen(file,"Net3.rpt","")
Example 1:

Retrieve simulation properties.

Basic properties of the network

>>> ret,result=et.ENgetcount(et.EN_LINKCOUNT)
>>> print(ret)
0
    >>> print(result)
    119
>>> ret,result=et.ENgetcount(et.EN_NODECOUNT)
>>> print(ret)
0
>>> print(result)
97
    >>> node='105'
    >>> ret,index=et.ENgetnodeindex(node)
    >>> print(ret)
    0
    >>> print ("Node " + node + " has index : " + str(index))
    Node 105 has index : 12

Get the list of nodes

>>> ret,nnodes=et.ENgetcount(et.EN_NODECOUNT)
>>> nodes=[]
>>> pres=[]
>>> time=[]
>>> for index in range(1,nnodes):
...     ret,t=et.ENgetnodeid(index)
...     nodes.append(t)
...     t=[]
...     pres.append(t)
>>> print (nodes)       #doctest: +ELLIPSIS
...                     #doctest: +NORMALIZE_WHITESPACE
    ['10', '15', '20', '35', '40', '50', '60', ..., '275', 'River', 'Lake', '1', '2']

Get nodes indexes on either side of a link with given index

>>> et.ENgetlinknodes(55) # note the first item in the list should be ignored.
[0, 5, 46]
>>> patId = "NewPattern";
>>> ret=et.ENaddpattern(patId)
>>> print(ret)
0
>>> import numpy as np
>>> patFactors=np.array([0.8, 1.1, 1.4, 1.1, 0.8, 0.7, 0.9, 0.0, 0.8, 0.8, 0.0, 0.0],
...                      dtype=np.float32)
>>> ret,patIndex=et.ENgetpatternindex(patId)
>>> print(patIndex)
6
>>> et.ENsetpattern(patIndex, patFactors)
0
>>> et.ENgetpatternid(6)[1]
'NewPattern'
>>> et.ENgetpatternlen(6)
[0, 12]
>>> [round(et.ENgetpatternvalue(6,i)[1],3) for i in range(1,12+1)]
[0.8, 1.1, 1.4, 1.1, 0.8, 0.7, 0.9, 0.0, 0.8, 0.8, 0.0, 0.0]
>>> et.ENsetpatternvalue(6,9,3.3)
0
>>> [round(et.ENgetpatternvalue(6,i)[1],3) for i in range(1,12+1)]
[0.8, 1.1, 1.4, 1.1, 0.8, 0.7, 0.9, 0.0, 3.3, 0.8, 0.0, 0.0]

Hydraulic Simulation

>>> et.ENopenH()
0
>>> et.ENinitH(0)
0
>>> while True :
...    ret,t=et.ENrunH()
...    time.append(t)
...    # Retrieve hydraulic results for time t
...    for  i in range(0,len(nodes)):
...        ret,p=et.ENgetnodevalue(i+1, et.EN_PRESSURE )
...        pres[i].append(p)
...    ret,tstep=et.ENnextH()
...    if (tstep<=0):
...        break
>>> ret=et.ENcloseH()
>>> print([round(x,4) for x in pres[0]])   #doctest: +ELLIPSIS
...                                         #doctest: +NORMALIZE_WHITESPACE
    [-0.6398, 40.1651, 40.891, 41.0433, ..., 0.569, -0.8864, 0.2997]

Pressure at the node ‘10’

>>> ret,ind=et.ENgetnodeindex("10")
>>> print (ind)
1
>>> print([round(x,4) for x in pres[ind+1]]) # remember epanet count starts at 1.
...                                          #doctest: +ELLIPSIS
...                                          #doctest: +NORMALIZE_WHITESPACE
    [12.5657, 12.9353, 13.4351, 14.0307, ..., 13.1174, 13.3985, 13.5478]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

EPANETTOOLS-0.5.0.2.zip (190.1 kB view details)

Uploaded Source

File details

Details for the file EPANETTOOLS-0.5.0.2.zip.

File metadata

  • Download URL: EPANETTOOLS-0.5.0.2.zip
  • Upload date:
  • Size: 190.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for EPANETTOOLS-0.5.0.2.zip
Algorithm Hash digest
SHA256 0c818e4f14ccb6b64dd552fa5acd23743cd6812b958ad2eadec0c9a73d7f6821
MD5 0836a14cf291f9f6ab97dd37d4e0ba55
BLAKE2b-256 210d4fc7858193da69d25e85d5d5ea187960b42c1cacf263500c4dd76ad3b3a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page