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 CPython 3.9 Windows x86-64

epanetmsx-2.0.0-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (155.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

epanetmsx-2.0.0-cp39-cp39-macosx_10_9_x86_64.whl (345.0 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

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

Uploaded CPython 3.8 Windows x86-64

epanetmsx-2.0.0-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (155.8 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

epanetmsx-2.0.0-cp38-cp38-macosx_10_9_x86_64.whl (345.2 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

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

Uploaded CPython 3.7m Windows x86-64

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

Uploaded CPython 3.7m Windows x86

epanetmsx-2.0.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (154.9 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

epanetmsx-2.0.0-cp37-cp37m-macosx_10_9_x86_64.whl (344.7 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

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

Uploaded CPython 3.6m Windows x86-64

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

Uploaded CPython 3.6m Windows x86

epanetmsx-2.0.0-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (154.9 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

epanetmsx-2.0.0-cp36-cp36m-macosx_10_9_x86_64.whl (344.7 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page