Giter Club home page Giter Club logo

stormwater-management-model's Introduction


python wrappers for the Stormwater Management Model (SWMM5)

GitHub Actions Build Status Documentation Status License Latest PyPI version PyPI Monthly Downloads Cite our Paper

Getting started

Introducing the SWAG STORE! All Proceeds go toward the hosting/service fees related to maintaining the PySWMM Project!!! Get yourself a hoodie or coffee cup!

🆘Do you need HELP?🆘

GitHub Discussions to answer support questions related to PySWMM.

Cite our Paper

McDonnell, Bryant E., Ratliff, Katherine M., Tryby, Michael E., Wu, Jennifer Jia Xin, & Mullapudi, Abhiram. (2020). PySWMM: The Python Interface to Stormwater Management Model (SWMM). Journal of Open Source Software, 5(52), 2292, https://doi.org/10.21105/joss.02292

YouTube Training Vidoes

Setting a manhole inflow during a running simulation!

image

Overview

PySWMM is a Python language software package for the creation, manipulation, and study of the structure, dynamics, and function of complex networks.

With PySWMM you can load and manipulate USEPA Stormwater Management Models. With the development of PySWMM, control algorithms can now be developed exclusively in Python which allows the use of functions and objects as well as storing and tracking hydraulic trends for control actions.

As of version v1.1.0, PySWMM includes new features to process metadata and timeseries stored in SWMM binary output file.

Who uses PySWMM?

PySWMM is used by engineers, modelers, and researchers who want to streamline stormwater modeling optimization, controls, and post-processing results.

Goals

PySWMM is intended to provide

  • tools for the study of the structure and dynamics within USEPA SWMM5,
  • a standard programming interface and graph implementation that is suitable for many applications,
  • a rapid development environment for collaborative, multidisciplinary projects,
  • an interface to USEPA SWMM5,
  • development and implementation of control logic outside of native EPA-SWMM Controls,
  • methods for users to establish their own node inflows,
  • a coding interface to binary output files,
  • new modeling possibilities for the SWMM5 Community.

Install

Get the latest version of PySWMM from PyPI See the Quick Guide!

$ pip install pyswmm

As of version 1.3.1, pyswmm can be installed with specific versions of the SWMM engine ranging from 5.1.14 to 5.2.4 using pip extras:

$ pip install pyswmm[swmm5.2.4]

SWMM and Python Compatibility Table

pyswmm version swmm-toolkit compatibility
(SWMM engine)
python compatibility
1.0.0 - 1.1.1 0.8.2 (SWMM 5.1.13) 3.6 - 3.9
1.2.0 - 1.5.0 0.9.1 - 0.15.0 (SWMM 5.1.14 - 5.2.4)
Note: 0.11.0 (SWMM 5.2.0) only supported on windows
3.7 - 3.12

Usage

A quick example that steps through a simulation:

Examples:

See the Latte Example

from pyswmm import Simulation, Nodes, Links

with Simulation(r'Example1.inp') as sim:
    Node21 = Nodes(sim)["21"]
    print("Invert Elevation: {}". format(Node21.invert_elevation))

    Link15 = Links(sim)['15']
    print("Outlet Node ID: {}".format(Link15.outlet_node))

    # Launch a simulation!
    for ind, step in enumerate(sim):
        if ind % 100 == 0:
            print(sim.current_time,",",round(sim.percent_complete*100),"%",\
                  Node21.depth, Link15.flow)

Opening a SWMM binary output file and accessing model metadata and timeseries.

from pyswmm import Output, SubcatchSeries, NodeSeries, LinkSeries, SystemSeries

with Output('model.out') as out:
    print(len(out.subcatchments))
    print(len(out.nodes))
    print(len(out.links))
    print(out.version)

    sub_ts = SubcatchSeries(out)['S1'].runoff_rate
    node_ts = NodeSeries(out)['J1'].invert_depth
    link_ts = LinkSeries(out)['C2'].flow_rate
    sys_ts = SystemSeries(out).rainfall

Bugs

