Python interface to Piccolo and Picalor simulation kernel
Project description
Piccolo5/Piccolo6/Picalor6 and Ganessa_SIM API python calling interface
What is it?
A python package enabling users to call a set of Picwin32.dll or Ganessa_SIM.dll API functions and subroutines within python scripts. Initially provided for python 2.7 32 bits only. 1.9.x versions served as python 3.5 / 3.6 pre-release.
Starting with version 2.0.0, the wheel package is provided for 32 bits version for python 2.7 / 3.5 / 3.6 / 3.7 (Piccolo kernel is a 32 bits application) and 64 bits version for python 3.6 / 3.7 (Ganessa_SIM is available as 32 and 64 bits).
Starting with version 2.1.0, the wheel package is provided for 32 bits version for python 2.7 / 3.5 / 3.6 / 3.7 / 3.8 (Piccolo kernel is a 32 bits application) and 64 bits version for python 3.7 / 3.8 (Ganessa_SIM is available as 32 and 64 bits).
Installation
Windows only
pip install ganessa
Requirements (32 bits)
python 2.7, 3.5, 3.6, 3.7, 3.8
python requirements: numpy 1.11 or above (python 2.7) / numpy 1.13.1 or above (python 3.5 - 3.6) / numpy 1.15.1 (python 3.7 / 3.8)
Piccolo or Picalor kernel library (picwin32.dll), starting from version 5 (141203) for python 2.7 / version 6 for python 3.x
valid Piccolo or Picalor or Ganessa_SIM license
Requirements (64 bits)
python 3.7 or 3.8
numpy 1.13.1 or above (python 3.6) / numpy 1.15.1 (python 3.7 / 3.8)
Ganessa_SIM_x64.dll (64 bit dll)
valid Ganessa_SIM license
This tool expects Picwin32.dll to be in the PATH or in one of the following folders:
[ C: or D: ] / ['Program Files/Adelior/Piccolo5_' or 'Program Files (x86)/Gfi Progiciels/Piccolo6_' or 'Program Files (x86)/Gfi Progiciels/Picalor6_'] 'Program Files (x86)/Safege/Ganessa_'] + ['fr' or 'uk' or 'esp' or 'eng'] + ['' or '_ck']
Or one of Ganessa_SIM.dll or Ganessa_TH.dll or Ganessa_SIM_x64.dll in:
[ C: or D: ] / ['Program Files (x86)/Safege/Ganessa_'] + ['fr' or 'uk' or 'esp' or 'eng']
With custom installations, PICCOLO_DIR or GANESSA_DIR environment variables can be set to define the path.
Content
- The package provides:
- ‘sim’ package:
a few basic functions for reading or loading a model, running hydraulic and WQ simulations.
‘getter’ functions for individual objects and attributes, time series vectors, attribute vector of all object.
- iterators over links, nodes, tanks, demands, and tables, or over Piccolo command language selections.
a Graph class built from the current model graph, with propagation functions.
‘th’ package: same functions for Picalor except running extended period simulations and time series getters.
‘util’ package: miscellaneous functions.
‘OpenFileMMI’ provides classes for opening dialog frame for a .dat/.bin model file, and output (result) file. It should be imported after ‘sim’ or ‘th’.
‘plot’ provides easy multiple simulation vs reference graphs plot settings - requires matplotlib.
‘sort’ provides a heapsort based on heapq.
‘midfile’ provides minimal mif/mid functions similar to shp/dbf shapefile handler (pyshp package).
‘geojsonfile’ provides minimal geojson functions similar to shp/dbf shapefile handler (pyshp package).
‘epanet’ provides epanet2 python API for win32 (thanks to Assela Pathirana - mailto: assela@pathirana.net) similar to EpanetTools-0.4.0; with epanet.getlinknodes corrected (from 0.9.2).
‘parallel’ provides a simple parallel simulations handling framework based on multiprocessing, returning either elementary or reduced results.
Model objects and parameters can be modified using Piccolo command language (see cmd, cmdfile and execute).
Recently introduced functions and classes may not be functional with old versions of Piccolo / Ganessa_SIM kernel.
Documentation
Documentation is provided as pyGanessa.html in the intallation folder.
History of the README document
- Created 2013-07-04:
Revised 2015-05-03: since 2014-12-04 Picwin32.dll is compatible with this API.
Revised 2016-07-07: provided as .rst.
Revised 2017-08-08: install using pip; Piccolo/Ganessa dll folder search order.
Revised 2017-09-12: split sim into core, core_sim, core_th.
Revised 2017-11-13: added sort, midfile, epanet modules.
Revised 2017-11-30: added parallel.
Revised 2018-03-29: minor changes / extension to python 3.5-3.6.
Revised 2018-06-08: OpenFileMMI and epanet details, added example.
Revised 2018-08-16: 64 bits compatibility (Ganessa_SIM and python 3.7 / 3.8 only).
Revised 2018-08-27: numpy requirements.
Revised 2019-09-13: minor changes.
Revised 2019-10-09: extension to python 3.8.
Revised 2019-10-15: README rst fix.
Revised 2020-02-05: added sim.Graph; README rst fix.
Example
# -*- coding: utf-8 -*- '''Test program for ganessa requires a Piccolo model 'model.dat' in the current folder''' from __future__ import (print_function, unicode_literals) import os import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import ganessa.sim as pic # This code sample runs under python 2.7, 3.5, 3.6, 3.7 if __name__ == '__main__': wkfold = os.path.dirname(__file__) if not wkfold: wkfold = os.getcwd() print('Current folder is:', wkfold) os.chdir(wkfold) # will create work files here pic.init(wkfold) # loads the model - change the name here... pic.cmdfile('model.dat') # select small pipe (diameter below 155) # using iterator and D getter, by id pipefilter = lambda d: (d > 0 and d < 155) pipes = [p for p in pic.Links() if pipefilter(pic.linkattr(p, 'D'))] # using iterator and D getter, by index (less concise but slightly faster) pipes = [pic.getid(pic.LINK, k) for k in range(1, pic.nbobjects(pic.LINK)) if pipefilter(pic.nlinkattr(k, 'D'))] # Most Piccoloic, using (french) command language selection pic.setlang('French') pipes = [p for p, _t in pic.Selected('TUYAU (D < 155) FIN')] # minimal setter functions for links, nodes, tanks attributes pid = pipes[len(pipes)//2] diam = pic.linkattr(pid, 'D') pic.setlinkattr(pid, 'D', diam*2) # language-independant commands KWEND = pic.getkeyword(pic.DICT.END) pic.gencmdw(pic.M.MOD, pic.M.MOD.MULT, pic.M.NONE, 'D 2') pic.gencmd(pic.M.LNK, pic.M.LNK.NONE, pic.M.NONE, pid + ' ' + KWEND, 1) # Use command language to set / modify / delete objects pic.execute('MODIF', 'DETR ARC {} FIN'.format(pid)) pic.execute('MODIF', 'FUSION NOEU (AA = 1) FIN', 'FUSION NOEU (AA = 1) FIN') # or change parameters pic.execute('SIMUL', 'CRITX 0.05', 'MXITER 75') # Unlike epanet, first run simulation then browse/ query results pic.full_solveH(silent=True, retry=True) print('Simulation done.') pic.browseH(3600*8.5) fig = plt.figure(figsize=(16-1, 9-1)) # plot 3D elevation and hydraulic head ax = fig.gca(projection='3d') for a in pic.Links(): x, y, z, v, nb = pic.linkXYZV(a, 'CH') if nb > 0: ax.plot(x, y, z, 'r-') ax.plot(x, y, v, 'b-') plt.title(u'Plan de charge a t= 08:30') plt.show() # print min/max pressure over the EPS attr = 'P' minpax_p = [data for data in pic.getMinMax(pic.NODE, attr)] for nid, vmin, vmax, vmoy in minpax_p[:10]: print(nid, attr+'min:', vmin, attr+'max:', vmax) print('\t...') for nid, vmin, vmax, vmoy in minpax_p[-10:]: print(nid, attr+'min:', vmin, attr+'max:', vmax) # get current volume simulation (internal variable steps) and measurement TS for tid in pic.Tanks(): t1, v1, nb1 = pic.tsval(pic.TANK, tid, 'VC') t2, v2, nb2 = pic.msval(pic.TANK, tid, 'VC') # get current volume simulation results at measurement sampling for tid in pic.Tanks(): t3, v3, nb3 = pic.tsvalbymts(pic.TANK, tid, 'VC') # export as Epanet .inp pic.exportEpanet('model.inp') pic.execute('XXMEM ARC : D') pic.savemodel('model_xx.dat', extra_data=[('ARC (D > 149) FIN', 'XX')]) # WQ source data optional argument is a specific node - not used here print('\nWQ source data (input forcing and TS at nodes):') for n, cd, attr, t, c, nb in pic.WQSources(): print(n, cd, attr, nb, t, c) print('Done.') # use reset() for switching model, close() to terminate pic.close()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for ganessa-2.1.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05634e47de8612c98080b97117ca6c16397f6ce22741f243987bc74e356602e2 |
|
MD5 | cbe2a833cd14c6500c0b40cb1cd8d145 |
|
BLAKE2b-256 | 83a60cafff7be381920b0fe69cd52b3bc944551da41e568945a5ac7332ff30b2 |
Hashes for ganessa-2.1.2-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e526eb4aba367fad3a124615257169ac016d4be381fdad5b3e8345aefeca1b2 |
|
MD5 | f1888c3ce35fe58edc85791ecbef8fa1 |
|
BLAKE2b-256 | 2d913a6da7ced503c389aa215f582a4e620060927de2699f49753051f2c94fa0 |
Hashes for ganessa-2.1.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41c2e0324e542ed28de9fa1454460b2adec21199162260ad7a75d40a60419295 |
|
MD5 | 29939900cc6261c630b8d4269d5631a6 |
|
BLAKE2b-256 | ab1758d03af9a3b826403bfb4e74c5b3ddaab97c07638b7fce5a8b0a77fc2f7b |
Hashes for ganessa-2.1.2-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 724a4610bb7510759f337916fd67012944b4a6e7cc1db1cbb1f005085876bc5d |
|
MD5 | 21dbdb7cca798ff8a31636fea9485d62 |
|
BLAKE2b-256 | 292b7f972c8dc3c310c70609c73b007c5bf4dd02ba810d0924f5a4d94f8fdf68 |
Hashes for ganessa-2.1.2-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64f82a4a88f4ce5920ae563c4d5424ab9f28c396fa43d2b59a5cf7580ed0e76f |
|
MD5 | fcb8133ebea931da3e7a348547eca038 |
|
BLAKE2b-256 | e8df925fff24db92e474d2a904982cccb08b7c774644c7b24384a5934770251f |