US-EPA-SWMM python interface
Project description
© Institute of Urban Water Management and Landscape Water Engineering, Graz University of Technology and Markus Pichler
This is an API for reading, manipulating and running SWMM-Projects
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
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
andswmm_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
)
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', convert_sections=[TIMESERIES]) # type: swmm_api.SwmmInput
# convert_sections limits the convertions during the reading of the file to the following section
# remove "convert_sections" to convert all sections
# converting sections helps manipulating the inp file
# unconverted sections will be loaded as the raw string
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 with Windows)
from swmm_api import SwmmInput
from swmm_api.input_file.sections.map_geodata import geo_section_converter
from swmm_api.input_file.macros.gis import write_geo_package, gpkg_to_swmm
inp = SwmmInput.read_file('inputfile.inp', custom_converter=geo_section_converter)
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
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
Built Distribution
Hashes for swmm_api-0.2.0.13-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5901f917d0e3a6a3b5ef82156f482b1f3c58bb4a39c5ae4e5177a4e173f3481 |
|
MD5 | 8964b396137bfa03cb1999551cd49b55 |
|
BLAKE2b-256 | 1d7a92904286fc24e5f3611863cfd800ea19464631f19d129caeadc9dad13204 |