Our issue tracker is at https://github.com/pyswmm/pyswmm/issues. Please report any bugs that you find. Or, even better, fork the repository on GitHub and create a pull request. All changes are welcome, big or small, and we will help you make the pull request if you are new to git (just ask on the issue).

Contributing

Please check out our Wiki https://github.com/pyswmm/pyswmm/wiki for more information on contributing, including an Author Contribution Checklist.

License

Distributed with a BSD2 license; see LICENSE.txt:

Copyright (C) 2014-2024 PySWMM Developers
Community-Owned See AUTHORS and CITATION.cff

stormwater-management-model's People

Contributors

abhiramm7 avatar aerispaha avatar andychase avatar bemason avatar bemcdonnell avatar cbuahin avatar dleutnant avatar goanpeca avatar h20melon avatar jaorquina avatar jennwuu avatar jubilee2 avatar karosc avatar katmratliff avatar lrntct avatar lrossman avatar michaeltryby avatar michelleannesimon avatar mingda-zhang avatar samhatchett avatar waterdesk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stormwater-management-model's Issues

Create conda packages

I think creating conda packages for this different products would definitely allow a bigger audience working on engineering and scientific applications. I would like to create conda packages for the different projects hosted at open water analytics.

Are you familiar with conda? and Anaconda?


Since this is an open source and community maintained version of the swmm engine, I am thinking of naming this (conda) package as openswmm or open-swmm. Once the packages are ready one could cross platform install swmm as

conda install open-swmm (or whatever name we think is best)

Thougths?


Using conda would really increase outreach f this prohect as it would allow for easy creation isolated environments for development, work and testing (travis ci etc...)

missing makefile for Shared object Library

Hi,
Is there a reason why there is no makefile for creating a shared object library of swmm on Linux?
If I uncomment #define SOL in swmm5.c, then none of the makefiles work in _build/GNU-DLL or _build/Linux

Decoupling the codebase a bit: headers

This might not be a priority, or we might lack resources to pursue this endeavor. I think that having a headers.h which itself imports almost all (have not checked) headers in the project makes the process of decoupling the codebase more difficult. I argue it would be better to import the headers that are strictly required for a given file. and this could be a first step in the decoupling/unit-testing process

Cmake: Building for OSX issues

Hi @samhatchett, I am trying to get this build for OSX and in the process I am getting the following warnings:

Building C object CMakeFiles/swmm.dir/Users/gpena-castellanos/continuum/Stormwater-Management-Model/src/roadway.c.o
/Users/gpena-castellanos/continuum/Stormwater-Management-Model/src/roadway.c:27:37: warning: useless storage class specifier in empty declaration [enabled by default]
 static enum RoadSurface {PAVED = 1, GRAVEL};

Building C object CMakeFiles/swmm.dir/Users/gpena-castellanos/continuum/Stormwater-Management-Model/src/swmm5.c.o
/Users/gpena-castellanos/continuum/Stormwater-Management-Model/src/swmm5.c: In function ‘swmm_open’:
/Users/gpena-castellanos/continuum/Stormwater-Management-Model/src/swmm5.c:313:4: warning: implicit declaration of function ‘_fpreset’ [-Wimplicit-function-declaration]
    _fpreset(); 

Building C object CMakeFiles/swmm.dir/Users/gpena-castellanos/continuum/Stormwater-Management-Model/src/toolkitAPI.c.o
/Users/gpena-castellanos/continuum/Stormwater-Management-Model/src/toolkitAPI.c: In function ‘swmm_setSimulationDateTime’:
/Users/gpena-castellanos/continuum/Stormwater-Management-Model/src/toolkitAPI.c:98:4: warning: implicit declaration of function ‘floor’ [-Wimplicit-function-declaration]
    TotalDuration = floor((EndDateTime - StartDateTime) * SECperDAY);
    ^
/Users/gpena-castellanos/continuum/Stormwater-Management-Model/src/toolkitAPI.c:98:20: warning: incompatible implicit declaration of built-in function ‘floor’ [enabled by default]
    TotalDuration = floor((EndDateTime - StartDateTime) * SECperDAY);

