WandaToolbox documentation!
Wanda Toolbox
Toolbox (python scripts) for Wanda modellers. This toolbox includes several tools and utilities that can help with Wanda modelling, running simulations and analyzing and visualizing simulation results. This module is closely related to PyWanda, the Python bindings for the Wanda API.
Wanda is an advanced water hammer software, designed for engineers by engineers. The Python API bindings can be used to create Wanda models, run simulations, and extract the simulation results. The Wanda Toolbox module includes additional scripts to go beyond the basic data retrieval of pywanda.
Installation
Run the following to install this package:
pip install WandaToolbox
Also see: https://pypi.org/project/wandatoolbox/
Usage
Tutorial and reference documentation is provided at wandatoolbox.readthedocs.io. A PDF version of the manual is available here. And the source code is always available at https://github.com/MichielTukker/WandaToolbox.
Support
No official support! For questions/improvements/comments, contact Deltares or Wanda support desk?
Contents
Changelog
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[## [Unreleased]] - 2021-9-20
Added
Added Dashboard example @samvanderzwan.
Added test for wandaplot_table()
sphinx documentation
Documentation pages
Changed
Set github actions for publishing packages automatically
changed unit-test to use mocked pywanda objects
modified github workflow
updated some required packages
[0.0.4] - 2020-03-11
Added
Added unit tests, fixing test names.
Added automatic builds via github actions.
Changed
fixed linting errors.
[0.0.3] - 2020-03-08
Added
Added unit tests, fixing test names.
Added automatic builds via github actions.
Changed
fixed linting errors.
Contributing
We’d love to accept your patches and contributions to this project. There are just a few small guidelines you need to follow.
Guidelines
Write your patch
Add a test case to your patch
Make sure that all tests run properly
Send your patch as a PR
Installation
You can install the WandaToolbox package as follows:
pip install wandatoolbox
Note that not all dependencies are installed by default, check requirements.txt
Development installation and testing
For development you can use the ‘editable’ installation:
pip install -r requirements.txt
pip install -e .
pytest
Building the package
Building the backage is done as follows:
pip install setuptools wheel
python setup.py sdist bdist_wheel
Creating a release
We use bump2version to update the version numbers. Bump2version will also create a tag and commit the changes. This can then be pushed using
cd <root of project>
pip install bump2version
bump2version <major|minor|patch>
git push origin <branch> --tags
The Github Actions have been configured to run the tests and flake8 linting and publish to test.Pypi on every push. If a commit is also tagged it will also publish to Pypi.
Development roadmap (Todo)
functionality for first official release:
[x] syschar plot implementation
[x] image plot implementation
[x] text plot implementation
[x] table plot implementation
[x] Monte-carlo scripts
[ ] unit testing
[ ] tox testing
[ ] Goal seek algorithm
[ ] parameter script read input, run,read output
[ ] calibration routine (goalseek?) for scalar, multiple scalar, timeseries
[ ] calibration for multiple parameters?
[ ] Simple optimization (1 parameter, 1 output?)
[ ] Valve characteristic creation and data import in Wanda
[ ] Pump characteristic creation and data import in Wanda
[ ] Epanet scripts and skeletonizer functions
[ ] Any other future developments ??
Plotting figures
Usage
WandaToolbox supports plotting various objects to a formatted PDF, which can be included as an appendix in your report. WandaToolbox.wanda_plot supports time and location series where data is exported directly from Wanda models. It also supports adding tables, images or text blocks on pages, and supports generating system characteristics for a range of flow rates and discharge points.
Code example:
1from wandatoolbox.wanda_plot import PlotSyschar, PlotText, PlotTable, PlotImage, plot
2import matplotlib.pyplot as plt
3from matplotlib.backends.backend_pdf import PdfPages
4import pandas as pd
5import pywanda as pw
6
7model = pw.WandaModel(r'c:\Wandamodel.wdi', 'c:\Wanda 4.6\Bin\\')
8img = plt.imread('WandaToolbox\data\DELTARES_ENABLING_CMYK.png')
9df = pd.read_excel(r'example_data\syschar_test.xlsx', header=0, index_col=0)
10scenario_names = ["Current min", "Current max", "Future min", "Future max"]
11
12with PdfPages(f'Document.pdf') as pdf:
13 subplots_table = [
14 PlotTable(df, ['description', "Current min", "Current max", "Future min", "Future max"]),
15 PlotImage(img), PlotText("Yada yada yada"),
16 PlotSyschar("BOUNDQ B1", 105.0, "Supplier #1", df, 'Wanda_name',
17 scenario_names, 3, "Industry description", 'Discharge (m3/day)', 'Head (m)')
18 ]
19 plot(model, subplots_table,
20 'Main title',
21 f'Subtitle 1',
22 'Subtitle 2',
23 'Subtitle 3',
24 'Subtitle 4',
25 f'Figure number: 1',
26 company_image=plt.imread('WandaToolbox\data\DELTARES_ENABLING_CMYK.png'),
27 fontsize=10)
28 pdf.savefig()
29 plt.close()
Parameterscript
Misc. functions and tools
analysis tools
Monte-carlo analysis
Generic usage of the monte-carlo class:
1from wandatoolbox.analysis.monte_carlo import MonteCarloInputProperty, MonteCarloOutputProperty, WandaMonteCarlo
2import pywanda as pw
3import os
4
5def main():
6 wandacase_fullpath = os.path.join(os.getcwd(), "Sewage_transient.wdi")
7 wanda_bin_directory = r'c:\Program Files (x86)\Deltares\Wanda 4.6\Bin\\'
8 model = pw.WandaModel(wandacase_fullpath, wanda_bin_directory)
9 parameters = [MonteCarloInputProperty(" PIPES", "Wall roughness", 2.5 / 1000, 0.5 / 1000, "normal", True)]
10 outputs = [MonteCarloOutputProperty(" PIPES", "Pressure", keyword=True, extreme="MIN"),
11 MonteCarloOutputProperty(" PIPES", "Pressure", keyword=True, extreme="MAX")]
12 analysis = WandaMonteCarlo(model, parameters, outputs, nruns=25, n_workers=2)
13 analysis.run()
14 analysis.plot_results(filename_prefix="test", width=1000, height=800)
15 analysis.cleanup()
16
17
18if __name__ == "__main__":
19 main() # This main() method is essential due to the way Python's multiprocessing module works
The monte carlo toolset will run multiple simulation in parallel, greatly reducing the simulation time.