Skip to main content

A thin wrapper for epanet-msx toolkit

Project description

epanet-msx-python

The python wrapper for epanet-msx.

Installation

  • Python version: 3.6+
pip install epanetmsx

Usage

Most of the functions are used in the same fashion as they would be in the C API, however it is not necessary to check the return values for an error code anymore. If an error occurs, an exception will be thrown stating the error code. The only major difference in calling functions using the python wrapper for epanet-msx is the way that values are returned. If a function in the C API took in a pointer as a parameter that was intended to be used as an output, it now will be returned by the function. For example:

// In C
int MSXgetindex(int type, char *id, int *index);
# In Python
index = msx.getindex(type, id)

If there are multiple pointers given that will be used for output. Python handles it like this:

// In C
int MSXgetspecies(int index, int *type, char *units, double *aTol, double *rTol);
# In Python
type, units, aTol, rTol = msx.getspecies(index)

Currently, there is only one function that uses a pointer variable for both input and output and it is the "t" variable in MSXstep. Example usage:

t, tleft = msx.step(t)

Check out this example for more details.

Development

Prerequisites

  • Install Cmake
  • Install Swig
  • pip install scikit-build

Ensure the epanet-msx subproject is initialized by running git submodule update --init. Then run and running the following commands (only run clean if you can run bash scripts). The following method uses scikit-build to invoke cmake for compiling and linking the shared libaries, and builds a python wheel.

./scripts/clean.sh
python setup.py sdist bdist_wheel
pip install dist/*.whl

There is also a script called build that will run the three commands from above. (build.sh should be called from the root)

./scripts/build.sh

Tests

There is a tests directory with a file that can be run using pytest for unit tests. All of the tests that are currently available are very basic, and mainly only test functions that are not utilized in either of the examples. Both of the examples are working, and therefore all of the critical functions that those use are working. It is more important that the example functions are running properly than the tests passing since the examples use more critical functions. To run the tests:

pytest tests/test_msx.py

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

epanetmsx-2.0.0.tar.gz (192.2 kB view hashes)

Uploaded source

Built Distributions

epanetmsx-2.0.0-cp39-cp39-win_amd64.whl (189.4 kB view hashes)

Uploaded cp39

epanetmsx-2.0.0-cp38-cp38-win_amd64.whl (189.1 kB view hashes)

Uploaded cp38

epanetmsx-2.0.0-cp37-cp37m-win_amd64.whl (193.1 kB view hashes)

Uploaded cp37

epanetmsx-2.0.0-cp37-cp37m-win32.whl (188.6 kB view hashes)

Uploaded cp37

epanetmsx-2.0.0-cp36-cp36m-win_amd64.whl (193.2 kB view hashes)

Uploaded cp36

epanetmsx-2.0.0-cp36-cp36m-win32.whl (188.7 kB view hashes)

Uploaded cp36

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page