Spaces:
Configuration error
Configuration error
File size: 9,940 Bytes
46b66f3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | {
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# PCSWMM Engineering Review Dashboard v0.3\n",
"\n",
"Deterministic, read-only hydrology, pond, topology, scenario, and model QA/QC.\n",
"\n",
"**Open a PCSWMM project before running this notebook.**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Load the matching SDK"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"import importlib\n",
"from pathlib import Path\n",
"\n",
"REQUIRED_VERSION = \"0.3.0\"\n",
"ROOT = Path.cwd()\n",
"\n",
"preferred = [\n",
" ROOT / \"PCSWMM_Engineering_SDK_v0_3\",\n",
" ROOT / \"PCSWMM_Engineering_SDK_v0_3\" / \"PCSWMM_Engineering_SDK_v0_3\",\n",
"]\n",
"\n",
"SDK_ROOT = next(\n",
" (path for path in preferred if (path / \"pcswmm_ai\").is_dir()),\n",
" None,\n",
")\n",
"\n",
"if SDK_ROOT is None:\n",
" matches = [\n",
" p.parent for p in ROOT.rglob(\"pcswmm_ai\")\n",
" if p.is_dir() and \"Engineering_SDK_v0_3\" in str(p.parent)\n",
" ]\n",
" SDK_ROOT = matches[0] if matches else None\n",
"\n",
"if SDK_ROOT is None:\n",
" raise FileNotFoundError(\"PCSWMM Engineering SDK v0.3 was not found.\")\n",
"\n",
"for module_name in list(sys.modules):\n",
" if module_name == \"pcswmm_ai\" or module_name.startswith(\"pcswmm_ai.\"):\n",
" del sys.modules[module_name]\n",
"\n",
"sys.path = [\n",
" p for p in sys.path\n",
" if \"PCSWMM_AI_SDK_v0_\" not in str(p)\n",
" and \"PCSWMM_Engineering_SDK_v0_3\" not in str(p)\n",
"]\n",
"sys.path.insert(0, str(SDK_ROOT))\n",
"importlib.invalidate_caches()\n",
"\n",
"from pcswmm_ai import PCSWMMClient, __version__\n",
"import pcswmm_ai\n",
"\n",
"print(\"SDK root:\", SDK_ROOT)\n",
"print(\"SDK package:\", Path(pcswmm_ai.__file__).resolve())\n",
"print(\"SDK version:\", __version__)\n",
"\n",
"if __version__ != REQUIRED_VERSION:\n",
" raise RuntimeError(\n",
" f\"Expected SDK {REQUIRED_VERSION}, loaded {__version__}\"\n",
" )\n",
"\n",
"client = PCSWMMClient(pcpy)\n",
"client.health()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Project and model inventory"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from IPython.display import display, Markdown\n",
"\n",
"display(pd.DataFrame(\n",
" list(client.project.summary().items()),\n",
" columns=[\"Property\", \"Value\"],\n",
"))\n",
"display(pd.DataFrame(client.collections.summary()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Hydrology review"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"display(Markdown(\"### Hydrology summary\"))\n",
"display(pd.DataFrame(\n",
" list(client.hydrology.summary().items()),\n",
" columns=[\"Metric\", \"Value\"],\n",
"))\n",
"\n",
"display(Markdown(\"### Hydrology findings\"))\n",
"display(pd.DataFrame(client.hydrology.review()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Pond and outlet review"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"display(Markdown(\"### Pond summary\"))\n",
"display(pd.DataFrame(\n",
" list(client.pond.summary().items()),\n",
" columns=[\"Metric\", \"Value\"],\n",
"))\n",
"\n",
"display(Markdown(\"### Storage records\"))\n",
"display(pd.DataFrame(client.pond.storage_records()))\n",
"\n",
"display(Markdown(\"### Outlet structures\"))\n",
"display(pd.DataFrame(client.pond.outlet_records()))\n",
"\n",
"display(Markdown(\"### Pond findings\"))\n",
"display(pd.DataFrame(client.pond.review()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. Topology review"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"display(Markdown(\"### Link endpoints\"))\n",
"display(pd.DataFrame(client.topology.link_endpoints()))\n",
"\n",
"display(Markdown(\"### Orphan links\"))\n",
"display(pd.DataFrame(client.topology.orphan_links()))\n",
"\n",
"display(Markdown(\"### Isolated nodes\"))\n",
"display(pd.DataFrame(client.topology.isolated_nodes()))\n",
"\n",
"display(Markdown(\"### Duplicate directed link pairs\"))\n",
"display(pd.DataFrame(client.topology.duplicate_link_pairs()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Scenario source-file review"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"display(pd.DataFrame(\n",
" list(client.scenarios.summary().items()),\n",
" columns=[\"Metric\", \"Value\"],\n",
"))\n",
"display(pd.DataFrame(client.scenarios.path_status()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 7. Consolidated screening summary"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"display(pd.DataFrame(\n",
" list(client.engineering.model_screening_summary().items()),\n",
" columns=[\"Check\", \"Finding count\"],\n",
"))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 8. Build report-ready review package"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"review_package = client.review_report.build()\n",
"\n",
"print(\"Review classification:\")\n",
"print(review_package[\"classification\"])\n",
"\n",
"print(\"\\nSections:\")\n",
"print(list(review_package.keys()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 9. Export review package to JSON"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"from pathlib import Path\n",
"from datetime import datetime\n",
"\n",
"# Uncomment to export.\n",
"# export_dir = Path(client.project.summary()[\"project_folder\"]) / \"PCSWMM_Engineering_Review\"\n",
"# export_dir.mkdir(parents=True, exist_ok=True)\n",
"# export_path = export_dir / (\n",
"# \"engineering_review_\"\n",
"# + datetime.now().strftime(\"%Y%m%d_%H%M%S\")\n",
"# + \".json\"\n",
"# )\n",
"# export_path.write_text(\n",
"# json.dumps(review_package, indent=2, default=str),\n",
"# encoding=\"utf-8\",\n",
"# )\n",
"# print(export_path)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 10. Run simulation explicitly"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Uncomment only when ready to run the active model.\n",
"# display(pd.DataFrame([client.simulation.run()]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 11. Hydraulic result examples"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Confirm PCSWMM result labels and units before uncommenting.\n",
"\n",
"# Link peak flow:\n",
"# display(pd.DataFrame(\n",
"# client.hydraulics.peak_link_results(\"Flow\", \"CMS\")\n",
"# ))\n",
"\n",
"# Pond peak depth:\n",
"# display(pd.DataFrame(\n",
"# client.hydraulics.peak_node_results(\n",
"# \"Depth\",\n",
"# \"m\",\n",
"# [\"pond\"],\n",
"# )\n",
"# ))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Engineering status\n",
"\n",
"The findings are automated screening results. They are not a substitute for\n",
"project-specific design criteria, municipal standards, calibration review,\n",
"or professional engineering judgment."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
} |