Skip to content

Commit

Permalink
fix typos in pyswmm example
Browse files Browse the repository at this point in the history
  • Loading branch information
aerispaha committed Dec 19, 2024
1 parent 15b419c commit 77b6fde
Showing 1 changed file with 41 additions and 222 deletions.
263 changes: 41 additions & 222 deletions docs/usage/working_with_pyswmm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -30,7 +30,7 @@
" 'invert_range': np.int64(35)}"
]
},
"execution_count": 106,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -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": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>InletNode</th>\n",
" <th>OutletNode</th>\n",
" <th>...</th>\n",
" <th>MaxDPerc</th>\n",
" <th>coords</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Name</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>9</td>\n",
" <td>10</td>\n",
" <td>...</td>\n",
" <td>0.38</td>\n",
" <td>[(4042.11, 9600.0), (4105.26, 6947.37)]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>19</td>\n",
" <td>20</td>\n",
" <td>...</td>\n",
" <td>0.22</td>\n",
" <td>[(7768.42, 6736.84), (5957.89, 6589.47)]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>20</td>\n",
" <td>21</td>\n",
" <td>...</td>\n",
" <td>0.17</td>\n",
" <td>[(5957.89, 6589.47), (4926.32, 6105.26)]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>10</td>\n",
" <td>21</td>\n",
" <td>...</td>\n",
" <td>1.00</td>\n",
" <td>[(4105.26, 6947.37), (4926.32, 6105.26)]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>21</td>\n",
" <td>22</td>\n",
" <td>...</td>\n",
" <td>0.29</td>\n",
" <td>[(4926.32, 6105.26), (4421.05, 4715.79)]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>22</td>\n",
" <td>16</td>\n",
" <td>...</td>\n",
" <td>0.39</td>\n",
" <td>[(4421.05, 4715.79), (4821.05, 3326.32)]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>17</td>\n",
" <td>18</td>\n",
" <td>...</td>\n",
" <td>0.53</td>\n",
" <td>[(6252.63, 2147.37), (6673.68, 1368.42), (6631.58, 505.26)]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>13</td>\n",
" <td>14</td>\n",
" <td>...</td>\n",
" <td>0.27</td>\n",
" <td>[(2336.84, 4357.89), (3157.89, 4294.74)]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>14</td>\n",
" <td>15</td>\n",
" <td>...</td>\n",
" <td>0.31</td>\n",
" <td>[(3157.89, 4294.74), (3221.05, 3242.11)]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>15</td>\n",
" <td>16</td>\n",
" <td>...</td>\n",
" <td>0.76</td>\n",
" <td>[(3221.05, 3242.11), (4821.05, 3326.32)]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>23</td>\n",
" <td>24</td>\n",
" <td>...</td>\n",
" <td>0.35</td>\n",
" <td>[(6484.21, 3978.95), (5389.47, 3031.58)]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>16</td>\n",
" <td>24</td>\n",
" <td>...</td>\n",
" <td>0.54</td>\n",
" <td>[(4821.05, 3326.32), (5389.47, 3031.58)]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>24</td>\n",
" <td>17</td>\n",
" <td>...</td>\n",
" <td>0.57</td>\n",
" <td>[(5389.47, 3031.58), (6252.63, 2147.37)]</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>13 rows × 22 columns</p>\n",
"</div>"
],
"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": [
{
Expand All @@ -253,7 +64,7 @@
"<Axes: >"
]
},
"execution_count": 103,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -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": [
{
Expand Down Expand Up @@ -481,42 +300,42 @@
"</style>\n",
"\n",
"<div class=\"animation\">\n",
" <img id=\"_anim_img1624ab0047f046feab057333bb190412\">\n",
" <img id=\"_anim_img22fd1faaafdf43cea8ea61aedd4bdfb9\">\n",
" <div class=\"anim-controls\">\n",
" <input id=\"_anim_slider1624ab0047f046feab057333bb190412\" type=\"range\" class=\"anim-slider\"\n",
" <input id=\"_anim_slider22fd1faaafdf43cea8ea61aedd4bdfb9\" type=\"range\" class=\"anim-slider\"\n",
" name=\"points\" min=\"0\" max=\"1\" step=\"1\" value=\"0\"\n",
" oninput=\"anim1624ab0047f046feab057333bb190412.set_frame(parseInt(this.value));\">\n",
" oninput=\"anim22fd1faaafdf43cea8ea61aedd4bdfb9.set_frame(parseInt(this.value));\">\n",
" <div class=\"anim-buttons\">\n",
" <button title=\"Decrease speed\" aria-label=\"Decrease speed\" onclick=\"anim1624ab0047f046feab057333bb190412.slower()\">\n",
" <button title=\"Decrease speed\" aria-label=\"Decrease speed\" onclick=\"anim22fd1faaafdf43cea8ea61aedd4bdfb9.slower()\">\n",
" <i class=\"fa fa-minus\"></i></button>\n",
" <button title=\"First frame\" aria-label=\"First frame\" onclick=\"anim1624ab0047f046feab057333bb190412.first_frame()\">\n",
" <button title=\"First frame\" aria-label=\"First frame\" onclick=\"anim22fd1faaafdf43cea8ea61aedd4bdfb9.first_frame()\">\n",
" <i class=\"fa fa-fast-backward\"></i></button>\n",
" <button title=\"Previous frame\" aria-label=\"Previous frame\" onclick=\"anim1624ab0047f046feab057333bb190412.previous_frame()\">\n",
" <button title=\"Previous frame\" aria-label=\"Previous frame\" onclick=\"anim22fd1faaafdf43cea8ea61aedd4bdfb9.previous_frame()\">\n",
" <i class=\"fa fa-step-backward\"></i></button>\n",
" <button title=\"Play backwards\" aria-label=\"Play backwards\" onclick=\"anim1624ab0047f046feab057333bb190412.reverse_animation()\">\n",
" <button title=\"Play backwards\" aria-label=\"Play backwards\" onclick=\"anim22fd1faaafdf43cea8ea61aedd4bdfb9.reverse_animation()\">\n",
" <i class=\"fa fa-play fa-flip-horizontal\"></i></button>\n",
" <button title=\"Pause\" aria-label=\"Pause\" onclick=\"anim1624ab0047f046feab057333bb190412.pause_animation()\">\n",
" <button title=\"Pause\" aria-label=\"Pause\" onclick=\"anim22fd1faaafdf43cea8ea61aedd4bdfb9.pause_animation()\">\n",
" <i class=\"fa fa-pause\"></i></button>\n",
" <button title=\"Play\" aria-label=\"Play\" onclick=\"anim1624ab0047f046feab057333bb190412.play_animation()\">\n",
" <button title=\"Play\" aria-label=\"Play\" onclick=\"anim22fd1faaafdf43cea8ea61aedd4bdfb9.play_animation()\">\n",
" <i class=\"fa fa-play\"></i></button>\n",
" <button title=\"Next frame\" aria-label=\"Next frame\" onclick=\"anim1624ab0047f046feab057333bb190412.next_frame()\">\n",
" <button title=\"Next frame\" aria-label=\"Next frame\" onclick=\"anim22fd1faaafdf43cea8ea61aedd4bdfb9.next_frame()\">\n",
" <i class=\"fa fa-step-forward\"></i></button>\n",
" <button title=\"Last frame\" aria-label=\"Last frame\" onclick=\"anim1624ab0047f046feab057333bb190412.last_frame()\">\n",
" <button title=\"Last frame\" aria-label=\"Last frame\" onclick=\"anim22fd1faaafdf43cea8ea61aedd4bdfb9.last_frame()\">\n",
" <i class=\"fa fa-fast-forward\"></i></button>\n",
" <button title=\"Increase speed\" aria-label=\"Increase speed\" onclick=\"anim1624ab0047f046feab057333bb190412.faster()\">\n",
" <button title=\"Increase speed\" aria-label=\"Increase speed\" onclick=\"anim22fd1faaafdf43cea8ea61aedd4bdfb9.faster()\">\n",
" <i class=\"fa fa-plus\"></i></button>\n",
" </div>\n",
" <form title=\"Repetition mode\" aria-label=\"Repetition mode\" action=\"#n\" name=\"_anim_loop_select1624ab0047f046feab057333bb190412\"\n",
" <form title=\"Repetition mode\" aria-label=\"Repetition mode\" action=\"#n\" name=\"_anim_loop_select22fd1faaafdf43cea8ea61aedd4bdfb9\"\n",
" class=\"anim-state\">\n",
" <input type=\"radio\" name=\"state\" value=\"once\" id=\"_anim_radio1_1624ab0047f046feab057333bb190412\"\n",
" <input type=\"radio\" name=\"state\" value=\"once\" id=\"_anim_radio1_22fd1faaafdf43cea8ea61aedd4bdfb9\"\n",
" >\n",
" <label for=\"_anim_radio1_1624ab0047f046feab057333bb190412\">Once</label>\n",
" <input type=\"radio\" name=\"state\" value=\"loop\" id=\"_anim_radio2_1624ab0047f046feab057333bb190412\"\n",
" <label for=\"_anim_radio1_22fd1faaafdf43cea8ea61aedd4bdfb9\">Once</label>\n",
" <input type=\"radio\" name=\"state\" value=\"loop\" id=\"_anim_radio2_22fd1faaafdf43cea8ea61aedd4bdfb9\"\n",
" checked>\n",
" <label for=\"_anim_radio2_1624ab0047f046feab057333bb190412\">Loop</label>\n",
" <input type=\"radio\" name=\"state\" value=\"reflect\" id=\"_anim_radio3_1624ab0047f046feab057333bb190412\"\n",
" <label for=\"_anim_radio2_22fd1faaafdf43cea8ea61aedd4bdfb9\">Loop</label>\n",
" <input type=\"radio\" name=\"state\" value=\"reflect\" id=\"_anim_radio3_22fd1faaafdf43cea8ea61aedd4bdfb9\"\n",
" >\n",
" <label for=\"_anim_radio3_1624ab0047f046feab057333bb190412\">Reflect</label>\n",
" <label for=\"_anim_radio3_22fd1faaafdf43cea8ea61aedd4bdfb9\">Reflect</label>\n",
" </form>\n",
" </div>\n",
"</div>\n",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -8264,7 +8083,7 @@
"<IPython.core.display.HTML object>"
]
},
"execution_count": 107,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
},
Expand Down

0 comments on commit 77b6fde

Please sign in to comment.