A Python package to aggregate and reduce water distribution network models
MAGNets (Model AGgregation and reduction of water distribution Networks) is a Python package designed to perform the reduction and aggregation of water distribution network models. The software is capable of reducing a network around an optional operating point and allows the user to customize which junctions they would like retained in the reduced model. MAGNets' reduction approach is based on the variable elimination method proposed by Ulanicki et al (1996).
Python distributions, such as Anaconda, are recommended to manage the Python environment as they already contain (or easily support the installation of) many Python packages (such as SciPy and NumPy) that are used in the MAGNets package.
To install MAGNets, run this command in your terminal:
pip install magnets
This is the preferred method to install MAGNets, as it will always install the most recent stable release.
If you don’t have pip installed, this Python installation guide can guide you through the process.
The sources for MAGNets can be downloaded from the Github repo.
You can either clone the public repository:
git clone git://github.com/meghnathomas/magnets
Or download the tarball:
curl -OJL https://github.com/meghnathomas/magnets/tarball/master
Once you have a copy of the source, you can install it with:
python setup.py install
Use this jupyter notebook to run some useful examples of MAGNets. Additional example codes and 12 test networks can be found in the examples and publications folders.
To use MAGNets in a project, open a Python IDE and import the package using the following command:
import magnets as mg
The user can then call on the following function to reduce a hydraulic model of a water distribution network.
wn2 = mg.reduction.reduce_model(inp_file, op_pt, nodes_to_keep, max_nodal_degree)
The parameters of the reduce_model
function are described as follows:
inp_file
: the EPANET-compatible .inp file of the water distribution network model.op_pt
: (optional, default = 0) the operating point, or the reporting time step of the hydraulic simulation at which the non-linear headloss equations are linearized.nodes_to_keep
: (optional, default = []) a list of nodes the user wishes to retain in the reduced model.max_nodal_degree
: (optional, default = None) the maximum nodal degree of nodes being removed from the model. The nodal degree of a node is equal to the number of pipes incident to the node.
wn2
contains the water network model object of the reduced model. A .inp file of the reduced model is also written into the directory that contains the .inp file of the original network.
MAGNets has been tested on Python version 3.6, 3.7, and 3.8. It requires the installation of the following dependencies:
- wntr >= 0.3.0
- numpy
- scipy
- pandas
- matplotlib
- networkx
- cycler
- decorator
- kiwisolver
- Pillow
- pyparsing
- python-dateutil
- pytz
- six
Meghna Thomas - [email protected]
Lina Sela - [email protected]
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.