And finally, this error:

Linking C shared library bin/libswmm.dylib
Undefined symbols for architecture x86_64:
  "__fpreset", referenced from:
      _swmm_open in swmm5.c.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [bin/libswmm.dylib] Error 1
make[1]: *** [CMakeFiles/swmm.dir/all] Error 2
make: *** [all] Error 2

Thoughts?

Should we or shouldn't we save an inp file from SWMM?

Hi,

I am trying to assimilate the intended workflow with the swwm python tools. Questions I could not answer by scanning the source tree and the docs there:

  1. How should tools/ by installed for the python search path?

  2. Are this tools within a module? e.g. can one do from .tools import swwm-reader?

  3. What python versions are supported? python 3?

I have developed a random network generator and I would be happy to make it compatible with your tools if I understand how to use them :D

Thanks

Node Lateral Inflow Bug

@fmyers caught a small bug that is almost harmless.

In routing.c under routing_execute() there is a loop that sets the oldLatFlow to the newLatFlow for all the nodes:

    // --- initialize lateral inflows at nodes
    for (j = 0; j < Nobjects[NODE]; j++)
    {
        Node[j].oldLatFlow  = Node[j].newLatFlow;
        Node[j].newLatFlow  = 0.0;
    }

then all the lateral inflows are added to the nodes

Then it jumps down and loops through all the nodes again calling a function in nodes.c node_setOldHydState()

            for (j = 0; j < Nobjects[NODE]; j++)
            {
                node_setOldHydState(j);
                node_initInflow(j, routingStep);
            }

where node_setOldHydState() also moves OldLatFlow to NewLatFlow

void node_setOldHydState(int j)
//
//  Input:   j = node index
//  Output:  none
//  Purpose: replaces a node's old hydraulic state values with new ones.
//
{
    Node[j].oldDepth    = Node[j].newDepth;
    Node[j].oldLatFlow  = Node[j].newLatFlow; // <- Not Needed (according to Lew and Fred).
    Node[j].oldVolume   = Node[j].newVolume;
}

GitHub Branching Model....

I'm not convinced we are using the best branching model for this project. PySWMM brings everything back to the master branch, which I find helpful and simple. This project is inherently different since (at least at the moment) we are working toward multiple releases of SWMM (5.1.13 - bug fixes and 5.2.0 - the new API).

Seems like people that are new to the project could become quickly frustrated. Thoughts?

Makefile for Linux

It would be useful to be able to build the SWMM source as an command line executable in a Linux environment. A Linux build will make it more convenient to run SWMM on web servers; this could make it easier to scale up model runs on powerful machines (on AWS or whatever you prefer) without having to pay for Windows virtual environments.

I've created a simple Linux Makefile that I've successfully tested on a Digital Ocean droplet running Ubuntu 14.04. This is in my linux branch.

Set Simulation End Time

From toolkitAPI.C... The EndDateTime is set correct but the TotalDuration was not updated. Probably need to add a function to re-validate the values before the simulation starts

// --- compute total duration of simulation in seconds
TotalDuration = floor((EndDateTime - StartDateTime) * SECperDAY);

Add Unit tests (to API)

I will start diving more and more with the codebase of SWMM in the following months (~6 months) and one of the things I have been looking around is for unit test libraries/frameworks for C.

This discuss some options.

https://sites.google.com/site/ruslancray/lab/projects/cunittestingframeworkswithcodecoveragemetrics/c-unit-testing

I have no experience with any of the one mentioned but with CI in place, its a good opportunity to try some options with some part of SWMM. We will need to decouple modules a bit, but for instance the shape.c seems like a good candidate (pretty small and just some methods to test) to start with.

What could be some loose list of requirements? for example,

  • Test framework should be for C and C++, in case the code uses C++ at some point in the future?
  • If it is a C only framework, tests would be much easier and simpler to write

CUnit, Check seem to be the classic ones, but https://github.com/Snaipe/Criterion looks promising. CMocka also looks simple. Or we could use a C++ unit testing framework like google test, but that would require C++ knowledge for running the tests.

