<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hydrology Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/hydrology/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/hydrology/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Sat, 21 Feb 2026 07:13:16 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>Swmm-Api: Python-Powered Real-Time Access to EPA’s SWMM Models</title>
		<link>https://www.scmgalaxy.com/tutorials/swmm-api-python-powered-real-time-access-to-epas-swmm-models/</link>
					<comments>https://www.scmgalaxy.com/tutorials/swmm-api-python-powered-real-time-access-to-epas-swmm-models/#respond</comments>
		
		<dc:creator><![CDATA[Vijay K]]></dc:creator>
		<pubDate>Tue, 22 Apr 2025 07:08:06 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[DigitalTwins]]></category>
		<category><![CDATA[EPAWaterTools]]></category>
		<category><![CDATA[Hydrology]]></category>
		<category><![CDATA[PythonSimulation]]></category>
		<category><![CDATA[RealTimeControl]]></category>
		<category><![CDATA[SmartCities]]></category>
		<category><![CDATA[StormwaterModeling]]></category>
		<category><![CDATA[SWMM5]]></category>
		<category><![CDATA[swmmAPI]]></category>
		<category><![CDATA[SWMMRTC]]></category>
		<category><![CDATA[UrbanDrainage]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=12122</guid>

					<description><![CDATA[<p>#WhatIsSwmmAPI 1. What is swmm-api? swmm-api is an open-source Python library that provides a low-level, real-time interface to the EPA [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/swmm-api-python-powered-real-time-access-to-epas-swmm-models/">Swmm-Api: Python-Powered Real-Time Access to EPA’s SWMM Models</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="507" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/04/image-7-1024x507.png" alt="" class="wp-image-12123" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/04/image-7-1024x507.png 1024w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/04/image-7-300x148.png 300w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/04/image-7-768x380.png 768w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/04/image-7.png 1437w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading"><strong>#WhatIsSwmmAPI</strong></h2>



<h3 class="wp-block-heading"><strong>1. What is swmm-api?</strong></h3>



<p class="wp-block-paragraph"><strong><code>swmm-api</code></strong> is an open-source Python library that provides a <strong>low-level, real-time interface</strong> to the <strong>EPA Storm Water Management Model (SWMM)</strong>. It allows Python developers to:</p>



<ul class="wp-block-list">
<li><strong>Read, modify, and control SWMM simulations</strong> dynamically</li>



<li>Access <strong>internal states</strong> of SWMM objects at each timestep</li>



<li>Inject <strong>custom control logic</strong> for pumps, valves, inflows, or rain events</li>



<li><strong>Integrate SWMM</strong> models into automated workflows, simulations, or optimization loops</li>
</ul>



<p class="wp-block-paragraph">Unlike high-level tools like <code>PySWMM</code>, <code>swmm-api</code> provides <strong>direct memory access</strong> to the internal SWMM simulation, making it extremely powerful for <strong>real-time control</strong>, <strong>data assimilation</strong>, and <strong>fine-grained simulation manipulation</strong>.</p>



<p class="wp-block-paragraph">It is developed and maintained by <a href="https://github.com/jbgo/swmm-api">jbgo/swmm-api</a> and supports SWMM5 engine integration across platforms.</p>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h2 class="wp-block-heading"><strong>#SwmmAPIUseCases</strong></h2>



<h3 class="wp-block-heading"><strong>2. Major Use Cases of swmm-api</strong></h3>



<p class="wp-block-paragraph">The <code>swmm-api</code> package offers advanced control and automation for stormwater simulations. It is best suited for professionals and developers requiring <strong>programmatic, stepwise control</strong> of the simulation process.</p>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">💧 <strong>2.1. Real-Time Control (RTC) of Urban Drainage Systems</strong></h3>



<ul class="wp-block-list">
<li>Implement <strong>sensor-driven</strong> control of gates, pumps, or regulators</li>



<li>Integrate SCADA systems to drive SWMM control logic</li>



<li>Update model parameters based on live weather or flow data</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">🧪 <strong>2.2. Calibration and Sensitivity Analysis</strong></h3>



<ul class="wp-block-list">
<li>Adjust parameters (e.g., catchment area, slope, or roughness) during runtime</li>



<li>Run multiple simulation iterations programmatically</li>



<li>Export results for analysis or optimization</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">📊 <strong>2.3. Research and Custom Simulation Scenarios</strong></h3>



<ul class="wp-block-list">
<li>Experiment with novel flow control strategies</li>



<li>Apply <strong>machine learning</strong> to predict optimal setpoints</li>



<li>Conduct storm event scenario testing with variable rainfall profiles</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">📡 <strong>2.4. Data Assimilation and Digital Twins</strong></h3>



<ul class="wp-block-list">
<li>Ingest real-time sensor data (rainfall, depth, flow) and simulate system response</li>



<li>Use SWMM as a <strong>digital twin</strong> of a physical urban stormwater system</li>



<li>Validate and refine predictive models in real-time</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">🧰 <strong>2.5. Automation and Workflow Integration</strong></h3>



<ul class="wp-block-list">
<li>Integrate with <strong>CI/CD pipelines</strong>, <strong>APIs</strong>, or <strong>data dashboards</strong></li>



<li>Use in notebooks or remote simulations</li>



<li>Combine with optimization libraries like <code>scipy.optimize</code> or <code>pyomo</code></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h2 class="wp-block-heading"><strong>#SwmmAPIArchitecture</strong></h2>



<h3 class="wp-block-heading"><strong>3. How swmm-api Works – Architecture Overview</strong></h3>



<p class="wp-block-paragraph">The <code>swmm-api</code> package operates by directly interfacing with the <strong>SWMM5 engine’s compiled binary</strong> (usually <code>swmm5.dll</code> or <code>swmm5.so</code>) and accessing its <strong>simulation memory</strong> using Python’s <code>ctypes</code> module.</p>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">🧱 <strong>3.1. Architecture Layers</strong></h3>



<h4 class="wp-block-heading">✅ <strong>A. SWMM Engine (Core)</strong></h4>



<ul class="wp-block-list">
<li>Original C-based SWMM5 engine (e.g., version 5.1.15 or newer)</li>



<li>Responsible for time-based hydrologic/hydraulic simulations</li>



<li>Processes <code>.inp</code> files defining system topology and parameters</li>
</ul>



<h4 class="wp-block-heading">✅ <strong>B. swmm-api Memory Interface</strong></h4>



<ul class="wp-block-list">
<li>Loads SWMM engine dynamically using ctypes</li>



<li>Attaches to the <strong>in-memory objects</strong> used during simulation</li>



<li>Provides access to core SWMM structures like:
<ul class="wp-block-list">
<li>Nodes</li>



<li>Links</li>



<li>Subcatchments</li>



<li>Controls</li>
</ul>
</li>
</ul>



<h4 class="wp-block-heading">✅ <strong>C. Python Interface Layer</strong></h4>



<ul class="wp-block-list">
<li>Offers Pythonic classes and methods to:
<ul class="wp-block-list">
<li>Read simulation outputs in real time</li>



<li>Set inflows, control settings, and time parameters</li>



<li>Monitor water quality, depth, volume, and more</li>
</ul>
</li>
</ul>



<h4 class="wp-block-heading">✅ <strong>D. User Script / Application</strong></h4>



<ul class="wp-block-list">
<li>Typically written in Python</li>



<li>Drives the simulation loop, custom control logic, optimization, or logging</li>



<li>Optionally visualizes results using <code>matplotlib</code>, <code>pandas</code>, or <code>Plotly</code></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h2 class="wp-block-heading"><strong>#SwmmAPIWorkflow</strong></h2>



<h3 class="wp-block-heading"><strong>4. Basic Workflow of swmm-api</strong></h3>



<p class="wp-block-paragraph">Here’s a high-level view of how a typical <code>swmm-api</code> based simulation workflow proceeds:</p>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">🔄 <strong>Simulation Loop Workflow</strong></h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>Step</th><th>Action</th></tr></thead><tbody><tr><td>1.</td><td>Load and compile the SWMM5 engine (DLL or shared object)</td></tr><tr><td>2.</td><td>Initialize simulation with <code>.inp</code> model</td></tr><tr><td>3.</td><td>Step through the simulation in real-time (1 timestep at a time)</td></tr><tr><td>4.</td><td>At each step, read/write values (e.g., depth, flow, rainfall)</td></tr><tr><td>5.</td><td>Optionally modify parameters based on logic or inputs</td></tr><tr><td>6.</td><td>Save results or visualize after simulation completes</td></tr></tbody></table></figure>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">🔍 <strong>Access Points</strong></h3>



<ul class="wp-block-list">
<li><code>getNodeParam</code>, <code>setLinkFlow</code>, <code>getRainfall</code></li>



<li><code>stepSimulation</code>, <code>getSimulationTime</code>, <code>getWaterQuality</code></li>



<li>All access is low-level and performant (direct pointer access)</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h2 class="wp-block-heading"><strong>#GettingStartedWithSwmmAPI</strong></h2>



<h3 class="wp-block-heading"><strong>5. Step-by-Step Guide to Using swmm-api</strong></h3>



<p class="wp-block-paragraph">This guide assumes you&#8217;re familiar with SWMM <code>.inp</code> files and basic Python.</p>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">✅ <strong>Step 1: Install Dependencies</strong></h3>



<p class="wp-block-paragraph">Clone the repository:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
git clone https://github.com/jbgo/swmm-api.git
cd swmm-api
pip install -r requirements.txt

</pre></div>


<p class="wp-block-paragraph">Install a compatible version of <strong>SWMM5 engine</strong>:</p>



<ul class="wp-block-list">
<li>Windows: download <code>swmm5.dll</code></li>



<li>Linux: compile <code>swmm5.so</code></li>



<li>Place it in your project directory or system path</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">✅ <strong>Step 2: Prepare a SWMM Model</strong></h3>



<p class="wp-block-paragraph">Use EPA SWMM or QGIS plugin to create a <code>.inp</code> file defining:</p>



<ul class="wp-block-list">
<li>Subcatchments</li>



<li>Junctions</li>



<li>Pipes</li>



<li>Control rules</li>



<li>Simulation time and rainfall data</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">✅ <strong>Step 3: Initialize Simulation</strong></h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
from swmm_api.input_file import read_inp_file
from swmm_api.simulation import Simulation

inp = read_inp_file(&quot;model.inp&quot;)
sim = Simulation(inp)

sim.start()

</pre></div>


<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">✅ <strong>Step 4: Step Through Simulation</strong></h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
while not sim.is_finished():
    sim.step_advance()  # advance simulation
    flow = sim.get_link_result(&#039;C1&#039;)&#x5B;&#039;flow_rate&#039;]
    depth = sim.get_node_result(&#039;J2&#039;)&#x5B;&#039;depth&#039;]
    print(f&quot;Flow at C1: {flow:.2f} m³/s, Depth at J2: {depth:.3f} m&quot;)

</pre></div>


<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">✅ <strong>Step 5: Inject Custom Logic</strong></h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
if depth &amp;gt; 1.5:
    sim.set_link_setting(&#039;C1&#039;, 0.3)  # throttle valve

</pre></div>


<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">✅ <strong>Step 6: Post-Process and Visualize</strong></h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
import matplotlib.pyplot as plt

times = sim.get_times()
flows = sim.get_link_result(&#039;C1&#039;)&#x5B;&#039;flow_rate_series&#039;]

plt.plot(times, flows)
plt.title(&quot;Flow Rate at Conduit C1&quot;)
plt.xlabel(&quot;Time&quot;)
plt.ylabel(&quot;Flow (m³/s)&quot;)
plt.show()

</pre></div>


<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">✅ <strong>Step 7: Advanced Uses</strong></h3>



<ul class="wp-block-list">
<li>Combine with sensor data via <code>requests</code> or MQTT</li>



<li>Integrate with Jupyter notebooks for interactive analysis</li>



<li>Automate batch runs for calibration</li>
</ul>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/swmm-api-python-powered-real-time-access-to-epas-swmm-models/">Swmm-Api: Python-Powered Real-Time Access to EPA’s SWMM Models</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/swmm-api-python-powered-real-time-access-to-epas-swmm-models/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
