来自python的epanet 2.0调用
EPANET的Python项目详细描述
流行的城市排水模型epanet 2.0引擎的python接口。 EPANET2由美国环境保护局重新分配到公共领域。 此python包受assela pathirana的版权保护,并在gnu通用公共许可版本3下发布。
readme.txt
epanet 2.0 python调用接口
由于版本为0.4.0.1,库与Python3.0兼容
这是什么?
一个python包,允许用户调用python脚本中的所有epanet programmers toolkit函数。
安装
Windows: | Download the MS Windows installer and run to install. Since version 0.4.0.1 “python wheels ” packages are also provided. So, the following command can also be used to install on windows ^{pr 1}$ |
---|---|
POSIX (e.g. Linux, OS-X): | |
Download source archive (zip file), extract and run (as root) ^{pr 2}$or just type ^{pr 3}$ |
用法:
>>> from epanet import epanet2 as et >>> p="epanet/examples/simple/" >>> ret=et.ENopen(p+"Net3.inp",p+"Net3.rpt","")
Example 1: | Retrieve simulation properties. |
---|
网络的基本特性
>>> 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
获取节点列表
>>> 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']
水力模拟
>>> 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]
节点“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]