Spaces:
Configuration error
Configuration error
File size: 6,063 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 | {
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# PCSWMM AI SDK \u2014 Quickstart v0.1\n",
"\n",
"This notebook uses PCSWMM's injected `pcpy` object through a reusable,\n",
"read-only SDK.\n",
"\n",
"**Open a PCSWMM project before running the cells below.**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Load the SDK"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"from pathlib import Path\n",
"\n",
"# This notebook is stored in: <SDK folder>/examples/\n",
"SDK_ROOT = Path.cwd().parent\n",
"if str(SDK_ROOT) not in sys.path:\n",
" sys.path.insert(0, str(SDK_ROOT))\n",
"\n",
"from pcswmm_ai import PCSWMMClient\n",
"\n",
"client = PCSWMMClient(pcpy)\n",
"client.health()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Active project summary"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"project_df = pd.DataFrame(\n",
" list(client.project.summary().items()),\n",
" columns=[\"Property\", \"Value\"],\n",
")\n",
"display(project_df)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. SWMM collection inventory"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"collection_df = pd.DataFrame(client.collections.summary())\n",
"display(collection_df)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. List collection keys"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for collection_name in [\"Scenarios\", \"Nodes\", \"Links\", \"Subcatchments\"]:\n",
" print(\"\\n\", collection_name)\n",
" print(client.collections.keys(collection_name))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. Map layers"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"layer_names = client.layers.names()\n",
"display(pd.DataFrame({\"Layer\": layer_names}))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Read a layer as records"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"layer_name = \"Subcatchments\"\n",
"\n",
"if layer_name in layer_names:\n",
" records = client.layers.records(layer_name)\n",
" display(pd.DataFrame(records))\n",
"else:\n",
" print(f\"{layer_name} is unavailable in the active project.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 7. Basic deterministic QA/QC"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if \"Subcatchments\" in layer_names:\n",
" duplicates = client.qaqc.duplicate_names(\"Subcatchments\")\n",
" print(\"Duplicate subcatchment names:\", duplicates)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 8. Run the active model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Uncomment only when ready to run the model.\n",
"# run_result = client.simulation.run()\n",
"# display(pd.DataFrame([run_result]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 9. Retrieve a PCSWMM time series"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Modify these four values to match the active model and result file.\n",
"OBJECT_GROUP = \"Links\"\n",
"RESULT_VARIABLE = \"Flow\"\n",
"UNITS = \"CMS\"\n",
"OBJECT_NAME = \"C_out\"\n",
"\n",
"# Uncomment after the model has been run and a graph file is available.\n",
"# records = client.results.timeseries(\n",
"# OBJECT_GROUP,\n",
"# RESULT_VARIABLE,\n",
"# UNITS,\n",
"# OBJECT_NAME,\n",
"# )\n",
"# display(pd.DataFrame(records).head())\n",
"# client.results.summarize(records)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Verification targets\n",
"\n",
"The first test is successful when:\n",
"\n",
"- `client.health()` shows the PCSWMM runtime type;\n",
"- the active project metadata appears;\n",
"- collection counts match the PCSWMM model;\n",
"- map layers are listed;\n",
"- subcatchment records appear as a DataFrame.\n",
"\n",
"The simulation and time-series cells are intentionally commented to prevent\n",
"unintended model execution."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
} |