| import streamlit as st |
| import wntr |
| import os |
| import pandas as pd |
| import plotly.express as px |
| from wntr_utils import run_simulation, plot_network_map |
|
|
| st.set_page_config(page_title="WNTR-QGIS Streamlit", layout="wide") |
|
|
| st.title("π§ WNTR-QGIS-style Water Network Analyzer") |
|
|
| |
| uploaded_file = st.file_uploader("Upload EPANET .inp File", type=["inp"]) |
|
|
| @st.cache_resource |
| def load_wn_model(file_path): |
| return wntr.network.WaterNetworkModel(file_path) |
|
|
| if uploaded_file: |
| |
| with open("temp.inp", "wb") as f: |
| f.write(uploaded_file.read()) |
| |
| try: |
| with st.spinner("Loading water network model..."): |
| wn = load_wn_model("temp.inp") |
| st.success("Model loaded successfully!") |
|
|
| |
| sim_choice = st.radio("Choose Simulation Engine", ["EpanetSimulator", "WntrSimulator"]) |
|
|
| with st.spinner("Running simulation..."): |
| results = run_simulation(wn, sim_choice) |
| st.success("Simulation completed!") |
|
|
| |
| st.subheader("π Result Viewer") |
| metric = st.selectbox("Select Node Metric", ["pressure", "head"]) |
| timestep = st.slider("Select Time Step", 0, len(results.node["pressure"].index)-1) |
|
|
| |
| with st.spinner("Plotting network map..."): |
| fig = plot_network_map(wn, results, metric, timestep) |
| st.plotly_chart(fig, use_container_width=True) |
|
|
| except Exception as e: |
| st.error(f"β An error occurred: {e}") |
|
|
| else: |
| st.info("π Please upload a valid EPANET `.inp` file to begin.") |
|
|