diff --git a/docs/usage/working_with_pyswmm.ipynb b/docs/usage/working_with_pyswmm.ipynb index 7cd17ae..d9a03b2 100644 --- a/docs/usage/working_with_pyswmm.ipynb +++ b/docs/usage/working_with_pyswmm.ipynb @@ -8,12 +8,12 @@ "\n", "If we _really_ want to supercharge our modeling workflow, we can tap into the excellent functionality provided by [pyswmm](https://www.pyswmm.org/). Here we'll walk through a simple example that runs a model with pyswmm and post-processes the results with `swmmio`.\n", "\n", - "We'll start by opening a {py:obj}`pyswmm.Simulation` context to run a model. Then we'll visualize the results using the {py:func}`swmmio.create_map` function.\n" + "We'll start by instantiating a `swmmio.Model` with a model hosted in the swmm-nrtestsuite repo." ] }, { "cell_type": "code", - "execution_count": 106, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -30,7 +30,7 @@ " 'invert_range': np.int64(35)}" ] }, - "execution_count": 106, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -43,208 +43,19 @@ "# path to a SWMM model from swmm-nrtestsuite\n", "model_path = 'https://raw.githubusercontent.com/USEPA/swmm-nrtestsuite/refs/heads/dev/public/examples/Example1.inp'\n", "model = swmmio.Model(model_path)\n", - "model.summary\n" + "model.summary" ] }, { - "cell_type": "code", - "execution_count": 28, + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
InletNodeOutletNode...MaxDPerccoords
Name
1910...0.38[(4042.11, 9600.0), (4105.26, 6947.37)]
41920...0.22[(7768.42, 6736.84), (5957.89, 6589.47)]
52021...0.17[(5957.89, 6589.47), (4926.32, 6105.26)]
61021...1.00[(4105.26, 6947.37), (4926.32, 6105.26)]
72122...0.29[(4926.32, 6105.26), (4421.05, 4715.79)]
82216...0.39[(4421.05, 4715.79), (4821.05, 3326.32)]
101718...0.53[(6252.63, 2147.37), (6673.68, 1368.42), (6631.58, 505.26)]
111314...0.27[(2336.84, 4357.89), (3157.89, 4294.74)]
121415...0.31[(3157.89, 4294.74), (3221.05, 3242.11)]
131516...0.76[(3221.05, 3242.11), (4821.05, 3326.32)]
142324...0.35[(6484.21, 3978.95), (5389.47, 3031.58)]
151624...0.54[(4821.05, 3326.32), (5389.47, 3031.58)]
162417...0.57[(5389.47, 3031.58), (6252.63, 2147.37)]
\n", - "

13 rows × 22 columns

\n", - "
" - ], - "text/plain": [ - " InletNode OutletNode ... MaxDPerc \\\n", - "Name ... \n", - "1 9 10 ... 0.38 \n", - "4 19 20 ... 0.22 \n", - "5 20 21 ... 0.17 \n", - "6 10 21 ... 1.00 \n", - "7 21 22 ... 0.29 \n", - "8 22 16 ... 0.39 \n", - "10 17 18 ... 0.53 \n", - "11 13 14 ... 0.27 \n", - "12 14 15 ... 0.31 \n", - "13 15 16 ... 0.76 \n", - "14 23 24 ... 0.35 \n", - "15 16 24 ... 0.54 \n", - "16 24 17 ... 0.57 \n", - "\n", - " coords \n", - "Name \n", - "1 [(4042.11, 9600.0), (4105.26, 6947.37)] \n", - "4 [(7768.42, 6736.84), (5957.89, 6589.47)] \n", - "5 [(5957.89, 6589.47), (4926.32, 6105.26)] \n", - "6 [(4105.26, 6947.37), (4926.32, 6105.26)] \n", - "7 [(4926.32, 6105.26), (4421.05, 4715.79)] \n", - "8 [(4421.05, 4715.79), (4821.05, 3326.32)] \n", - "10 [(6252.63, 2147.37), (6673.68, 1368.42), (6631.58, 505.26)] \n", - "11 [(2336.84, 4357.89), (3157.89, 4294.74)] \n", - "12 [(3157.89, 4294.74), (3221.05, 3242.11)] \n", - "13 [(3221.05, 3242.11), (4821.05, 3326.32)] \n", - "14 [(6484.21, 3978.95), (5389.47, 3031.58)] \n", - "15 [(4821.05, 3326.32), (5389.47, 3031.58)] \n", - "16 [(5389.47, 3031.58), (6252.63, 2147.37)] \n", - "\n", - "[13 rows x 22 columns]" - ] - }, - "execution_count": 28, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ - "model.links.dataframe" + "Next, we'll opening a {py:obj}`pyswmm.Simulation` context to run the model. At each simulation step, we'll store the flows at each link. When the simulation is done, we'll plots things in a simple timeseries chart." ] }, { "cell_type": "code", - "execution_count": 103, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -253,7 +64,7 @@ "" ] }, - "execution_count": 103, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" }, @@ -288,9 +99,17 @@ "pd.DataFrame(link_flows).T.plot()\n" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Animating Link Flows \n", + "Let's out post-processing up a notch by animating the flows in the network:" + ] + }, { "cell_type": "code", - "execution_count": 107, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -481,42 +300,42 @@ "\n", "\n", "
\n", - " \n", + " \n", "
\n", - " \n", + " oninput=\"anim22fd1faaafdf43cea8ea61aedd4bdfb9.set_frame(parseInt(this.value));\">\n", "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", "
\n", - "
\n", - " \n", - " \n", - " Once\n", + " \n", - " \n", - " Loop\n", + " \n", - " \n", + " \n", "
\n", "
\n", "
\n", @@ -526,9 +345,9 @@ " /* Instantiate the Animation class. */\n", " /* The IDs given should match those used in the template above. */\n", " (function() {\n", - " var img_id = \"_anim_img1624ab0047f046feab057333bb190412\";\n", - " var slider_id = \"_anim_slider1624ab0047f046feab057333bb190412\";\n", - " var loop_select_id = \"_anim_loop_select1624ab0047f046feab057333bb190412\";\n", + " var img_id = \"_anim_img22fd1faaafdf43cea8ea61aedd4bdfb9\";\n", + " var slider_id = \"_anim_slider22fd1faaafdf43cea8ea61aedd4bdfb9\";\n", + " var loop_select_id = \"_anim_loop_select22fd1faaafdf43cea8ea61aedd4bdfb9\";\n", " var frames = new Array(22);\n", " \n", " frames[0] = \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAYAAAA10dzkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90\\\n", @@ -8254,7 +8073,7 @@ " /* set a timeout to make sure all the above elements are created before\n", " the object is initialized. */\n", " setTimeout(function() {\n", - " anim1624ab0047f046feab057333bb190412 = new Animation(frames, img_id, slider_id, 200.0,\n", + " anim22fd1faaafdf43cea8ea61aedd4bdfb9 = new Animation(frames, img_id, slider_id, 200.0,\n", " loop_select_id);\n", " }, 0);\n", " })()\n", @@ -8264,7 +8083,7 @@ "" ] }, - "execution_count": 107, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" },