swmm-api


Nameswmm-api JSON
Version 0.4.42 PyPI version JSON
download
home_pagehttps://gitlab.com/markuspichler/swmm_api
SummaryAPI for reading, manipulating and running US-EPA-SWMM-Projects
upload_time2024-04-16 10:08:09
maintainerNone
docs_urlNone
authorMarkus Pichler
requires_python>=3.7
licenseMIT
keywords swmm environment civil_engineering api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            © [Institute of Urban Water Management and Landscape Water Engineering](https://www.sww.tugraz.at), [Graz University of Technology](https://www.tugraz.at/home/) and [Markus Pichler](mailto:markus.pichler@tugraz.at)

# 💡 Getting started

[![PyPI](https://img.shields.io/pypi/v/swmm-api.svg?logo=pypi&logoColor=white)](https://pypi.python.org/pypi/swmm-api)
[![pipeline status](https://gitlab.com/markuspichler/swmm_api/badges/main/pipeline.svg)](https://gitlab.com/markuspichler/swmm_api/-/commits/main)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![docs](https://img.shields.io/static/v1.svg?label=&message=documentation&color=blue&logo=readthedocs&logoColor=white)](https://markuspichler.gitlab.io/swmm_api)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7054804.svg)](https://zenodo.org/doi/10.5281/zenodo.5862140)
[![Latest Release](https://gitlab.com/markuspichler/swmm_api/-/badges/release.svg)](https://gitlab.com/markuspichler/swmm_api/-/releases)
[![Matrix](https://img.shields.io/matrix/swmm-api-python%3Amatrix.org?style=flat&logo=matrix)](https://matrix.to/#/#swmm-api-python:matrix.org)

[![PyPI - Downloads](https://img.shields.io/pypi/dd/swmm-api)](https://pypi.python.org/pypi/swmm-api)
[![PyPI - Downloads](https://img.shields.io/pypi/dw/swmm-api)](https://pypi.python.org/pypi/swmm-api)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/swmm-api)](https://pypi.python.org/pypi/swmm-api)


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.2](https://www.epa.gov/system/files/documents/2022-04/swmm-users-manual-version-5.2.pdf))

## Introduction

The swmm-api package is a powerful tool for modellers and researchers who use the Storm Water Management Model (SWMM). This software enables the manipulation and analysis of SWMM models, both in terms of the input data and the simulation results. The package is written in Python, making it an attractive option for those who use this language for data management and advanced analysis.

One of the key features of swmm-api is its ability to read and write SWMM import-files (.inp), allowing the user to manipulate the model structure and input data. The package also has the capability to run the SWMM model within the Python environment, providing users with quick access to simulation results. Furthermore, swmm-api can read both the report (.rpt) and binary output-files (.out), presenting the results as a Pandas DataFrame for easy analysis. The ability to read binary hotstart-files (.hst) is also included, which enables the acceleration of simulation time by using initial values stored in the file.

The swmm-api package is designed to be flexible and user-friendly, with an object-oriented structure that is lightweight and fast. The package is based on the SWMM command line syntax, making it easy to use for those familiar with this model. Additionally, swmm-api has the ability to interact with GIS data, making it a valuable tool for modellers working with spatial data.

## Install the package
```bash
pip install swmm-api
```

... to install the package with all dependencies for macros use:

```bash
pip install swmm-api[macros]
```

... to install the package with all dependencies for GIS I/O use (for Linux or for Windows using python >= 3.10):

```bash
pip install swmm-api[gis]
```

... and to install the package with all dependencies for macros and GIS I/O use (for Linux or for Windows using python >= 3.10):

```bash
pip install swmm-api[full]
```

To add the GIS functionality on **Windows**, I recommend using python version >= 3.10 or with [Mamba](https://github.com/conda-forge/miniforge#mambaforge)
 (or [miniconda](https://docs.conda.io/en/latest/miniconda.html) or [Anaconda](https://www.anaconda.com/))
and run `mamba install geopandas` to install the GIS dependencies (see [GeoPandas](https://geopandas.org/en/stable/getting_started.html)).

Here you can see which packages are getting installed:

| packages                       | required | macros | gis | full | docs |
|:------------------------------:|:--------:|:------:|:---:|:----:|:----:|
| pandas                         | x        | x      | x   | x    | x    |
| tqdm                           | x        | x      | x   | x    | x    |
| networkx                       |          | x      |     | x    | x    |
| fastparquet                    |          | x      |     | x    | x    |
| matplotlib                     |          | x      |     | x    | x    |
| SWMM_xsections_shape_generator |          | x      |     | x    | x    |
| pyswmm                         |          | x      |     | x    | x    |
| Shapely                        |          |        | x   | x    | x    |
| pyproj                         |          |        | x   | x    | x    |
| Rtree                          |          |        | x   | x    | x    |
| geopandas                      |          |        | x   | x    | x    |
| sphinx                         |          |        |     |      | x    |
| nbsphinx                       |          |        |     |      | x    |
| recommonmark                   |          |        |     |      | x    |
| pydata_sphinx_theme            |          |        |     |      | x    |

## 📖 Documentation
[Link](https://markuspichler.gitlab.io/swmm_api) to the documentation of the api and some example jupyter notebook.

[Here](https://gitlab.com/markuspichler/swmm_api/-/tree/main/examples) are example files for other use-cases.

## Read, manipulate and write the INP-File

### Read the INP-File

```python
from swmm_api import read_inp_file, SwmmInput

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

```

### Getting information

```python
from swmm_api.input_file.section_labels import TIMESERIES

# getting a specific section of the inp-file

sec_timeseries = inp[TIMESERIES]  # type: swmm_api.input_file.helpers.InpSection
# or
sec_timeseries = inp.TIMESERIES  # type: swmm_api.input_file.helpers.InpSection

# getting a specific timeseries as pandas.Series
ts = inp[TIMESERIES]['regenseries'].pandas  # type: pandas.Series
```

### Manipulate the INP-File

```python
from swmm_api.input_file.section_labels import JUNCTIONS

# setting the elevation of a specific node to a new value

inp[JUNCTIONS]['J01'].elevation = 210
# or
inp.JUNCTIONS['J01'].elevation = 210
# or
inp.JUNCTIONS['J01']['elevation'] = 210
```

### Write the manipulated INP-File
```python
inp.write_file('new_inputfile.inp')
```

see [examples/inp_file_reader.ipynb](https://gitlab.com/markuspichler/swmm_api/-/blob/main/examples/inp_file_reader.ipynb)

see [examples/inp_file_structure.ipynb](https://gitlab.com/markuspichler/swmm_api/-/blob/main/examples/inp_file_structure.ipynb)

see [examples/inp_file_macros.ipynb](https://gitlab.com/markuspichler/swmm_api/-/blob/main/examples/inp_file_macros.ipynb)




## Run SWMM

Run SWMM with a specified executable.

```python
from swmm_api import swmm5_run
swmm5_run('new_inputfile.inp', swmm_lib_path=r'C:\path\to\runswmm.exe')
```

Or run SWMM with [pyswmm](https://github.com/OpenWaterAnalytics/pyswmm). This would be platform independent as pyswmm is compiled for all platforms.
Additionally, you gain the advantage of a progress bar.

```python
from swmm_api import swmm5_run
swmm5_run('new_inputfile.inp', progress_size=100)
```

```
swmm5 C:\path\to\new_inputfile.inp:  77%|███████▋  | 77/100 [00:03<00:01, 22.36it/s, 2007-02-16 08:46:27]
```

## Read the OUT-File
```python
from swmm_api import read_out_file, SwmmOutput

out = read_out_file('new_inputfile.out')   # type: swmm_api.SwmmOut
# or
out = SwmmOutput('new_inputfile.out')

df = out.to_frame()  # type: pandas.DataFrame
```
see [examples/out_file_reader.ipynb](https://gitlab.com/markuspichler/swmm_api/-/blob/main/examples/out_file_reader.ipynb)


## Read the RPT-File
```python
from swmm_api import read_rpt_file, SwmmReport

rpt = read_rpt_file('new_inputfile.rpt')  # type: swmm_api.SwmmReport
# or
rpt = SwmmReport('new_inputfile.rpt')

node_flooding_summary = rpt.node_flooding_summary  # type: pandas.DataFrame
```
see [examples/rpt_file_reader.ipynb](https://gitlab.com/markuspichler/swmm_api/-/blob/main/examples/rpt_file_reader.ipynb)

## 🗺️ GIS interactions

[`geopandas`](https://geopandas.org/) and its requirements (`Shapely`, `pyproj`, `Rtree`) must be installed! (Use python version >3.10 or conda (Anaconda|miniconda) on Windows)

```python
from swmm_api import SwmmInput
from swmm_api.input_file.macros.gis import write_geo_package, gpkg_to_swmm, complete_vertices

inp = SwmmInput('inputfile.inp')

coords = inp.COORDINATES.geo_series  # type: geoandas.GeoSeries with points for all nodes

complete_vertices(inp)  # this will insert the start and end node points into the link vertices.
# this function is automatically called in `write_geo_package`, but is needed if the geo-series of vertices is used directly.

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')
```

## ⚠️ Be Aware!

> As python is case-sensitive this API is also case-sensitive, but SWMM is case-insensitive. 
> This is important for the naming of the objects. 
> For example, you could create a junction 'a' and 'A' with this API, but SWMM would only consider one and ignore the other.

AND

> This package uses `utf-8` as default encoding for the file I/O (reading and writing inp, rpt and out files.)
> Every function to read a file has the option to define a custom encoding (for example Windows uses this as default for german `encoding='iso-8859-1'`).

But one can set a default encoding for the package using:
```python
from swmm_api import CONFIG
CONFIG['encoding'] = 'iso-8859-1'
```

---

This documentation will be continuously extended and enhanced. 
If you have any question, don't hesitate to write the author and email or create an issue on GitLab or GitHub.

MORE INFORMATION COMING SOON

## Cite as

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

## Publications mentioning swmm-api

1. Baumann, H., Ravn, N. H., & Schaum, A. (2022). Efficient hydrodynamic modelling of urban stormwater systems for real-time applications. *Modelling, 3(4)*, 464–480. <https://doi.org/10.3390/modelling3040030>
2. Farina, A., Di Nardo, A., Gargano, R., & Greco, R. (2022). Assessing the environmental impact of combined sewer overflows through a parametric study. *EWaS5*, 8. <https://doi.org/10.3390/environsciproc2022021008>
3. Schilling, J., & Tränckner, J. (2022). Generate_swmm_inp: An open-source qgis plugin to import and export model input files for swmm. *Water, 14(14)*, 2262. <https://doi.org/10.3390/w14142262>
4. Zhang, Z., Tian, W., & Liao, Z. (2023). Towards coordinated and robust real-time control: A decentralized approach for combined sewer overflow and urban flooding reduction based on multi-agent reinforcement learning. *Water Research, 229*, 119498. <https://doi.org/10.1016/j.watres.2022.119498>
5. van der Werf, J. A., Kapelan Z., Langeveld, J. G. (2023). Predictive heuristic control: inferring risks from heterogeneous nowcast accuracy. *Water Sci Technol* 2023; 87 (4): 1009–1028. <https://doi.org/10.2166/wst.2023.027>
6. Farina, A., Di Nardo, A., Gargano, R., Van Der Werf, J. A., & Greco, R. (2023). A simplified approach for the hydrological simulation of urban drainage systems with SWMM. Journal of Hydrology, 623, 129757. <https://doi.org/10.1016/j.jhydrol.2023.129757>
7. Wicki, T. (2022). Effekt der Einzugsgebietsmodellierung auf  die Abflusssimulation im urbanen Gebiet. Master thesis. Paris Lodron-Universität Salzburg. <https://unigis.at/files/Mastertheses/Full/106726.pdf>
8. Ryrfors Wien, C. (2023). Nature-based solution retrofit in an urban catchment for CSO reduction (Master's thesis, NTNU). <https://hdl.handle.net/11250/3108487>


## Alternative packages

- **swmmr** / R-language / [GitHub](https://github.com/dleutnant/swmmr) / [cran](https://cran.r-project.org/web/packages/swmmr/index.html)
- **MatSWMM** / Matlab / [GitHub](https://github.com/gandresr/MatSWMM) 
- **swmmNode** / TypeScript / [GitHub](https://github.com/swmm-js/swmmNode)

---

- **swmmio** / [docs](https://swmmio.readthedocs.io/en/latest/) / [pypi](https://pypi.org/project/swmmio/) / [GitHub](https://github.com/aerispaha/swmmio) / simular to this package but more high-level approach (= slower for specific tasks)
- **GisToSWMM5** / [GitHub](https://github.com/AaltoUrbanWater/GisToSWMM5) / 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](https://github.com/timcera/swmmtoolbox) / 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](https://github.com/austinorr/swmmnetwork) / create graph network from swmm model (see `swmm_api.input_file.macros.inp_to_graph`)
- **SWMMOutputAPI** / [GitHub](https://github.com/bemcdonnell/SWMMOutputAPI) / read the output file (see `swmm_api.output_file.out`) / (OpenWaterAnalytics)
- **swmm-pandas** / [pypi](https://pypi.org/project/swmm-pandas/) / equal functionalities to this package, but not feature complete
- **swmmout** / [pypi](https://pypi.org/project/swmmout/) / [docs](https://swmmout.readthedocs.io/en/latest/) / simular to `swmmtoolbox` and `SWMMOutputAPI`
- **swmmtonetcdf** / [pypi](https://pypi.org/project/swmmtonetcdf/) / [GitHub](https://github.com/cbuahin/swmmtonetcdf)
- **hymo** / [GitHub](https://github.com/lucashtnguyen/hymo) Input and Report Reader (Lucas Nguyen)
- **shmm** / [GitHub](https://github.com/lucashtnguyen/shmm) Input Reader (Lucas Nguyen)
- **swmmreport** / [GitHub](https://github.com/lucashtnguyen/swmmreport) Report Reader (Lucas Nguyen)
- **swmmdoodler** / [GitHub](https://github.com/Geosyntec/swmmdoodler)

### Other SWMM-related python-packages

- **pyswmm** / [pypi](https://pypi.org/project/pyswmm/) / [GitHub](https://github.com/OpenWaterAnalytics/pyswmm) / [Website](https://www.pyswmm.org) / RTC, etc. / based on swmm-toolkit (OpenWaterAnalytics)
- **swmm-toolkit** / [pypi](https://pypi.org/project/swmm-toolkit/) / [GitHub](https://github.com/OpenWaterAnalytics/swmm-python) / by Michael Tryby (OpenWaterAnalytics)
- **SWMM5** / [pypi](https://pypi.org/project/SWMM5/) / [GitHub](https://github.com/asselapathirana/swmm5-python) / simular approach to swmm-toolkit (by Assela Pathirana)
- **SWMM-xsections-shape-generator** / [pypi](https://pypi.org/project/SWMM-xsections-shape-generator/) / tool to generate custom shapes (by me)
- **SWMM_EA** / [pypi](https://pypi.org/project/SWMM5_EA/) / usage of genetic algorithms with SWMM (by Assela Pathirana)
- **OSTRICH-SWMM** / [GitHub](https://github.com/ubccr/ostrich-swmm) / OSTRICH optimization software toolkit with SWMM

            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.com/markuspichler/swmm_api",
    "name": "swmm-api",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "swmm, environment, civil_engineering, api",
    "author": "Markus Pichler",
    "author_email": "Markus Pichler <markus.pichler@tugraz.at>",
    "download_url": "https://files.pythonhosted.org/packages/27/6d/54c38a095cca176d8ceb3afaa5f2482195f93c3c9dbb29cc4d9f37236678/swmm-api-0.4.42.tar.gz",
    "platform": null,
    "description": "\u00a9 [Institute of Urban Water Management and Landscape Water Engineering](https://www.sww.tugraz.at), [Graz University of Technology](https://www.tugraz.at/home/) and [Markus Pichler](mailto:markus.pichler@tugraz.at)\n\n# \ud83d\udca1 Getting started\n\n[![PyPI](https://img.shields.io/pypi/v/swmm-api.svg?logo=pypi&logoColor=white)](https://pypi.python.org/pypi/swmm-api)\n[![pipeline status](https://gitlab.com/markuspichler/swmm_api/badges/main/pipeline.svg)](https://gitlab.com/markuspichler/swmm_api/-/commits/main)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![docs](https://img.shields.io/static/v1.svg?label=&message=documentation&color=blue&logo=readthedocs&logoColor=white)](https://markuspichler.gitlab.io/swmm_api)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7054804.svg)](https://zenodo.org/doi/10.5281/zenodo.5862140)\n[![Latest Release](https://gitlab.com/markuspichler/swmm_api/-/badges/release.svg)](https://gitlab.com/markuspichler/swmm_api/-/releases)\n[![Matrix](https://img.shields.io/matrix/swmm-api-python%3Amatrix.org?style=flat&logo=matrix)](https://matrix.to/#/#swmm-api-python:matrix.org)\n\n[![PyPI - Downloads](https://img.shields.io/pypi/dd/swmm-api)](https://pypi.python.org/pypi/swmm-api)\n[![PyPI - Downloads](https://img.shields.io/pypi/dw/swmm-api)](https://pypi.python.org/pypi/swmm-api)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/swmm-api)](https://pypi.python.org/pypi/swmm-api)\n\n\nWith this package you can read INP-files, manipulate them and write new ones.\nYou can run swmm within the python api.\nAnd you can read the RPT- and OUT-files as a pandas DataFrame for further analysis.\n\nThis package is based on the command line SWMM syntax. ([see Appendix D in the SWMM User Manual 5.2](https://www.epa.gov/system/files/documents/2022-04/swmm-users-manual-version-5.2.pdf))\n\n## Introduction\n\nThe swmm-api package is a powerful tool for modellers and researchers who use the Storm Water Management Model (SWMM). This software enables the manipulation and analysis of SWMM models, both in terms of the input data and the simulation results. The package is written in Python, making it an attractive option for those who use this language for data management and advanced analysis.\n\nOne of the key features of swmm-api is its ability to read and write SWMM import-files (.inp), allowing the user to manipulate the model structure and input data. The package also has the capability to run the SWMM model within the Python environment, providing users with quick access to simulation results. Furthermore, swmm-api can read both the report (.rpt) and binary output-files (.out), presenting the results as a Pandas DataFrame for easy analysis. The ability to read binary hotstart-files (.hst) is also included, which enables the acceleration of simulation time by using initial values stored in the file.\n\nThe swmm-api package is designed to be flexible and user-friendly, with an object-oriented structure that is lightweight and fast. The package is based on the SWMM command line syntax, making it easy to use for those familiar with this model. Additionally, swmm-api has the ability to interact with GIS data, making it a valuable tool for modellers working with spatial data.\n\n## Install the package\n```bash\npip install swmm-api\n```\n\n... to install the package with all dependencies for macros use:\n\n```bash\npip install swmm-api[macros]\n```\n\n... to install the package with all dependencies for GIS I/O use (for Linux or for Windows using python >= 3.10):\n\n```bash\npip install swmm-api[gis]\n```\n\n... and to install the package with all dependencies for macros and GIS I/O use (for Linux or for Windows using python >= 3.10):\n\n```bash\npip install swmm-api[full]\n```\n\nTo add the GIS functionality on **Windows**, I recommend using python version >= 3.10 or with [Mamba](https://github.com/conda-forge/miniforge#mambaforge)\n (or [miniconda](https://docs.conda.io/en/latest/miniconda.html) or [Anaconda](https://www.anaconda.com/))\nand run `mamba install geopandas` to install the GIS dependencies (see [GeoPandas](https://geopandas.org/en/stable/getting_started.html)).\n\nHere you can see which packages are getting installed:\n\n| packages                       | required | macros | gis | full | docs |\n|:------------------------------:|:--------:|:------:|:---:|:----:|:----:|\n| pandas                         | x        | x      | x   | x    | x    |\n| tqdm                           | x        | x      | x   | x    | x    |\n| networkx                       |          | x      |     | x    | x    |\n| fastparquet                    |          | x      |     | x    | x    |\n| matplotlib                     |          | x      |     | x    | x    |\n| SWMM_xsections_shape_generator |          | x      |     | x    | x    |\n| pyswmm                         |          | x      |     | x    | x    |\n| Shapely                        |          |        | x   | x    | x    |\n| pyproj                         |          |        | x   | x    | x    |\n| Rtree                          |          |        | x   | x    | x    |\n| geopandas                      |          |        | x   | x    | x    |\n| sphinx                         |          |        |     |      | x    |\n| nbsphinx                       |          |        |     |      | x    |\n| recommonmark                   |          |        |     |      | x    |\n| pydata_sphinx_theme            |          |        |     |      | x    |\n\n## \ud83d\udcd6 Documentation\n[Link](https://markuspichler.gitlab.io/swmm_api) to the documentation of the api and some example jupyter notebook.\n\n[Here](https://gitlab.com/markuspichler/swmm_api/-/tree/main/examples) are example files for other use-cases.\n\n## Read, manipulate and write the INP-File\n\n### Read the INP-File\n\n```python\nfrom swmm_api import read_inp_file, SwmmInput\n\ninp = read_inp_file('inputfile.inp')  # type: swmm_api.SwmmInput\n# or \ninp = SwmmInput.read_file('inputfile.inp')\n# or\ninp = SwmmInput('inputfile.inp')\n\n```\n\n### Getting information\n\n```python\nfrom swmm_api.input_file.section_labels import TIMESERIES\n\n# getting a specific section of the inp-file\n\nsec_timeseries = inp[TIMESERIES]  # type: swmm_api.input_file.helpers.InpSection\n# or\nsec_timeseries = inp.TIMESERIES  # type: swmm_api.input_file.helpers.InpSection\n\n# getting a specific timeseries as pandas.Series\nts = inp[TIMESERIES]['regenseries'].pandas  # type: pandas.Series\n```\n\n### Manipulate the INP-File\n\n```python\nfrom swmm_api.input_file.section_labels import JUNCTIONS\n\n# setting the elevation of a specific node to a new value\n\ninp[JUNCTIONS]['J01'].elevation = 210\n# or\ninp.JUNCTIONS['J01'].elevation = 210\n# or\ninp.JUNCTIONS['J01']['elevation'] = 210\n```\n\n### Write the manipulated INP-File\n```python\ninp.write_file('new_inputfile.inp')\n```\n\nsee [examples/inp_file_reader.ipynb](https://gitlab.com/markuspichler/swmm_api/-/blob/main/examples/inp_file_reader.ipynb)\n\nsee [examples/inp_file_structure.ipynb](https://gitlab.com/markuspichler/swmm_api/-/blob/main/examples/inp_file_structure.ipynb)\n\nsee [examples/inp_file_macros.ipynb](https://gitlab.com/markuspichler/swmm_api/-/blob/main/examples/inp_file_macros.ipynb)\n\n\n\n\n## Run SWMM\n\nRun SWMM with a specified executable.\n\n```python\nfrom swmm_api import swmm5_run\nswmm5_run('new_inputfile.inp', swmm_lib_path=r'C:\\path\\to\\runswmm.exe')\n```\n\nOr run SWMM with [pyswmm](https://github.com/OpenWaterAnalytics/pyswmm). This would be platform independent as pyswmm is compiled for all platforms.\nAdditionally, you gain the advantage of a progress bar.\n\n```python\nfrom swmm_api import swmm5_run\nswmm5_run('new_inputfile.inp', progress_size=100)\n```\n\n```\nswmm5 C:\\path\\to\\new_inputfile.inp:  77%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258b  | 77/100 [00:03<00:01, 22.36it/s, 2007-02-16 08:46:27]\n```\n\n## Read the OUT-File\n```python\nfrom swmm_api import read_out_file, SwmmOutput\n\nout = read_out_file('new_inputfile.out')   # type: swmm_api.SwmmOut\n# or\nout = SwmmOutput('new_inputfile.out')\n\ndf = out.to_frame()  # type: pandas.DataFrame\n```\nsee [examples/out_file_reader.ipynb](https://gitlab.com/markuspichler/swmm_api/-/blob/main/examples/out_file_reader.ipynb)\n\n\n## Read the RPT-File\n```python\nfrom swmm_api import read_rpt_file, SwmmReport\n\nrpt = read_rpt_file('new_inputfile.rpt')  # type: swmm_api.SwmmReport\n# or\nrpt = SwmmReport('new_inputfile.rpt')\n\nnode_flooding_summary = rpt.node_flooding_summary  # type: pandas.DataFrame\n```\nsee [examples/rpt_file_reader.ipynb](https://gitlab.com/markuspichler/swmm_api/-/blob/main/examples/rpt_file_reader.ipynb)\n\n## \ud83d\uddfa\ufe0f GIS interactions\n\n[`geopandas`](https://geopandas.org/) and its requirements (`Shapely`, `pyproj`, `Rtree`) must be installed! (Use python version >3.10 or conda (Anaconda|miniconda) on Windows)\n\n```python\nfrom swmm_api import SwmmInput\nfrom swmm_api.input_file.macros.gis import write_geo_package, gpkg_to_swmm, complete_vertices\n\ninp = SwmmInput('inputfile.inp')\n\ncoords = inp.COORDINATES.geo_series  # type: geoandas.GeoSeries with points for all nodes\n\ncomplete_vertices(inp)  # this will insert the start and end node points into the link vertices.\n# this function is automatically called in `write_geo_package`, but is needed if the geo-series of vertices is used directly.\n\nvertices = inp.VERTICES.geo_series  # type: geoandas.GeoSeries with lines for all links\npolygons = inp.POLYGONS.geo_series  # type: geoandas.GeoSeries with polygons for all subcatchments\n\n# create geopackage of all objects in inp file\nwrite_geo_package(inp, gpkg_fn='geopackage.gpkg', driver='GPKG', label_sep='.', crs=\"EPSG:32633\")\n\n# read above written geopackage and convert it to inp-data\ninp_new = gpkg_to_swmm('geopackage.gpkg', label_sep='.')\ninp_new.write_file('new_inputfile.inp')\n```\n\n## \u26a0\ufe0f Be Aware!\n\n> As python is case-sensitive this API is also case-sensitive, but SWMM is case-insensitive. \n> This is important for the naming of the objects. \n> For example, you could create a junction 'a' and 'A' with this API, but SWMM would only consider one and ignore the other.\n\nAND\n\n> This package uses `utf-8` as default encoding for the file I/O (reading and writing inp, rpt and out files.)\n> Every function to read a file has the option to define a custom encoding (for example Windows uses this as default for german `encoding='iso-8859-1'`).\n\nBut one can set a default encoding for the package using:\n```python\nfrom swmm_api import CONFIG\nCONFIG['encoding'] = 'iso-8859-1'\n```\n\n---\n\nThis documentation will be continuously extended and enhanced. \nIf you have any question, don't hesitate to write the author and email or create an issue on GitLab or GitHub.\n\nMORE INFORMATION COMING SOON\n\n## Cite as\n\n> *Pichler, Markus. (2022). swmm_api: API for reading, manipulating and running SWMM-Projects with python (0.3). Zenodo. https://doi.org/10.5281/zenodo.7054804*\n\n## Publications mentioning swmm-api\n\n1. Baumann, H., Ravn, N. H., & Schaum, A. (2022). Efficient hydrodynamic modelling of urban stormwater systems for real-time applications. *Modelling, 3(4)*, 464\u2013480. <https://doi.org/10.3390/modelling3040030>\n2. Farina, A., Di Nardo, A., Gargano, R., & Greco, R. (2022). Assessing the environmental impact of combined sewer overflows through a parametric study. *EWaS5*, 8. <https://doi.org/10.3390/environsciproc2022021008>\n3. Schilling, J., & Tr\u00e4nckner, J. (2022). Generate_swmm_inp: An open-source qgis plugin to import and export model input files for swmm. *Water, 14(14)*, 2262. <https://doi.org/10.3390/w14142262>\n4. Zhang, Z., Tian, W., & Liao, Z. (2023). Towards coordinated and robust real-time control: A decentralized approach for combined sewer overflow and urban flooding reduction based on multi-agent reinforcement learning. *Water Research, 229*, 119498. <https://doi.org/10.1016/j.watres.2022.119498>\n5. van der Werf, J. A., Kapelan Z., Langeveld, J. G. (2023). Predictive heuristic control: inferring risks from heterogeneous nowcast accuracy. *Water Sci Technol* 2023; 87 (4): 1009\u20131028. <https://doi.org/10.2166/wst.2023.027>\n6. Farina, A., Di Nardo, A., Gargano, R., Van Der Werf, J. A., & Greco, R. (2023). A simplified approach for the hydrological simulation of urban drainage systems with SWMM. Journal of Hydrology, 623, 129757. <https://doi.org/10.1016/j.jhydrol.2023.129757>\n7. Wicki, T. (2022). Effekt der Einzugsgebietsmodellierung auf  die Abflusssimulation im urbanen Gebiet. Master thesis. Paris Lodron-Universit\u00e4t Salzburg. <https://unigis.at/files/Mastertheses/Full/106726.pdf>\n8. Ryrfors Wien, C. (2023). Nature-based solution retrofit in an urban catchment for CSO reduction (Master's thesis, NTNU). <https://hdl.handle.net/11250/3108487>\n\n\n## Alternative packages\n\n- **swmmr** / R-language / [GitHub](https://github.com/dleutnant/swmmr) / [cran](https://cran.r-project.org/web/packages/swmmr/index.html)\n- **MatSWMM** / Matlab / [GitHub](https://github.com/gandresr/MatSWMM) \n- **swmmNode** / TypeScript / [GitHub](https://github.com/swmm-js/swmmNode)\n\n---\n\n- **swmmio** / [docs](https://swmmio.readthedocs.io/en/latest/) / [pypi](https://pypi.org/project/swmmio/) / [GitHub](https://github.com/aerispaha/swmmio) / simular to this package but more high-level approach (= slower for specific tasks)\n- **GisToSWMM5** / [GitHub](https://github.com/AaltoUrbanWater/GisToSWMM5) / 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`)\n- **swmmtoolbox** / [GitHub](https://github.com/timcera/swmmtoolbox) / 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.\n- **swmmnetwork** / [GitHub](https://github.com/austinorr/swmmnetwork) / create graph network from swmm model (see `swmm_api.input_file.macros.inp_to_graph`)\n- **SWMMOutputAPI** / [GitHub](https://github.com/bemcdonnell/SWMMOutputAPI) / read the output file (see `swmm_api.output_file.out`) / (OpenWaterAnalytics)\n- **swmm-pandas** / [pypi](https://pypi.org/project/swmm-pandas/) / equal functionalities to this package, but not feature complete\n- **swmmout** / [pypi](https://pypi.org/project/swmmout/) / [docs](https://swmmout.readthedocs.io/en/latest/) / simular to `swmmtoolbox` and `SWMMOutputAPI`\n- **swmmtonetcdf** / [pypi](https://pypi.org/project/swmmtonetcdf/) / [GitHub](https://github.com/cbuahin/swmmtonetcdf)\n- **hymo** / [GitHub](https://github.com/lucashtnguyen/hymo) Input and Report Reader (Lucas Nguyen)\n- **shmm** / [GitHub](https://github.com/lucashtnguyen/shmm) Input Reader (Lucas Nguyen)\n- **swmmreport** / [GitHub](https://github.com/lucashtnguyen/swmmreport) Report Reader (Lucas Nguyen)\n- **swmmdoodler** / [GitHub](https://github.com/Geosyntec/swmmdoodler)\n\n### Other SWMM-related python-packages\n\n- **pyswmm** / [pypi](https://pypi.org/project/pyswmm/) / [GitHub](https://github.com/OpenWaterAnalytics/pyswmm) / [Website](https://www.pyswmm.org) / RTC, etc. / based on swmm-toolkit (OpenWaterAnalytics)\n- **swmm-toolkit** / [pypi](https://pypi.org/project/swmm-toolkit/) / [GitHub](https://github.com/OpenWaterAnalytics/swmm-python) / by Michael Tryby (OpenWaterAnalytics)\n- **SWMM5** / [pypi](https://pypi.org/project/SWMM5/) / [GitHub](https://github.com/asselapathirana/swmm5-python) / simular approach to swmm-toolkit (by Assela Pathirana)\n- **SWMM-xsections-shape-generator** / [pypi](https://pypi.org/project/SWMM-xsections-shape-generator/) / tool to generate custom shapes (by me)\n- **SWMM_EA** / [pypi](https://pypi.org/project/SWMM5_EA/) / usage of genetic algorithms with SWMM (by Assela Pathirana)\n- **OSTRICH-SWMM** / [GitHub](https://github.com/ubccr/ostrich-swmm) / OSTRICH optimization software toolkit with SWMM\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "API for reading, manipulating and running US-EPA-SWMM-Projects",
    "version": "0.4.42",
    "project_urls": {
        "Changelog": "https://gitlab.com/markuspichler/swmm_api/-/blob/main/CHANGELOG.md",
        "Documentation": "https://markuspichler.gitlab.io/swmm_api",
        "Homepage": "https://gitlab.com/markuspichler/swmm_api"
    },
    "split_keywords": [
        "swmm",
        " environment",
        " civil_engineering",
        " api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a2d04610f6cf7ad46c419076302f1b494fd089608e42d8a1949a18569b03a450",
                "md5": "87997c050651e5d92c531540d5ac2500",
                "sha256": "37e3edbdac40b590bf0619a47cd0579a40d39706b7dda82276fb9b8c196eed00"
            },
            "downloads": -1,
            "filename": "swmm_api-0.4.42-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "87997c050651e5d92c531540d5ac2500",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 295249,
            "upload_time": "2024-04-16T10:07:57",
            "upload_time_iso_8601": "2024-04-16T10:07:57.068340Z",
            "url": "https://files.pythonhosted.org/packages/a2/d0/4610f6cf7ad46c419076302f1b494fd089608e42d8a1949a18569b03a450/swmm_api-0.4.42-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "276d54c38a095cca176d8ceb3afaa5f2482195f93c3c9dbb29cc4d9f37236678",
                "md5": "2fe3130f8e7fe744ffac273008657f51",
                "sha256": "3a7d29c4110bc43b4a5d9af8c7ba60863ba7f8ebc009206273e32a411d5ed34f"
            },
            "downloads": -1,
            "filename": "swmm-api-0.4.42.tar.gz",
            "has_sig": false,
            "md5_digest": "2fe3130f8e7fe744ffac273008657f51",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 260301,
            "upload_time": "2024-04-16T10:08:09",
            "upload_time_iso_8601": "2024-04-16T10:08:09.281463Z",
            "url": "https://files.pythonhosted.org/packages/27/6d/54c38a095cca176d8ceb3afaa5f2482195f93c3c9dbb29cc4d9f37236678/swmm-api-0.4.42.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-16 10:08:09",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "markuspichler",
    "gitlab_project": "swmm_api",
    "lcname": "swmm-api"
}
        
Elapsed time: 0.23870s