Steps:

  1. Decouple the code of shape.c so it can be compiled as a standalone thing (if not possible already)
  2. Write some basic unittests for the file using some of the tools/frameworks available.
  3. Pick something to work with :-p

Thoughts @bemcdonnell, @michaeltryby ?

Create some testing models

We need a set of models that will be run in CI for regression tests.

@aerispaha, @mehmetbercan, @rkertesz, @abhiramm7 would any of (or all of, or some of) you guys be interested in making a set of simple models that isolate some process thing? Ideally these models will run really fast and encompass all of the necessary components without the need for support files.

For example:

  • RTK's
  • Subcatchment Runoff
  • LID's
  • Controls
  • GW/Aquifers
  • (dare I say) Water Quality

Autoformat code

We could use something like https://clang.llvm.org/docs/ClangFormat.html, once tests are implemented, to keep the code base in a consistent state. Also this would be enforced on the CI. The idea is to not waste developers time in style reviews but in code reviews, what the code is actually doing!

NCDC CDO 15 minute precipitation data units not recognized

NCDC CDO 15 minute precipitation data product can be ordered in metric (MM) or standard units (HI, HT). SWMM does not recognize when the units of the supplied data file are in MM it assumes they are either in HI or HT hundred or tenths of an inch respectively. It appears that the rain units attribute for the rain gage selected by the user are being ignored.

This bug is further compounded because the units flag is not being set correctly when ordering data from NCDC CDO. According to the specification 15 Minute Precipitation Data Documentation dated February 2016, the units flag reflects the the units in which the data values are given. This, however, is not the case in practice.

A potential solution to this problem would be to check for the unit flag in the data file. Which currently isn't happening. Another possible solution would be to honor the user indicated units provided in the rain units attribute.

Regression Testing - SWMM

Automated regression testing would be a great feature as SWMM is moved toward open source development. The EPANET development team has spent a lot of time on this issue (OpenWaterAnalytics/EPANET#16 OpenWaterAnalytics/EPANET#54). They have implemented a build pass/fail testing protocol that uses Travis-CI testing framework. I've been a bit out of touch with what they have recently been up to, however, they have decided on a set of canonical models that are used for the regression testing. Travis-CI pulls down any committed code and follows the routine you ask it to (I.e. Compiles your code, runs the models (Pyswmm in our case), "mathematically" diffs the outputs (Python wrapper to swmm outputAPI), and returns a true or false for pass/fail, respectively.)

Two levels of regression testing would be nice. 1) a tool that works with Travis-CI (returns a pass fail) and 2) a tool that gives you the details. The latter could help us in justifying any changes to the model that you wanted.

Between Pyswmm and the Python outputAPI wrapper, the tools are already available to get this up and running. However, the SWMM community might benefit from deciding on how the time series "diff" is performed between new engine and old engine.

I can put together a small roadmap for this once the discussion begins.

You all may have some thoughts on the issue?
@samhatchett @michaeltryby @rkertesz @fmyers @lmontest

Cmake: Build for Linux issues

Travis-CI build is failing on Linux due to cmake build.

$ cmake ..
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at CMakeLists.txt:28 (target_compile_definitions):
  Unknown CMake command "target_compile_definitions".

<malloc.h> posix portability

all #include <malloc.h> lines should be replaced by <stdlib.h> as the former is not always available on all systems.

Epanet and SWMM common codebase

As discussed in #57 there is some common ground between Epanet and SWMM that could be unified in a single codebase (additional separate library/repo?)

Let's use this issue to discuss how we could achieve this. There is the issue of making SWMM more OO oriented (using C++) as Epanet is already moving in that direction, I don't know if that is also a separate issue/discussion but I guess we can have that talk here.

Please share your thoughts @samhatchett , @bemcdonnell, @michaeltryby

Fix swmm_setNodeInflow

Disaggregate the input file parser function

int inflow_readExtInflow(char* tok[], int ntoks)

into two pieces.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.