Skip to main content

US-EPA-SWMM python interface

Project description

© Institute of Urban Water Management and Landscape Water Engineering, Graz University of Technology and Markus Pichler

Getting started

PyPI pipeline status License: MIT docs

PyPI - Downloads PyPI - Downloads PyPI - Downloads

DOI Gitter

With this package you can read INP-files, manipulate them and write new ones. You can run swmm within the python api. And you can read the RPT- and OUT-files as a pandas DataFrame for further analysis.

This package is based on the command line SWMM syntax. (see Appendix D in the SWMM User Manual 5.1)

Install the package

pip install swmm-api

Documentation

Link to the documentation of the api and some example jupyter notebook.

Alternative packages

R-language:

python:

  • swmmio / docs / pypi / github /
  • GisToSWMM5 / github / converting gis data to swmm model (also possible with swmm_api: swmm_api.input_file.macro_snippets.gis_standard_import and swmm_api.input_file.macro_snippets.gis_export)
  • swmmtoolbox / github / Thanks to Tim Cera for this package! I used his package to understand the .out-files but completely rewrote the reading process in this package.
  • swmmnetwork / github / create graph network from swmm model (see swmm_api.input_file.macros.inp_to_graph)
  • SWMMOutputAPI / github / read the output file (see swmm_api.output_file.out) / (OpenWaterAnalytics)
  • swmm-pandas / pypi / equal functionalities to this package, but not feature complete
  • swmmout / pypi / docs / simular to swmmtoolbox and SWMMOutputAPI
  • swmmtonetcdf / pypi / github

Other SWMM-related packages

python:

  • pyswmm / pypi / github / RTC, etc. / based on swmm-toolkit (OpenWaterAnalytics)
  • swmm-toolkit / pypi / github / by Michael Tryby (OpenWaterAnalytics)
  • SWMM5 / pypi / github / simular approach to swmm-toolkit (by Assela Pathirana)
  • SWMM-xsections-shape-generator / pypi / tool to generate custom shapes (by me)
  • SWMM_EA / pypi / usage of genetic algorithms with SWMM (by Assela Pathirana)

Read, manipulate and write the INP-File

Read the INP-File

from swmm_api.input_file.section_labels import TIMESERIES
from swmm_api import read_inp_file

inp = read_inp_file('inputfile.inp')  # type: swmm_api.SwmmInput

sec_timeseries = inp[TIMESERIES]  # type: swmm_api.input_file.helpers.InpSection
ts = inp[TIMESERIES]['regenseries'].frame  # type: pandas.Series

Manipulate the INP-File

from swmm_api import read_inp_file, SwmmInput
from swmm_api.input_file.section_labels import JUNCTIONS

inp = read_inp_file('inputfile.inp')  # type: swmm_api.SwmmInput
# or 
inp = SwmmInput.read_file('inputfile.inp')

inp[JUNCTIONS]['J01'].elevation = 210

Write the manipulated INP-File

inp.write_file('new_inputfile.inp')

see examples/inp_file_reader.ipynb

see examples/inp_file_structure.ipynb

see examples/inp_file_macros.ipynb

Run SWMM

from swmm_api import swmm5_run
swmm5_run('new_inputfile.inp')

Read the OUT-File

from swmm_api import read_out_file
out = read_out_file('new_inputfile.out')   # type: swmm_api.SwmmOut
df = out.to_frame()  # type: pandas.DataFrame

see examples/out_file_reader.ipynb

Read the RPT-File

from swmm_api import read_rpt_file
rpt = read_rpt_file('new_inputfile.rpt')  # type: swmm_api.SwmmReport
node_flooding_summary = rpt.node_flooding_summary  # type: pandas.DataFrame

see examples/rpt_file_reader.ipynb

GIS interactions

geopandas and its requirements (Shapely, pyproj, Rtree) must be installed! (not that easy on Windows)

from swmm_api import SwmmInput
from swmm_api.input_file.macros.gis import write_geo_package, gpkg_to_swmm

inp = SwmmInput.read_file('inputfile.inp')

coords = inp.COORDINATES.geo_series  # type: geoandas.GeoSeries with points for all nodes
vertices = inp.VERTICES.geo_series  # type: geoandas.GeoSeries with lines for all links
polygons = inp.POLYGONS.geo_series  # type: geoandas.GeoSeries with polygons for all subcatchments

# create geopackage of all objects in inp file
write_geo_package(inp, gpkg_fn='geopackage.gpkg', driver='GPKG', label_sep='.', crs="EPSG:32633")

# read above written geopackage and convert it to inp-data
inp_new = gpkg_to_swmm('geopackage.gpkg', label_sep='.')
inp_new.write_file('new_inputfile.inp')

MORE INFORMATION COMING SOON

Cite as

Pichler, Markus. (2022). swmm_api: API for reading, manipulating and running SWMM-Projects with python (0.2.0.16). Zenodo. https://doi.org/10.5281/zenodo.5862141

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swmm-api-0.3a12.tar.gz (144.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swmm_api-0.3a12-py3-none-any.whl (166.8 kB view details)

Uploaded Python 3

File details

Details for the file swmm-api-0.3a12.tar.gz.

File metadata

  • Download URL: swmm-api-0.3a12.tar.gz
  • Upload date:
  • Size: 144.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for swmm-api-0.3a12.tar.gz
Algorithm Hash digest
SHA256 8b4a3c76f5f0ff34fbe4153b622b84e0503da6dde1733c0842559d4b78f9d5a0
MD5 073aa505ea93d7a7035ba1dae6dcf0e6
BLAKE2b-256 cbe992f6f14bded5de655870e2a6738a4f4928608fb3c78a2f077f14a546e3bb

See more details on using hashes here.

File details

Details for the file swmm_api-0.3a12-py3-none-any.whl.

File metadata

  • Download URL: swmm_api-0.3a12-py3-none-any.whl
  • Upload date:
  • Size: 166.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for swmm_api-0.3a12-py3-none-any.whl
Algorithm Hash digest
SHA256 008981f0044c36ae090573a37b6918f13ebede1c9d180ca22566675366396df9
MD5 a1a022cc670f286d8da66ab4dfddd382
BLAKE2b-256 e4a9d1c79ec8930f6faaa577de3ad2e97814d4a2a285e90c6724ff0efd37832e

See more details on using hashes here.

Supported by

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