| import wntr |
| import plotly.express as px |
| import pandas as pd |
|
|
| def run_simulation(wn, engine_type="EpanetSimulator"): |
| if engine_type == "EpanetSimulator": |
| sim = wntr.sim.EpanetSimulator(wn) |
| else: |
| sim = wntr.sim.WNTRSimulator(wn) |
| return sim.run_sim() |
|
|
| def plot_network_map(wn, results, metric, timestep): |
| node_attribute = results.node[metric].iloc[timestep] |
| node_df = pd.DataFrame({ |
| 'node': node_attribute.index, |
| 'value': node_attribute.values, |
| 'x': [wn.get_node(n).coordinates[0] for n in node_attribute.index], |
| 'y': [wn.get_node(n).coordinates[1] for n in node_attribute.index] |
| }) |
| fig = px.scatter(node_df, x="x", y="y", color="value", hover_name="node", |
| title=f"{metric.capitalize()} at Time Step {timestep}") |
| fig.update_layout(yaxis=dict(scaleanchor="x", scaleratio=1)) |
| return fig |
|
|