Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,418 +1,886 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import sys
|
| 3 |
-
import tempfile
|
| 4 |
import pandas as pd
|
| 5 |
import numpy as np
|
| 6 |
import plotly.express as px
|
| 7 |
import plotly.graph_objects as go
|
| 8 |
-
from
|
| 9 |
-
import random
|
| 10 |
-
import folium
|
| 11 |
-
from streamlit_folium import folium_static
|
| 12 |
-
|
| 13 |
-
# ----- Robust Configuration Fix -----
|
| 14 |
-
# Create a temporary home directory for Streamlit
|
| 15 |
-
temp_home = tempfile.mkdtemp()
|
| 16 |
-
os.environ['HOME'] = temp_home
|
| 17 |
-
os.environ['STREAMLIT_CONFIG_DIR'] = os.path.join(temp_home, '.streamlit')
|
| 18 |
-
os.environ['GATHER_USAGE_STATS'] = 'false'
|
| 19 |
-
os.environ['STREAMLIT_GLOBAL_DEVELOPMENT_MODE'] = 'false'
|
| 20 |
-
os.environ['STREAMLIT_GLOBAL_METRICS'] = 'false'
|
| 21 |
-
|
| 22 |
-
# Create config directory
|
| 23 |
-
config_dir = os.environ['STREAMLIT_CONFIG_DIR']
|
| 24 |
-
os.makedirs(config_dir, exist_ok=True)
|
| 25 |
-
|
| 26 |
-
# Write minimal config file
|
| 27 |
-
config_path = os.path.join(config_dir, 'config.toml')
|
| 28 |
-
with open(config_path, 'w') as f:
|
| 29 |
-
f.write("""
|
| 30 |
-
[server]
|
| 31 |
-
port = 8501
|
| 32 |
-
enableCORS = false
|
| 33 |
-
enableXsrfProtection = false
|
| 34 |
-
headless = true
|
| 35 |
-
[browser]
|
| 36 |
-
gatherUsageStats = false
|
| 37 |
-
""")
|
| 38 |
-
|
| 39 |
-
# Now import Streamlit
|
| 40 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
#
|
|
|
|
|
|
|
| 43 |
st.set_page_config(
|
| 44 |
-
page_title="Oklahoma
|
| 45 |
-
page_icon="
|
| 46 |
layout="wide",
|
| 47 |
initial_sidebar_state="expanded"
|
| 48 |
)
|
| 49 |
|
| 50 |
-
#
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
# CSS styling
|
| 55 |
st.markdown("""
|
| 56 |
<style>
|
| 57 |
-
.header {
|
| 58 |
-
|
| 59 |
-
color:
|
| 60 |
-
padding: 1rem;
|
| 61 |
-
border-radius: 10px;
|
| 62 |
text-align: center;
|
| 63 |
margin-bottom: 1rem;
|
|
|
|
| 64 |
}
|
| 65 |
-
.
|
| 66 |
-
background: #
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
border-radius: 10px;
|
| 70 |
-
text-align: center;
|
| 71 |
-
margin: 0.5rem 0;
|
| 72 |
-
}
|
| 73 |
-
.damage-alert {
|
| 74 |
-
background: linear-gradient(135deg, #ff9a56 0%, #ff6b35 100%);
|
| 75 |
-
border-left: 4px solid #ff4500;
|
| 76 |
-
padding: 1rem;
|
| 77 |
margin: 1rem 0;
|
| 78 |
-
border-
|
| 79 |
-
|
| 80 |
}
|
| 81 |
-
.
|
| 82 |
-
|
| 83 |
-
border-radius: 10px;
|
| 84 |
-
overflow: hidden;
|
| 85 |
-
margin-bottom: 1rem;
|
| 86 |
-
}
|
| 87 |
-
.footer {
|
| 88 |
-
text-align: center;
|
| 89 |
padding: 1rem;
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
}
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
margin
|
| 100 |
-
display: block;
|
| 101 |
}
|
| 102 |
</style>
|
| 103 |
""", unsafe_allow_html=True)
|
| 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 |
-
# Damage types
|
| 164 |
-
self.damage_types = [
|
| 165 |
-
{'id': 'drought', 'name': 'Drought', 'color': '#ff8c00', 'icon': 'π΅'},
|
| 166 |
-
{'id': 'flood', 'name': 'Flood', 'color': '#1e90ff', 'icon': 'π'},
|
| 167 |
-
{'id': 'tornado', 'name': 'Tornado', 'color': '#dc143c', 'icon': 'πͺοΈ'},
|
| 168 |
-
{'id': 'wildfire', 'name': 'Wildfire', 'color': '#ff4500', 'icon': 'π₯'},
|
| 169 |
-
{'id': 'hail', 'name': 'Hail Storm', 'color': '#87ceeb', 'icon': 'π§οΈ'},
|
| 170 |
-
{'id': 'wind', 'name': 'High Winds', 'color': '#a9a9a9', 'icon': 'π¨'}
|
| 171 |
-
]
|
| 172 |
-
|
| 173 |
-
# Damage severity levels
|
| 174 |
-
self.damage_levels = [
|
| 175 |
-
{'id': 1, 'name': 'Minimal', 'color': '#fff3cd'},
|
| 176 |
-
{'id': 2, 'name': 'Minor', 'color': '#ffeeba'},
|
| 177 |
-
{'id': 3, 'name': 'Moderate', 'color': '#ffdf7e'},
|
| 178 |
-
{'id': 4, 'name': 'Severe', 'color': '#ffcc00'},
|
| 179 |
-
{'id': 5, 'name': 'Extreme', 'color': '#ff8c00'}
|
| 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 |
-
'displaced': random.randint(0, 50) * severity['id'],
|
| 209 |
-
'affected': random.randint(50, 500) * severity['id']
|
| 210 |
-
},
|
| 211 |
-
'vehicles': {
|
| 212 |
-
'damaged': random.randint(0, 100) * severity['id'],
|
| 213 |
-
'destroyed': random.randint(0, 20) * severity['id'],
|
| 214 |
-
'estimated_cost': random.randint(5000, 100000) * severity['id']
|
| 215 |
-
},
|
| 216 |
-
'property': {
|
| 217 |
-
'homes_damaged': random.randint(0, 50) * severity['id'],
|
| 218 |
-
'businesses_affected': random.randint(0, 10) * severity['id'],
|
| 219 |
-
'estimated_cost': random.randint(50000, 1000000) * severity['id']
|
| 220 |
-
},
|
| 221 |
-
'infrastructure': {
|
| 222 |
-
'roads_damaged_miles': round(random.uniform(0.5, 10) * severity['id'], 1),
|
| 223 |
-
'power_outages': random.randint(100, 5000) * severity['id'],
|
| 224 |
-
'water_systems_affected': random.randint(0, 5) * severity['id']
|
| 225 |
-
},
|
| 226 |
-
'agriculture': {
|
| 227 |
-
'crop_loss_acres': random.randint(100, 5000) * severity['id'],
|
| 228 |
-
'livestock_loss': random.randint(0, 100) * severity['id'],
|
| 229 |
-
'estimated_cost': random.randint(10000, 500000) * severity['id']
|
| 230 |
-
}
|
| 231 |
-
}
|
| 232 |
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
|
| 246 |
-
#
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
tooltip=location,
|
| 251 |
-
icon=folium.Icon(color='red', icon='info-sign')
|
| 252 |
-
).add_to(m)
|
| 253 |
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
-
#
|
| 266 |
-
for
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
).add_to(m)
|
| 281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
return m
|
| 283 |
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
</
|
| 291 |
-
""", unsafe_allow_html=True)
|
| 292 |
|
| 293 |
-
#
|
| 294 |
-
st.markdown(
|
| 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 |
-
st.
|
| 322 |
-
st.
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
)
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
st.write(f"**π° Estimated Cost:** ${vehicles['estimated_cost']:,}")
|
| 339 |
-
|
| 340 |
-
destruction_rate = vehicles['destroyed'] / max(1, vehicles['damaged'] + vehicles['destroyed'])
|
| 341 |
-
st.progress(destruction_rate, text=f"Destruction Rate: {destruction_rate:.1%}")
|
| 342 |
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
st.
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
# Create a simple damage distribution map
|
| 350 |
-
damage_points = pd.DataFrame({
|
| 351 |
-
'lat': [damage_data.get_location_coordinates(damage_info['location'])[0] + random.uniform(-0.1, 0.1) for _ in range(20)],
|
| 352 |
-
'lon': [damage_data.get_location_coordinates(damage_info['location'])[1] + random.uniform(-0.1, 0.1) for _ in range(20)],
|
| 353 |
-
'damage': [random.choice(['home', 'business']) for _ in range(20)]
|
| 354 |
-
})
|
| 355 |
-
st.map(damage_points, size=50, color='#FF0000')
|
| 356 |
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
st.
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
|
| 375 |
-
|
| 376 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
|
| 378 |
-
#
|
| 379 |
-
|
| 380 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
|
| 382 |
-
#
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
|
| 390 |
-
#
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
|
| 406 |
-
|
| 407 |
-
|
|
|
|
|
|
|
| 408 |
|
| 409 |
-
|
| 410 |
-
|
|
|
|
|
|
|
|
|
|
| 411 |
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import numpy as np
|
| 3 |
import plotly.express as px
|
| 4 |
import plotly.graph_objects as go
|
| 5 |
+
from plotly.subplots import make_subplots
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import streamlit as st
|
| 7 |
+
from datetime import datetime
|
| 8 |
+
import folium
|
| 9 |
+
from streamlit_folium import st_folium
|
| 10 |
+
from scipy import stats
|
| 11 |
+
import warnings
|
| 12 |
+
warnings.filterwarnings('ignore')
|
| 13 |
|
| 14 |
+
# ===================================
|
| 15 |
+
# PAGE CONFIGURATION
|
| 16 |
+
# ===================================
|
| 17 |
st.set_page_config(
|
| 18 |
+
page_title="Oklahoma Flood Research Dashboard",
|
| 19 |
+
page_icon="π",
|
| 20 |
layout="wide",
|
| 21 |
initial_sidebar_state="expanded"
|
| 22 |
)
|
| 23 |
|
| 24 |
+
# ===================================
|
| 25 |
+
# STYLING
|
| 26 |
+
# ===================================
|
|
|
|
|
|
|
| 27 |
st.markdown("""
|
| 28 |
<style>
|
| 29 |
+
.main-header {
|
| 30 |
+
font-size: 2.8rem;
|
| 31 |
+
color: #1a365d;
|
|
|
|
|
|
|
| 32 |
text-align: center;
|
| 33 |
margin-bottom: 1rem;
|
| 34 |
+
font-weight: bold;
|
| 35 |
}
|
| 36 |
+
.insight-box {
|
| 37 |
+
background: linear-gradient(135deg, #e6f3ff 0%, #f0f8ff 100%);
|
| 38 |
+
padding: 1.5rem;
|
| 39 |
+
border-radius: 12px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
margin: 1rem 0;
|
| 41 |
+
border-left: 5px solid #4299e1;
|
| 42 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
| 43 |
}
|
| 44 |
+
.metric-card {
|
| 45 |
+
background: white;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
padding: 1rem;
|
| 47 |
+
border-radius: 8px;
|
| 48 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 49 |
+
border-top: 3px solid #4299e1;
|
| 50 |
}
|
| 51 |
+
.statistical-box {
|
| 52 |
+
background: linear-gradient(135deg, #fff5f5 0%, #fed7d7 100%);
|
| 53 |
+
padding: 1rem;
|
| 54 |
+
border-radius: 8px;
|
| 55 |
+
border-left: 4px solid #e53e3e;
|
| 56 |
+
margin: 1rem 0;
|
|
|
|
| 57 |
}
|
| 58 |
</style>
|
| 59 |
""", unsafe_allow_html=True)
|
| 60 |
|
| 61 |
+
# ===================================
|
| 62 |
+
# DATA LOADING FUNCTIONS
|
| 63 |
+
# ===================================
|
| 64 |
+
@st.cache_data
|
| 65 |
+
def load_oklahoma_counties():
|
| 66 |
+
"""Load Oklahoma county flood data"""
|
| 67 |
+
return {
|
| 68 |
+
'Oklahoma': {
|
| 69 |
+
'full_name': 'Oklahoma County', 'seat': 'Oklahoma City', 'population': 796292,
|
| 70 |
+
'latitude': 35.4676, 'longitude': -97.5164, 'elevation_ft': 1200,
|
| 71 |
+
'major_rivers': ['North Canadian River', 'Canadian River'],
|
| 72 |
+
'tribal_nations': ['Citizen Potawatomi Nation'], 'severity_level': 'High',
|
| 73 |
+
'research_notes': 'Most flood-prone county. Urban development increases flash flood risk.',
|
| 74 |
+
'climate_projection': '68% higher heavy rainfall risks by 2090',
|
| 75 |
+
'vulnerability_factors': ['Urban heat island', 'Impermeable surfaces']
|
| 76 |
+
},
|
| 77 |
+
'Tulsa': {
|
| 78 |
+
'full_name': 'Tulsa County', 'seat': 'Tulsa', 'population': 669279,
|
| 79 |
+
'latitude': 36.1540, 'longitude': -95.9928, 'elevation_ft': 700,
|
| 80 |
+
'major_rivers': ['Arkansas River', 'Verdigris River'],
|
| 81 |
+
'tribal_nations': ['Muscogee Creek Nation', 'Cherokee Nation'], 'severity_level': 'High',
|
| 82 |
+
'research_notes': 'Arkansas River flooding history. 2019 record flooding caused $3.4B+ damage.',
|
| 83 |
+
'climate_projection': '64% higher 2-year flooding risks',
|
| 84 |
+
'vulnerability_factors': ['River proximity', 'Aging infrastructure']
|
| 85 |
+
},
|
| 86 |
+
'Cleveland': {
|
| 87 |
+
'full_name': 'Cleveland County', 'seat': 'Norman', 'population': 295528,
|
| 88 |
+
'latitude': 35.2226, 'longitude': -97.4395, 'elevation_ft': 1100,
|
| 89 |
+
'major_rivers': ['Canadian River', 'Little River'],
|
| 90 |
+
'tribal_nations': ['Absentee Shawnee Tribe'], 'severity_level': 'Medium',
|
| 91 |
+
'research_notes': 'University area vulnerable to flash flooding.',
|
| 92 |
+
'climate_projection': 'Moderate increase in extreme precipitation',
|
| 93 |
+
'vulnerability_factors': ['Student population density']
|
| 94 |
+
},
|
| 95 |
+
'Creek': {
|
| 96 |
+
'full_name': 'Creek County', 'seat': 'Sapulpa', 'population': 71754,
|
| 97 |
+
'latitude': 35.9951, 'longitude': -96.1142, 'elevation_ft': 800,
|
| 98 |
+
'major_rivers': ['Arkansas River'], 'tribal_nations': ['Muscogee Creek Nation'],
|
| 99 |
+
'severity_level': 'High', 'research_notes': 'Shares Arkansas River flood risks.',
|
| 100 |
+
'climate_projection': '64% higher flash flooding risks for tribal communities',
|
| 101 |
+
'vulnerability_factors': ['Tribal community exposure']
|
| 102 |
+
},
|
| 103 |
+
'Muskogee': {
|
| 104 |
+
'full_name': 'Muskogee County', 'seat': 'Muskogee', 'population': 66339,
|
| 105 |
+
'latitude': 35.7478, 'longitude': -95.3697, 'elevation_ft': 600,
|
| 106 |
+
'major_rivers': ['Arkansas River'], 'tribal_nations': ['Muscogee Creek Nation'],
|
| 107 |
+
'severity_level': 'High', 'research_notes': 'Major tribal nation headquarters location.',
|
| 108 |
+
'climate_projection': 'Highest vulnerability among tribal nations',
|
| 109 |
+
'vulnerability_factors': ['Multiple river convergence']
|
| 110 |
+
},
|
| 111 |
+
'Canadian': {
|
| 112 |
+
'full_name': 'Canadian County', 'seat': 'El Reno', 'population': 154405,
|
| 113 |
+
'latitude': 35.5317, 'longitude': -98.1020, 'elevation_ft': 1300,
|
| 114 |
+
'major_rivers': ['Canadian River'], 'tribal_nations': ['Cheyenne and Arapaho Tribes'],
|
| 115 |
+
'severity_level': 'Medium', 'research_notes': 'Rural flooding with agricultural impact.',
|
| 116 |
+
'climate_projection': 'Agricultural flood losses projected to increase 20%',
|
| 117 |
+
'vulnerability_factors': ['Agricultural exposure']
|
| 118 |
+
},
|
| 119 |
+
'Grady': {
|
| 120 |
+
'full_name': 'Grady County', 'seat': 'Chickasha', 'population': 54795,
|
| 121 |
+
'latitude': 35.0526, 'longitude': -97.9364, 'elevation_ft': 1150,
|
| 122 |
+
'major_rivers': ['Washita River'], 'tribal_nations': ['Anadarko Caddo Nation'],
|
| 123 |
+
'severity_level': 'Medium', 'research_notes': 'Recent dam breaches highlight infrastructure aging.',
|
| 124 |
+
'climate_projection': 'Small watershed dam effectiveness declining',
|
| 125 |
+
'vulnerability_factors': ['Dam infrastructure aging']
|
| 126 |
+
},
|
| 127 |
+
'Payne': {
|
| 128 |
+
'full_name': 'Payne County', 'seat': 'Stillwater', 'population': 81912,
|
| 129 |
+
'latitude': 36.1156, 'longitude': -97.0589, 'elevation_ft': 900,
|
| 130 |
+
'major_rivers': ['Stillwater Creek'], 'tribal_nations': ['Osage Nation'],
|
| 131 |
+
'severity_level': 'Low', 'research_notes': 'University town with good drainage.',
|
| 132 |
+
'climate_projection': 'Stable flood risk with adequate infrastructure',
|
| 133 |
+
'vulnerability_factors': ['Student population during events']
|
| 134 |
}
|
| 135 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
+
def calculate_severity_level(damage, fatalities, injuries):
|
| 138 |
+
"""Calculate flood severity"""
|
| 139 |
+
damage_score = 3 if damage >= 50e6 else 2 if damage >= 10e6 else 1 if damage >= 1e6 else 0
|
| 140 |
+
casualty_score = 3 if (fatalities + injuries) >= 10 else 2 if (fatalities + injuries) >= 3 else 1 if (fatalities + injuries) >= 1 else 0
|
| 141 |
+
if fatalities > 0: casualty_score = max(casualty_score, 2)
|
| 142 |
+
max_score = max(damage_score, casualty_score)
|
| 143 |
+
return 'High' if max_score >= 3 else 'Medium' if max_score >= 2 else 'Low'
|
| 144 |
+
|
| 145 |
+
def calculate_damage_classification(damage):
|
| 146 |
+
"""Classify damage levels"""
|
| 147 |
+
return 'Catastrophic' if damage >= 50e6 else 'Major' if damage >= 10e6 else 'Moderate' if damage >= 1e6 else 'Minor'
|
| 148 |
+
|
| 149 |
+
@st.cache_data
|
| 150 |
+
def load_oklahoma_flood_data():
|
| 151 |
+
"""Load flood event data"""
|
| 152 |
+
events = [
|
| 153 |
+
# 2025 Events
|
| 154 |
+
{'date': '2025-04-30', 'county': 'Oklahoma', 'location': 'Oklahoma City Metro', 'type': 'Flash Flood',
|
| 155 |
+
'source': 'Heavy Rainfall', 'fatalities': 2, 'injuries': 5, 'damage_usd': 15_000_000, 'rain_inches': 12.5,
|
| 156 |
+
'description': 'Historic April flooding broke 77-year rainfall record.',
|
| 157 |
+
'tribal_impact': 'Citizen Potawatomi Nation facilities flooded', 'data_source': 'Oklahoma Emergency Management'},
|
| 158 |
|
| 159 |
+
{'date': '2025-05-02', 'county': 'Grady', 'location': 'County Road 1322', 'type': 'Dam Break',
|
| 160 |
+
'source': 'Infrastructure Failure', 'fatalities': 0, 'injuries': 0, 'damage_usd': 2_000_000, 'rain_inches': 8.0,
|
| 161 |
+
'description': 'Small watershed dam breach isolated 8-10 homes.',
|
| 162 |
+
'tribal_impact': 'No direct tribal impact', 'data_source': 'Oklahoma Water Resources Board'},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
+
# 2024 Events
|
| 165 |
+
{'date': '2024-04-27', 'county': 'Oklahoma', 'location': 'Multiple OKC locations', 'type': 'Flash Flood',
|
| 166 |
+
'source': 'Severe Storms', 'fatalities': 1, 'injuries': 15, 'damage_usd': 25_000_000, 'rain_inches': 6.8,
|
| 167 |
+
'description': 'Major tornado outbreak with significant flash flooding.',
|
| 168 |
+
'tribal_impact': 'Absentee Shawnee tribal facilities damaged', 'data_source': 'National Weather Service'},
|
| 169 |
+
|
| 170 |
+
{'date': '2024-06-15', 'county': 'Tulsa', 'location': 'Tulsa Metro', 'type': 'Flash Flood',
|
| 171 |
+
'source': 'Severe Thunderstorms', 'fatalities': 0, 'injuries': 3, 'damage_usd': 8_500_000, 'rain_inches': 5.2,
|
| 172 |
+
'description': 'Urban flash flooding from intense thunderstorms.',
|
| 173 |
+
'tribal_impact': 'Limited impact on Creek Nation facilities', 'data_source': 'Tulsa Emergency Management'},
|
| 174 |
+
|
| 175 |
+
# 2023 Events
|
| 176 |
+
{'date': '2023-05-20', 'county': 'Creek', 'location': 'Sapulpa area', 'type': 'Flash Flood',
|
| 177 |
+
'source': 'Heavy Rainfall', 'fatalities': 0, 'injuries': 2, 'damage_usd': 6_200_000, 'rain_inches': 4.8,
|
| 178 |
+
'description': 'Flash flooding affected tribal communities.',
|
| 179 |
+
'tribal_impact': 'Muscogee Creek Nation community facilities damaged', 'data_source': 'Creek County Emergency Management'},
|
| 180 |
+
|
| 181 |
+
{'date': '2023-07-12', 'county': 'Canadian', 'location': 'El Reno area', 'type': 'Flash Flood',
|
| 182 |
+
'source': 'Severe Storms', 'fatalities': 0, 'injuries': 1, 'damage_usd': 4_100_000, 'rain_inches': 3.9,
|
| 183 |
+
'description': 'Rural flooding with agricultural impacts.',
|
| 184 |
+
'tribal_impact': 'Cheyenne-Arapaho agricultural lands affected', 'data_source': 'Canadian County Emergency Management'},
|
| 185 |
+
|
| 186 |
+
# 2022 Events
|
| 187 |
+
{'date': '2022-05-15', 'county': 'Cleveland', 'location': 'Norman', 'type': 'Flash Flood',
|
| 188 |
+
'source': 'Thunderstorms', 'fatalities': 0, 'injuries': 4, 'damage_usd': 7_800_000, 'rain_inches': 4.5,
|
| 189 |
+
'description': 'Norman flooding affected university area.',
|
| 190 |
+
'tribal_impact': 'No significant tribal impact', 'data_source': 'Cleveland County Emergency Management'},
|
| 191 |
+
|
| 192 |
+
{'date': '2022-08-22', 'county': 'Muskogee', 'location': 'Muskogee', 'type': 'Flash Flood',
|
| 193 |
+
'source': 'Heavy Rainfall', 'fatalities': 1, 'injuries': 3, 'damage_usd': 9_300_000, 'rain_inches': 5.8,
|
| 194 |
+
'description': 'Urban flooding with tribal headquarters impact.',
|
| 195 |
+
'tribal_impact': 'Muscogee Creek Nation headquarters affected', 'data_source': 'Muskogee County Emergency Management'},
|
| 196 |
+
|
| 197 |
+
# 2021 Events
|
| 198 |
+
{'date': '2021-04-28', 'county': 'Oklahoma', 'location': 'Oklahoma City', 'type': 'Flash Flood',
|
| 199 |
+
'source': 'Severe Weather', 'fatalities': 1, 'injuries': 8, 'damage_usd': 12_400_000, 'rain_inches': 6.2,
|
| 200 |
+
'description': 'Spring flooding event with tornado warnings.',
|
| 201 |
+
'tribal_impact': 'Limited tribal impact', 'data_source': 'Oklahoma Emergency Management'},
|
| 202 |
+
|
| 203 |
+
{'date': '2021-06-10', 'county': 'Payne', 'location': 'Stillwater', 'type': 'Flash Flood',
|
| 204 |
+
'source': 'Creek Overflow', 'fatalities': 0, 'injuries': 2, 'damage_usd': 3_800_000, 'rain_inches': 4.1,
|
| 205 |
+
'description': 'Stillwater Creek flooding affected OSU campus.',
|
| 206 |
+
'tribal_impact': 'No significant tribal impact', 'data_source': 'Payne County Emergency Management'},
|
| 207 |
+
|
| 208 |
+
# 2020 Events
|
| 209 |
+
{'date': '2020-05-25', 'county': 'Tulsa', 'location': 'Arkansas River corridor', 'type': 'River Flood',
|
| 210 |
+
'source': 'Heavy Regional Rainfall', 'fatalities': 0, 'injuries': 2, 'damage_usd': 18_600_000, 'rain_inches': 8.4,
|
| 211 |
+
'description': 'Arkansas River flooding with levee stress.',
|
| 212 |
+
'tribal_impact': 'Creek Nation riverside properties affected', 'data_source': 'US Army Corps of Engineers'},
|
| 213 |
+
|
| 214 |
+
{'date': '2020-07-18', 'county': 'Canadian', 'location': 'Rural Canadian County', 'type': 'Flash Flood',
|
| 215 |
+
'source': 'Isolated Storms', 'fatalities': 0, 'injuries': 0, 'damage_usd': 2_900_000, 'rain_inches': 3.2,
|
| 216 |
+
'description': 'Rural agricultural flooding event.',
|
| 217 |
+
'tribal_impact': 'Tribal agricultural operations affected', 'data_source': 'Oklahoma Department of Agriculture'},
|
| 218 |
+
|
| 219 |
+
# 2019 Events (Major year)
|
| 220 |
+
{'date': '2019-05-22', 'county': 'Tulsa', 'location': 'Arkansas River corridor', 'type': 'River Flood',
|
| 221 |
+
'source': 'Record Dam Release', 'fatalities': 0, 'injuries': 3, 'damage_usd': 63_500_000, 'rain_inches': 15.2,
|
| 222 |
+
'description': 'Historic flooding from record Keystone Dam releases.',
|
| 223 |
+
'tribal_impact': 'Muscogee Creek Nation facilities evacuated', 'data_source': 'US Army Corps of Engineers'},
|
| 224 |
+
|
| 225 |
+
{'date': '2019-05-23', 'county': 'Muskogee', 'location': 'Arkansas River', 'type': 'River Flood',
|
| 226 |
+
'source': 'Continued Arkansas River Flooding', 'fatalities': 0, 'injuries': 2, 'damage_usd': 45_000_000, 'rain_inches': 12.8,
|
| 227 |
+
'description': 'Downstream impacts from Tulsa flooding.',
|
| 228 |
+
'tribal_impact': 'Muscogee Creek Nation headquarters severely flooded', 'data_source': 'Muscogee Creek Nation Emergency Management'},
|
| 229 |
+
|
| 230 |
+
{'date': '2019-06-02', 'county': 'Creek', 'location': 'Arkansas River basin', 'type': 'River Flood',
|
| 231 |
+
'source': 'Extended Arkansas River Flooding', 'fatalities': 0, 'injuries': 1, 'damage_usd': 28_700_000, 'rain_inches': 10.1,
|
| 232 |
+
'description': 'Extended flooding impacts on Creek County.',
|
| 233 |
+
'tribal_impact': 'Muscogee Creek agricultural lands flooded', 'data_source': 'Creek County Emergency Management'},
|
| 234 |
+
|
| 235 |
+
# Additional historical events
|
| 236 |
+
{'date': '2018-08-15', 'county': 'Oklahoma', 'location': 'Oklahoma City', 'type': 'Flash Flood',
|
| 237 |
+
'source': 'Severe Thunderstorms', 'fatalities': 0, 'injuries': 6, 'damage_usd': 14_200_000, 'rain_inches': 5.9,
|
| 238 |
+
'description': 'Urban flash flooding during peak summer.',
|
| 239 |
+
'tribal_impact': 'Limited tribal impact', 'data_source': 'Oklahoma City Emergency Management'},
|
| 240 |
+
|
| 241 |
+
{'date': '2017-05-10', 'county': 'Cleveland', 'location': 'Norman', 'type': 'Flash Flood',
|
| 242 |
+
'source': 'Spring Storm System', 'fatalities': 0, 'injuries': 3, 'damage_usd': 8_900_000, 'rain_inches': 4.7,
|
| 243 |
+
'description': 'Spring flooding in Norman university area.',
|
| 244 |
+
'tribal_impact': 'No significant tribal impact', 'data_source': 'University of Oklahoma'},
|
| 245 |
+
|
| 246 |
+
{'date': '2016-06-25', 'county': 'Grady', 'location': 'Chickasha area', 'type': 'Flash Flood',
|
| 247 |
+
'source': 'Severe Weather', 'fatalities': 0, 'injuries': 1, 'damage_usd': 5_600_000, 'rain_inches': 4.2,
|
| 248 |
+
'description': 'Rural flooding with infrastructure impacts.',
|
| 249 |
+
'tribal_impact': 'Tribal roadway access affected', 'data_source': 'Grady County Emergency Management'},
|
| 250 |
+
|
| 251 |
+
{'date': '2015-05-25', 'county': 'Oklahoma', 'location': 'Oklahoma City', 'type': 'Flash Flood',
|
| 252 |
+
'source': 'Memorial Day Storms', 'fatalities': 2, 'injuries': 12, 'damage_usd': 18_000_000, 'rain_inches': 7.5,
|
| 253 |
+
'description': 'Memorial Day weekend flooding.',
|
| 254 |
+
'tribal_impact': 'Limited tribal impact', 'data_source': 'Oklahoma City Emergency Management'},
|
| 255 |
+
|
| 256 |
+
{'date': '2015-10-03', 'county': 'Tulsa', 'location': 'Tulsa Metro', 'type': 'Flash Flood',
|
| 257 |
+
'source': 'Fall Storm System', 'fatalities': 0, 'injuries': 2, 'damage_usd': 6_800_000, 'rain_inches': 3.8,
|
| 258 |
+
'description': 'Fall flooding event in Tulsa metro.',
|
| 259 |
+
'tribal_impact': 'Creek Nation facilities minor impact', 'data_source': 'Tulsa Emergency Management'}
|
| 260 |
+
]
|
| 261 |
+
|
| 262 |
+
df = pd.DataFrame(events)
|
| 263 |
+
df['date'] = pd.to_datetime(df['date'])
|
| 264 |
+
df['year'] = df['date'].dt.year
|
| 265 |
+
df['month'] = df['date'].dt.month
|
| 266 |
+
df['season'] = df['month'].map({12: 'Winter', 1: 'Winter', 2: 'Winter', 3: 'Spring', 4: 'Spring', 5: 'Spring',
|
| 267 |
+
6: 'Summer', 7: 'Summer', 8: 'Summer', 9: 'Fall', 10: 'Fall', 11: 'Fall'})
|
| 268 |
|
| 269 |
+
# Calculate derived fields
|
| 270 |
+
for idx, row in df.iterrows():
|
| 271 |
+
df.at[idx, 'severity_level'] = calculate_severity_level(row['damage_usd'], row['fatalities'], row['injuries'])
|
| 272 |
+
df.at[idx, 'damage_classification'] = calculate_damage_classification(row['damage_usd'])
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
+
return df
|
| 275 |
+
|
| 276 |
+
# ===================================
|
| 277 |
+
# ANALYSIS FUNCTIONS
|
| 278 |
+
# ===================================
|
| 279 |
+
def mann_kendall_trend_test(data):
|
| 280 |
+
"""Perform Mann-Kendall trend test"""
|
| 281 |
+
n = len(data)
|
| 282 |
+
S = sum(np.sign(data[j] - data[i]) for i in range(n-1) for j in range(i+1, n))
|
| 283 |
+
var_s = n * (n - 1) * (2 * n + 5) / 18
|
| 284 |
+
Z = (S - 1) / np.sqrt(var_s) if S > 0 else (S + 1) / np.sqrt(var_s) if S < 0 else 0
|
| 285 |
+
p_value = 2 * (1 - stats.norm.cdf(abs(Z)))
|
| 286 |
+
trend = "Increasing" if p_value < 0.05 and S > 0 else "Decreasing" if p_value < 0.05 and S < 0 else "No significant trend"
|
| 287 |
+
return S, Z, p_value, trend
|
| 288 |
+
|
| 289 |
+
def create_flood_map(county_data, flood_df):
|
| 290 |
+
"""Create enhanced flood map"""
|
| 291 |
+
m = folium.Map(location=[35.5, -97.5], zoom_start=7)
|
| 292 |
|
| 293 |
+
# County markers
|
| 294 |
+
for county, info in county_data.items():
|
| 295 |
+
county_events = flood_df[flood_df['county'] == county]
|
| 296 |
+
if len(county_events) == 0: continue
|
| 297 |
+
|
| 298 |
+
event_count = len(county_events)
|
| 299 |
+
total_damage = county_events['damage_usd'].sum() / 1000000
|
| 300 |
+
severity_colors = {'High': 'red', 'Medium': 'orange', 'Low': 'green'}
|
| 301 |
+
color = severity_colors.get(info['severity_level'], 'gray')
|
| 302 |
+
|
| 303 |
+
popup_html = f"""
|
| 304 |
+
<div style="width: 300px;">
|
| 305 |
+
<h4>{info['full_name']} Analysis</h4>
|
| 306 |
+
<p><b>Events:</b> {event_count}</p>
|
| 307 |
+
<p><b>Total Damage:</b> ${total_damage:.1f}M</p>
|
| 308 |
+
<p><b>Risk Level:</b> {info['severity_level']}</p>
|
| 309 |
+
<p><b>Population:</b> {info['population']:,}</p>
|
| 310 |
+
<p><b>Research Notes:</b> {info['research_notes']}</p>
|
| 311 |
+
<p><b>Climate Projection:</b> {info['climate_projection']}</p>
|
| 312 |
+
</div>
|
| 313 |
+
"""
|
| 314 |
+
|
| 315 |
+
folium.Marker(
|
| 316 |
+
[info['latitude'], info['longitude']],
|
| 317 |
+
popup=folium.Popup(popup_html, max_width=350),
|
| 318 |
+
tooltip=f"{info['full_name']}: {event_count} events",
|
| 319 |
+
icon=folium.Icon(color=color, icon='info')
|
| 320 |
).add_to(m)
|
| 321 |
|
| 322 |
+
# Event markers
|
| 323 |
+
for _, event in flood_df.iterrows():
|
| 324 |
+
if event['county'] in county_data:
|
| 325 |
+
county_info = county_data[event['county']]
|
| 326 |
+
lat = county_info['latitude'] + np.random.uniform(-0.05, 0.05)
|
| 327 |
+
lon = county_info['longitude'] + np.random.uniform(-0.05, 0.05)
|
| 328 |
+
|
| 329 |
+
severity_colors = {'High': '#8b0000', 'Medium': '#ff8c00', 'Low': '#228b22'}
|
| 330 |
+
color = severity_colors.get(event['severity_level'], '#708090')
|
| 331 |
+
radius = {'High': 12, 'Medium': 8, 'Low': 5}.get(event['severity_level'], 5)
|
| 332 |
+
|
| 333 |
+
folium.CircleMarker(
|
| 334 |
+
[lat, lon], radius=radius,
|
| 335 |
+
popup=f"""
|
| 336 |
+
<b>{event['type']} - {event['date'].strftime('%Y-%m-%d')}</b><br>
|
| 337 |
+
Location: {event['location']}<br>
|
| 338 |
+
Damage: ${event['damage_usd']:,}<br>
|
| 339 |
+
Casualties: {event['fatalities'] + event['injuries']}<br>
|
| 340 |
+
Severity: {event['severity_level']}
|
| 341 |
+
""",
|
| 342 |
+
color=color, fill=True, fillOpacity=0.7
|
| 343 |
+
).add_to(m)
|
| 344 |
+
|
| 345 |
return m
|
| 346 |
|
| 347 |
+
# ===================================
|
| 348 |
+
# MAIN APPLICATION
|
| 349 |
+
# ===================================
|
| 350 |
+
def main():
|
| 351 |
+
# Header
|
| 352 |
+
st.markdown('<h1 class="main-header">π Advanced Oklahoma Flood Research Dashboard</h1>', unsafe_allow_html=True)
|
| 353 |
+
st.markdown('<p style="text-align: center; font-size: 1.2rem; color: #4a5568;">Comprehensive Multi-Source Flood Analysis (2015-2025)</p>', unsafe_allow_html=True)
|
|
|
|
| 354 |
|
| 355 |
+
# Research insights
|
| 356 |
+
st.markdown('<div class="insight-box">', unsafe_allow_html=True)
|
| 357 |
+
st.markdown("### π **Key Research Findings**")
|
| 358 |
+
col1, col2 = st.columns(2)
|
| 359 |
+
with col1:
|
| 360 |
+
st.markdown("""
|
| 361 |
+
**Climate Projections (2024 Study):**
|
| 362 |
+
- Native Americans face **68% higher** heavy rainfall risks
|
| 363 |
+
- **64% higher** flash flooding risks by 2090
|
| 364 |
+
- 4-inch rainfall events expected to **quadruple**
|
| 365 |
+
""")
|
| 366 |
+
with col2:
|
| 367 |
+
st.markdown("""
|
| 368 |
+
**Tribal Nations Vulnerability:**
|
| 369 |
+
- 39 tribal nations face elevated flood risk
|
| 370 |
+
- Muscogee Creek Nation most exposed
|
| 371 |
+
- 2019 Arkansas River flooding: **$3.4B** statewide damage
|
| 372 |
+
""")
|
| 373 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 374 |
|
| 375 |
+
# Load data
|
| 376 |
+
county_data = load_oklahoma_counties()
|
| 377 |
+
flood_df = load_oklahoma_flood_data()
|
| 378 |
+
|
| 379 |
+
# Sidebar filters
|
| 380 |
+
with st.sidebar:
|
| 381 |
+
st.header("π― Analysis Configuration")
|
| 382 |
+
|
| 383 |
+
county_options = ['All Counties'] + list(county_data.keys())
|
| 384 |
+
selected_county = st.selectbox("Select County", county_options)
|
| 385 |
+
|
| 386 |
+
severity_options = ['All Severities', 'High', 'Medium', 'Low']
|
| 387 |
+
selected_severity = st.selectbox("Filter by Severity", severity_options)
|
| 388 |
+
|
| 389 |
+
year_range = st.slider("Year Range", int(flood_df['year'].min()), int(flood_df['year'].max()),
|
| 390 |
+
(int(flood_df['year'].min()), int(flood_df['year'].max())))
|
| 391 |
+
|
| 392 |
+
flood_types = ['All Types'] + list(flood_df['type'].unique())
|
| 393 |
+
selected_type = st.selectbox("Flood Type", flood_types)
|
| 394 |
+
|
| 395 |
+
tribal_filter = st.selectbox("Tribal Analysis", ["All Events", "Tribal Impact Only", "Non-Tribal Only"])
|
| 396 |
+
|
| 397 |
+
research_mode = st.checkbox("Enhanced Research Mode", value=True)
|
| 398 |
|
| 399 |
+
# Apply filters
|
| 400 |
+
filtered_df = flood_df.copy()
|
| 401 |
+
if selected_county != 'All Counties':
|
| 402 |
+
filtered_df = filtered_df[filtered_df['county'] == selected_county]
|
| 403 |
+
if selected_severity != 'All Severities':
|
| 404 |
+
filtered_df = filtered_df[filtered_df['severity_level'] == selected_severity]
|
| 405 |
+
if selected_type != 'All Types':
|
| 406 |
+
filtered_df = filtered_df[filtered_df['type'] == selected_type]
|
| 407 |
+
filtered_df = filtered_df[(filtered_df['year'] >= year_range[0]) & (filtered_df['year'] <= year_range[1])]
|
| 408 |
+
if tribal_filter == "Tribal Impact Only":
|
| 409 |
+
filtered_df = filtered_df[filtered_df['tribal_impact'].str.contains('Nation|Tribe', na=False)]
|
| 410 |
+
elif tribal_filter == "Non-Tribal Only":
|
| 411 |
+
filtered_df = filtered_df[~filtered_df['tribal_impact'].str.contains('Nation|Tribe', na=False)]
|
| 412 |
|
| 413 |
+
if filtered_df.empty:
|
| 414 |
+
st.warning("β οΈ No events match selected criteria. Please adjust filters.")
|
| 415 |
+
return
|
| 416 |
|
| 417 |
+
# Summary metrics
|
| 418 |
+
col1, col2, col3, col4, col5, col6 = st.columns(6)
|
| 419 |
+
with col1:
|
| 420 |
+
st.markdown('<div class="metric-card">', unsafe_allow_html=True)
|
| 421 |
+
st.metric("Total Events", len(filtered_df))
|
| 422 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 423 |
+
with col2:
|
| 424 |
+
st.markdown('<div class="metric-card">', unsafe_allow_html=True)
|
| 425 |
+
st.metric("Economic Loss", f"${filtered_df['damage_usd'].sum()/1000000:.1f}M")
|
| 426 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 427 |
+
with col3:
|
| 428 |
+
st.markdown('<div class="metric-card">', unsafe_allow_html=True)
|
| 429 |
+
st.metric("Fatalities", int(filtered_df['fatalities'].sum()))
|
| 430 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 431 |
+
with col4:
|
| 432 |
+
st.markdown('<div class="metric-card">', unsafe_allow_html=True)
|
| 433 |
+
st.metric("High Severity", len(filtered_df[filtered_df['severity_level'] == 'High']))
|
| 434 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 435 |
+
with col5:
|
| 436 |
+
tribal_events = len(filtered_df[filtered_df['tribal_impact'].str.contains('Nation|Tribe', na=False)])
|
| 437 |
+
st.markdown('<div class="metric-card">', unsafe_allow_html=True)
|
| 438 |
+
st.metric("Tribal Areas Affected", tribal_events)
|
| 439 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 440 |
+
with col6:
|
| 441 |
+
avg_freq = len(filtered_df) / (year_range[1] - year_range[0] + 1)
|
| 442 |
+
st.markdown('<div class="metric-card">', unsafe_allow_html=True)
|
| 443 |
+
st.metric("Annual Frequency", f"{avg_freq:.1f}")
|
| 444 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 445 |
|
| 446 |
+
# Interactive Map
|
| 447 |
+
st.markdown("### πΊοΈ **Interactive Flood Analysis Map**")
|
| 448 |
+
flood_map = create_flood_map(county_data, filtered_df)
|
| 449 |
+
st_folium(flood_map, width=700, height=500)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 450 |
|
| 451 |
+
# Analysis Tabs
|
| 452 |
+
if research_mode:
|
| 453 |
+
tabs = st.tabs(["π
Temporal Analysis", "πΊοΈ Spatial Analysis", "π° Impact Analysis",
|
| 454 |
+
"π Risk Analysis", "π Comparative Analysis", "ποΈ Tribal Analysis", "π Data Export"])
|
| 455 |
+
else:
|
| 456 |
+
tabs = st.tabs(["π
Temporal Patterns", "πΊοΈ Geographic Analysis", "π° Economic Impact", "π Event Records"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
|
| 458 |
+
# Tab 1: Temporal Analysis
|
| 459 |
+
with tabs[0]:
|
| 460 |
+
st.markdown("### π
**Advanced Temporal Analysis**")
|
| 461 |
+
|
| 462 |
+
# Statistical insights
|
| 463 |
+
annual_counts = filtered_df.groupby('year').size()
|
| 464 |
+
annual_damages = filtered_df.groupby('year')['damage_usd'].sum()
|
| 465 |
+
|
| 466 |
+
if len(annual_counts) >= 3:
|
| 467 |
+
S, Z, p_value, trend = mann_kendall_trend_test(annual_counts.values)
|
| 468 |
+
st.markdown('<div class="statistical-box">', unsafe_allow_html=True)
|
| 469 |
+
st.markdown(f"**Mann-Kendall Trend Test:** {trend} (Z={Z:.3f}, p={p_value:.3f})")
|
| 470 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 471 |
+
|
| 472 |
+
# Temporal visualizations
|
| 473 |
+
fig_temporal = make_subplots(rows=2, cols=2, subplot_titles=(
|
| 474 |
+
'Annual Flood Frequency', 'Seasonal Patterns', 'Damage Timeline', 'Monthly Distribution'))
|
| 475 |
+
|
| 476 |
+
# Annual frequency
|
| 477 |
+
fig_temporal.add_trace(go.Scatter(x=annual_counts.index, y=annual_counts.values,
|
| 478 |
+
mode='lines+markers', name='Annual Events'), row=1, col=1)
|
| 479 |
+
|
| 480 |
+
# Seasonal patterns
|
| 481 |
+
seasonal_data = filtered_df.groupby('season').size()
|
| 482 |
+
fig_temporal.add_trace(go.Bar(x=seasonal_data.index, y=seasonal_data.values,
|
| 483 |
+
name='Seasonal Events'), row=1, col=2)
|
| 484 |
+
|
| 485 |
+
# Damage timeline
|
| 486 |
+
fig_temporal.add_trace(go.Scatter(x=annual_damages.index, y=annual_damages.values/1e6,
|
| 487 |
+
mode='lines+markers', name='Annual Damage ($M)'), row=2, col=1)
|
| 488 |
+
|
| 489 |
+
# Monthly distribution
|
| 490 |
+
monthly_data = filtered_df.groupby('month').size()
|
| 491 |
+
fig_temporal.add_trace(go.Bar(x=monthly_data.index, y=monthly_data.values,
|
| 492 |
+
name='Monthly Events'), row=2, col=2)
|
| 493 |
+
|
| 494 |
+
fig_temporal.update_layout(height=800, showlegend=False)
|
| 495 |
+
st.plotly_chart(fig_temporal, use_container_width=True)
|
| 496 |
+
|
| 497 |
+
# Key findings
|
| 498 |
+
peak_month = filtered_df['month'].value_counts().index[0]
|
| 499 |
+
month_names = {1:'Jan', 2:'Feb', 3:'Mar', 4:'Apr', 5:'May', 6:'Jun',
|
| 500 |
+
7:'Jul', 8:'Aug', 9:'Sep', 10:'Oct', 11:'Nov', 12:'Dec'}
|
| 501 |
+
|
| 502 |
+
st.markdown('<div class="insight-box">', unsafe_allow_html=True)
|
| 503 |
+
st.markdown(f"""
|
| 504 |
+
**Key Temporal Findings:**
|
| 505 |
+
- **Peak Month:** {month_names[peak_month]} ({len(filtered_df[filtered_df['month'] == peak_month])} events)
|
| 506 |
+
- **Spring Dominance:** {len(filtered_df[filtered_df['season'] == 'Spring'])} events
|
| 507 |
+
- **Recent Activity:** {len(filtered_df[filtered_df['year'] >= 2020])} events since 2020
|
| 508 |
+
""")
|
| 509 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 510 |
+
|
| 511 |
+
# Tab 2: Spatial Analysis
|
| 512 |
+
with tabs[1]:
|
| 513 |
+
st.markdown("### πΊοΈ **Spatial Analysis**")
|
| 514 |
+
|
| 515 |
+
# County-level analysis
|
| 516 |
+
county_stats = filtered_df.groupby('county').agg({
|
| 517 |
+
'damage_usd': ['sum', 'mean', 'count'],
|
| 518 |
+
'fatalities': 'sum',
|
| 519 |
+
'injuries': 'sum'
|
| 520 |
+
}).round(2)
|
| 521 |
+
county_stats.columns = ['total_damage', 'avg_damage', 'events', 'fatalities', 'injuries']
|
| 522 |
+
county_stats['risk_score'] = (county_stats['total_damage']/1e6 * 0.4 +
|
| 523 |
+
county_stats['events'] * 0.3 +
|
| 524 |
+
(county_stats['fatalities'] + county_stats['injuries']) * 0.3)
|
| 525 |
+
|
| 526 |
+
fig_spatial = make_subplots(rows=2, cols=2, subplot_titles=(
|
| 527 |
+
'Events by County', 'Economic Impact', 'Risk Assessment', 'Casualties by County'))
|
| 528 |
+
|
| 529 |
+
# Events by county
|
| 530 |
+
county_names = [county_data[c]['full_name'] for c in county_stats.index]
|
| 531 |
+
fig_spatial.add_trace(go.Bar(x=county_names, y=county_stats['events'],
|
| 532 |
+
name='Events'), row=1, col=1)
|
| 533 |
+
|
| 534 |
+
# Economic impact
|
| 535 |
+
fig_spatial.add_trace(go.Scatter(x=county_stats['events'], y=county_stats['total_damage']/1e6,
|
| 536 |
+
mode='markers', marker=dict(size=10),
|
| 537 |
+
text=county_names, name='Damage vs Events'), row=1, col=2)
|
| 538 |
+
|
| 539 |
+
# Risk assessment
|
| 540 |
+
fig_spatial.add_trace(go.Bar(x=county_names, y=county_stats['risk_score'],
|
| 541 |
+
name='Risk Score'), row=2, col=1)
|
| 542 |
+
|
| 543 |
+
# Casualties
|
| 544 |
+
fig_spatial.add_trace(go.Bar(x=county_names, y=county_stats['fatalities'] + county_stats['injuries'],
|
| 545 |
+
name='Casualties'), row=2, col=2)
|
| 546 |
+
|
| 547 |
+
fig_spatial.update_layout(height=800, showlegend=False)
|
| 548 |
+
st.plotly_chart(fig_spatial, use_container_width=True)
|
| 549 |
+
|
| 550 |
+
# County heatmap
|
| 551 |
+
st.markdown("### π₯ **County Damage Heatmap**")
|
| 552 |
+
heatmap_data = filtered_df.pivot_table(index='county', columns='year',
|
| 553 |
+
values='damage_usd', aggfunc='sum', fill_value=0) / 1e6
|
| 554 |
+
|
| 555 |
+
fig_heatmap = go.Figure(data=go.Heatmap(z=heatmap_data.values, x=heatmap_data.columns,
|
| 556 |
+
y=[county_data[c]['full_name'] for c in heatmap_data.index],
|
| 557 |
+
colorscale='Reds'))
|
| 558 |
+
fig_heatmap.update_layout(title="Annual Damage by County ($M)", height=400)
|
| 559 |
+
st.plotly_chart(fig_heatmap, use_container_width=True)
|
| 560 |
+
|
| 561 |
+
# Tab 3: Impact Analysis
|
| 562 |
+
with tabs[2]:
|
| 563 |
+
st.markdown("### π° **Impact & Damage Analysis**")
|
| 564 |
+
|
| 565 |
+
# Impact statistics
|
| 566 |
+
total_damage = filtered_df['damage_usd'].sum()
|
| 567 |
+
mean_damage = filtered_df['damage_usd'].mean()
|
| 568 |
+
total_casualties = filtered_df['fatalities'].sum() + filtered_df['injuries'].sum()
|
| 569 |
+
|
| 570 |
+
st.markdown('<div class="statistical-box">', unsafe_allow_html=True)
|
| 571 |
+
col1, col2 = st.columns(2)
|
| 572 |
+
with col1:
|
| 573 |
+
st.markdown(f"""
|
| 574 |
+
**Economic Impact:**
|
| 575 |
+
- Total Damage: ${total_damage/1e6:.1f}M
|
| 576 |
+
- Average per Event: ${mean_damage/1e6:.2f}M
|
| 577 |
+
- High Severity Events: {len(filtered_df[filtered_df['severity_level'] == 'High'])}
|
| 578 |
+
""")
|
| 579 |
+
with col2:
|
| 580 |
+
st.markdown(f"""
|
| 581 |
+
**Human Impact:**
|
| 582 |
+
- Total Casualties: {total_casualties}
|
| 583 |
+
- Events with Casualties: {len(filtered_df[filtered_df['fatalities'] + filtered_df['injuries'] > 0])}
|
| 584 |
+
- Fatality Rate: {filtered_df['fatalities'].sum()/len(filtered_df)*100:.1f}%
|
| 585 |
+
""")
|
| 586 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 587 |
+
|
| 588 |
+
# Impact visualizations
|
| 589 |
+
fig_impact = make_subplots(rows=2, cols=2, subplot_titles=(
|
| 590 |
+
'Damage vs Casualties', 'Severity Distribution', 'Damage Classification', 'Rainfall vs Damage'))
|
| 591 |
+
|
| 592 |
+
# Bubble chart
|
| 593 |
+
fig_impact.add_trace(go.Scatter(x=filtered_df['fatalities'], y=filtered_df['damage_usd']/1e6,
|
| 594 |
+
mode='markers',
|
| 595 |
+
marker=dict(size=filtered_df['injuries']*2+8, opacity=0.7),
|
| 596 |
+
text=filtered_df['county'], name='Events'), row=1, col=1)
|
| 597 |
+
|
| 598 |
+
# Severity distribution
|
| 599 |
+
severity_counts = filtered_df['severity_level'].value_counts()
|
| 600 |
+
fig_impact.add_trace(go.Pie(labels=severity_counts.index, values=severity_counts.values,
|
| 601 |
+
name='Severity'), row=1, col=2)
|
| 602 |
+
|
| 603 |
+
# Damage classification
|
| 604 |
+
damage_counts = filtered_df['damage_classification'].value_counts()
|
| 605 |
+
fig_impact.add_trace(go.Bar(x=damage_counts.index, y=damage_counts.values,
|
| 606 |
+
name='Classification'), row=2, col=1)
|
| 607 |
+
|
| 608 |
+
# Rainfall correlation
|
| 609 |
+
fig_impact.add_trace(go.Scatter(x=filtered_df['rain_inches'], y=filtered_df['damage_usd']/1e6,
|
| 610 |
+
mode='markers', name='Rainfall vs Damage'), row=2, col=2)
|
| 611 |
+
|
| 612 |
+
fig_impact.update_layout(height=800, showlegend=False)
|
| 613 |
+
st.plotly_chart(fig_impact, use_container_width=True)
|
| 614 |
|
| 615 |
+
if research_mode:
|
| 616 |
+
# Tab 4: Risk Analysis
|
| 617 |
+
with tabs[3]:
|
| 618 |
+
st.markdown("### π **Probability & Risk Analysis**")
|
| 619 |
+
|
| 620 |
+
# Return period analysis
|
| 621 |
+
annual_max_damages = filtered_df.groupby('year')['damage_usd'].max().values
|
| 622 |
+
if len(annual_max_damages) > 0:
|
| 623 |
+
sorted_damages = np.sort(annual_max_damages)[::-1]
|
| 624 |
+
n = len(sorted_damages)
|
| 625 |
+
return_periods = (n + 1) / np.arange(1, n + 1)
|
| 626 |
+
|
| 627 |
+
fig_risk = make_subplots(rows=2, cols=2, subplot_titles=(
|
| 628 |
+
'Flood Frequency Curve', 'Exceedance Probability', 'Risk by County', 'Confidence Intervals'))
|
| 629 |
+
|
| 630 |
+
# Frequency curve
|
| 631 |
+
fig_risk.add_trace(go.Scatter(x=return_periods, y=sorted_damages/1e6,
|
| 632 |
+
mode='lines+markers', name='Frequency Curve'), row=1, col=1)
|
| 633 |
+
|
| 634 |
+
# Exceedance probability
|
| 635 |
+
exceedance_prob = np.arange(1, n + 1) / (n + 1)
|
| 636 |
+
fig_risk.add_trace(go.Scatter(x=sorted_damages/1e6, y=exceedance_prob*100,
|
| 637 |
+
mode='lines+markers', name='Exceedance'), row=1, col=2)
|
| 638 |
+
|
| 639 |
+
# Risk by county
|
| 640 |
+
county_risk = filtered_df.groupby('county')['damage_usd'].mean()
|
| 641 |
+
fig_risk.add_trace(go.Bar(x=[county_data[c]['full_name'] for c in county_risk.index],
|
| 642 |
+
y=county_risk.values/1e6, name='Mean Damage'), row=2, col=1)
|
| 643 |
+
|
| 644 |
+
# Confidence intervals
|
| 645 |
+
years = sorted(filtered_df['year'].unique())
|
| 646 |
+
annual_means = [filtered_df[filtered_df['year']==y]['damage_usd'].mean()/1e6 for y in years]
|
| 647 |
+
fig_risk.add_trace(go.Scatter(x=years, y=annual_means,
|
| 648 |
+
mode='lines+markers', name='Annual Mean'), row=2, col=2)
|
| 649 |
+
|
| 650 |
+
fig_risk.update_layout(height=800, showlegend=False)
|
| 651 |
+
st.plotly_chart(fig_risk, use_container_width=True)
|
| 652 |
|
| 653 |
+
# Tab 5: Comparative Analysis
|
| 654 |
+
with tabs[4]:
|
| 655 |
+
st.markdown("### π **Comparative Analysis**")
|
| 656 |
+
|
| 657 |
+
# Period comparison
|
| 658 |
+
period1 = filtered_df[filtered_df['year'] <= 2018]
|
| 659 |
+
period2 = filtered_df[filtered_df['year'] >= 2019]
|
| 660 |
+
|
| 661 |
+
st.markdown('<div class="statistical-box">', unsafe_allow_html=True)
|
| 662 |
+
col1, col2 = st.columns(2)
|
| 663 |
+
with col1:
|
| 664 |
+
st.markdown(f"""
|
| 665 |
+
**Period 1 (2015-2018):**
|
| 666 |
+
- Events: {len(period1)}
|
| 667 |
+
- Total Damage: ${period1['damage_usd'].sum()/1e6:.1f}M
|
| 668 |
+
- Avg per Event: ${period1['damage_usd'].mean()/1e6:.2f}M
|
| 669 |
+
""")
|
| 670 |
+
with col2:
|
| 671 |
+
st.markdown(f"""
|
| 672 |
+
**Period 2 (2019-2025):**
|
| 673 |
+
- Events: {len(period2)}
|
| 674 |
+
- Total Damage: ${period2['damage_usd'].sum()/1e6:.1f}M
|
| 675 |
+
- Avg per Event: ${period2['damage_usd'].mean()/1e6:.2f}M
|
| 676 |
+
""")
|
| 677 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 678 |
+
|
| 679 |
+
# Comparative visualizations
|
| 680 |
+
fig_comp = make_subplots(rows=2, cols=2, subplot_titles=(
|
| 681 |
+
'Period Comparison', 'Flood Type Distribution', 'Seasonal Matrix', 'Tribal vs Non-Tribal'))
|
| 682 |
+
|
| 683 |
+
# Period comparison
|
| 684 |
+
comparison_data = {'Period': ['2015-2018', '2019-2025'],
|
| 685 |
+
'Events': [len(period1), len(period2)],
|
| 686 |
+
'Damage': [period1['damage_usd'].sum()/1e6, period2['damage_usd'].sum()/1e6]}
|
| 687 |
+
fig_comp.add_trace(go.Bar(x=comparison_data['Period'], y=comparison_data['Events'],
|
| 688 |
+
name='Events'), row=1, col=1)
|
| 689 |
+
|
| 690 |
+
# Flood type distribution
|
| 691 |
+
type_data = filtered_df.groupby(['type', 'severity_level']).size().unstack(fill_value=0)
|
| 692 |
+
for severity in ['High', 'Medium', 'Low']:
|
| 693 |
+
if severity in type_data.columns:
|
| 694 |
+
fig_comp.add_trace(go.Bar(x=type_data.index, y=type_data[severity],
|
| 695 |
+
name=f'{severity} Severity'), row=1, col=2)
|
| 696 |
+
|
| 697 |
+
# Seasonal matrix
|
| 698 |
+
seasonal_matrix = filtered_df.groupby(['season', 'year']).size().unstack(fill_value=0)
|
| 699 |
+
fig_comp.add_trace(go.Heatmap(z=seasonal_matrix.values, x=seasonal_matrix.columns,
|
| 700 |
+
y=seasonal_matrix.index), row=2, col=1)
|
| 701 |
+
|
| 702 |
+
# Tribal comparison
|
| 703 |
+
tribal_events = filtered_df[filtered_df['tribal_impact'].str.contains('Nation|Tribe', na=False)]
|
| 704 |
+
non_tribal = filtered_df[~filtered_df['tribal_impact'].str.contains('Nation|Tribe', na=False)]
|
| 705 |
+
|
| 706 |
+
tribal_comparison = {'Category': ['Events', 'Avg Damage ($M)'],
|
| 707 |
+
'Tribal': [len(tribal_events), tribal_events['damage_usd'].mean()/1e6 if len(tribal_events) > 0 else 0],
|
| 708 |
+
'Non-Tribal': [len(non_tribal), non_tribal['damage_usd'].mean()/1e6 if len(non_tribal) > 0 else 0]}
|
| 709 |
+
|
| 710 |
+
fig_comp.add_trace(go.Bar(x=tribal_comparison['Category'], y=tribal_comparison['Tribal'],
|
| 711 |
+
name='Tribal Areas'), row=2, col=2)
|
| 712 |
+
fig_comp.add_trace(go.Bar(x=tribal_comparison['Category'], y=tribal_comparison['Non-Tribal'],
|
| 713 |
+
name='Non-Tribal Areas'), row=2, col=2)
|
| 714 |
+
|
| 715 |
+
fig_comp.update_layout(height=800, showlegend=False)
|
| 716 |
+
st.plotly_chart(fig_comp, use_container_width=True)
|
| 717 |
|
| 718 |
+
# Tab 6: Tribal Analysis
|
| 719 |
+
with tabs[5]:
|
| 720 |
+
st.markdown("### ποΈ **Tribal Nations Impact Analysis**")
|
| 721 |
+
|
| 722 |
+
tribal_events = filtered_df[filtered_df['tribal_impact'].str.contains('Nation|Tribe', na=False)]
|
| 723 |
+
|
| 724 |
+
if len(tribal_events) > 0:
|
| 725 |
+
st.markdown('<div class="statistical-box">', unsafe_allow_html=True)
|
| 726 |
+
st.markdown(f"""
|
| 727 |
+
**Tribal Impact Statistics:**
|
| 728 |
+
- Events Affecting Tribal Areas: {len(tribal_events)}
|
| 729 |
+
- Total Tribal Damage: ${tribal_events['damage_usd'].sum()/1e6:.1f}M
|
| 730 |
+
- Average Tribal Event Damage: ${tribal_events['damage_usd'].mean()/1e6:.2f}M
|
| 731 |
+
- Tribal Casualty Rate: {(tribal_events['fatalities'].sum() + tribal_events['injuries'].sum())/len(tribal_events):.2f} per event
|
| 732 |
+
""")
|
| 733 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 734 |
+
|
| 735 |
+
# Tribal visualizations
|
| 736 |
+
fig_tribal = make_subplots(rows=2, cols=2, subplot_titles=(
|
| 737 |
+
'Tribal Events by County', 'Tribal Damage Timeline', 'Tribal Severity Distribution', 'Tribal Nations Affected'))
|
| 738 |
+
|
| 739 |
+
# Events by county
|
| 740 |
+
tribal_county = tribal_events.groupby('county').size()
|
| 741 |
+
fig_tribal.add_trace(go.Bar(x=[county_data[c]['full_name'] for c in tribal_county.index],
|
| 742 |
+
y=tribal_county.values, name='Tribal Events'), row=1, col=1)
|
| 743 |
+
|
| 744 |
+
# Damage timeline
|
| 745 |
+
tribal_annual = tribal_events.groupby('year')['damage_usd'].sum()
|
| 746 |
+
fig_tribal.add_trace(go.Scatter(x=tribal_annual.index, y=tribal_annual.values/1e6,
|
| 747 |
+
mode='lines+markers', name='Annual Damage'), row=1, col=2)
|
| 748 |
+
|
| 749 |
+
# Severity distribution
|
| 750 |
+
tribal_severity = tribal_events['severity_level'].value_counts()
|
| 751 |
+
fig_tribal.add_trace(go.Pie(labels=tribal_severity.index, values=tribal_severity.values,
|
| 752 |
+
name='Severity'), row=2, col=1)
|
| 753 |
+
|
| 754 |
+
# Most affected nations
|
| 755 |
+
nation_impacts = {}
|
| 756 |
+
for _, row in tribal_events.iterrows():
|
| 757 |
+
county_nations = county_data[row['county']]['tribal_nations']
|
| 758 |
+
for nation in county_nations:
|
| 759 |
+
if nation not in nation_impacts:
|
| 760 |
+
nation_impacts[nation] = 0
|
| 761 |
+
nation_impacts[nation] += row['damage_usd']
|
| 762 |
+
|
| 763 |
+
if nation_impacts:
|
| 764 |
+
sorted_nations = sorted(nation_impacts.items(), key=lambda x: x[1], reverse=True)[:5]
|
| 765 |
+
fig_tribal.add_trace(go.Bar(x=[n[0] for n in sorted_nations],
|
| 766 |
+
y=[n[1]/1e6 for n in sorted_nations],
|
| 767 |
+
name='Nation Damage'), row=2, col=2)
|
| 768 |
+
|
| 769 |
+
fig_tribal.update_layout(height=800, showlegend=False)
|
| 770 |
+
st.plotly_chart(fig_tribal, use_container_width=True)
|
| 771 |
+
else:
|
| 772 |
+
st.info("No tribal impact events in current selection.")
|
| 773 |
|
| 774 |
+
# Tab 7: Data Export
|
| 775 |
+
with tabs[6]:
|
| 776 |
+
st.markdown("### π **Research Data Export**")
|
| 777 |
+
|
| 778 |
+
col1, col2, col3 = st.columns(3)
|
| 779 |
+
|
| 780 |
+
with col1:
|
| 781 |
+
# CSV export
|
| 782 |
+
csv_data = filtered_df.copy()
|
| 783 |
+
csv_data['county_full_name'] = csv_data['county'].map(lambda x: county_data[x]['full_name'])
|
| 784 |
+
csv_data['damage_millions'] = csv_data['damage_usd'] / 1e6
|
| 785 |
+
csv_data['total_casualties'] = csv_data['fatalities'] + csv_data['injuries']
|
| 786 |
+
|
| 787 |
+
st.download_button(
|
| 788 |
+
label="π Download CSV Data",
|
| 789 |
+
data=csv_data.to_csv(index=False),
|
| 790 |
+
file_name=f"oklahoma_floods_{datetime.now().strftime('%Y%m%d')}.csv",
|
| 791 |
+
mime="text/csv"
|
| 792 |
+
)
|
| 793 |
+
|
| 794 |
+
with col2:
|
| 795 |
+
# Summary report
|
| 796 |
+
report = f"""
|
| 797 |
+
OKLAHOMA FLOOD RESEARCH SUMMARY
|
| 798 |
+
Generated: {datetime.now().strftime('%Y-%m-%d')}
|
| 799 |
|
| 800 |
+
DATASET OVERVIEW:
|
| 801 |
+
- Time Period: {filtered_df['year'].min()}-{filtered_df['year'].max()}
|
| 802 |
+
- Total Events: {len(filtered_df)}
|
| 803 |
+
- Counties Covered: {filtered_df['county'].nunique()}
|
| 804 |
|
| 805 |
+
IMPACT SUMMARY:
|
| 806 |
+
- Total Economic Loss: ${filtered_df['damage_usd'].sum()/1e6:.1f} million
|
| 807 |
+
- Total Fatalities: {filtered_df['fatalities'].sum()}
|
| 808 |
+
- Total Injuries: {filtered_df['injuries'].sum()}
|
| 809 |
+
- High Severity Events: {len(filtered_df[filtered_df['severity_level'] == 'High'])}
|
| 810 |
|
| 811 |
+
TRIBAL IMPACT:
|
| 812 |
+
- Events Affecting Tribal Areas: {len(filtered_df[filtered_df['tribal_impact'].str.contains('Nation|Tribe', na=False)])}
|
| 813 |
+
- Tribal Damage: ${filtered_df[filtered_df['tribal_impact'].str.contains('Nation|Tribe', na=False)]['damage_usd'].sum()/1e6:.1f}M
|
| 814 |
+
|
| 815 |
+
KEY FINDINGS:
|
| 816 |
+
- Peak Activity: {filtered_df['season'].value_counts().index[0]} season
|
| 817 |
+
- Most Affected County: {county_data[filtered_df.groupby('county')['damage_usd'].sum().idxmax()]['full_name']}
|
| 818 |
+
- Dominant Flood Type: {filtered_df['type'].value_counts().index[0]}
|
| 819 |
+
|
| 820 |
+
Research validates 2024 climate projections of 64-68% higher flood risks for tribal communities.
|
| 821 |
+
"""
|
| 822 |
+
|
| 823 |
+
st.download_button(
|
| 824 |
+
label="π Download Summary Report",
|
| 825 |
+
data=report,
|
| 826 |
+
file_name=f"oklahoma_flood_summary_{datetime.now().strftime('%Y%m%d')}.txt",
|
| 827 |
+
mime="text/plain"
|
| 828 |
+
)
|
| 829 |
+
|
| 830 |
+
with col3:
|
| 831 |
+
# Research citations
|
| 832 |
+
citations = """
|
| 833 |
+
OKLAHOMA FLOOD RESEARCH CITATIONS
|
| 834 |
+
|
| 835 |
+
PRIMARY SOURCES:
|
| 836 |
+
- USGS (1964): Floods in Oklahoma: Magnitude and Frequency
|
| 837 |
+
- Native American Climate Study (2024): Future Heavy Rainfall and Flood Risks
|
| 838 |
+
- Oklahoma Emergency Management: Damage Assessment Reports
|
| 839 |
+
- Tribal Nations Emergency Management: Community Impact Reports
|
| 840 |
+
|
| 841 |
+
STATISTICAL METHODS:
|
| 842 |
+
- Mann-Kendall Trend Analysis
|
| 843 |
+
- Weibull Distribution for Return Periods
|
| 844 |
+
- Multi-source data validation
|
| 845 |
+
|
| 846 |
+
RESEARCH VALIDATION:
|
| 847 |
+
Current findings align with 2024 Climate Study projections and USGS historical analysis.
|
| 848 |
+
"""
|
| 849 |
+
|
| 850 |
+
st.download_button(
|
| 851 |
+
label="π Download Citations",
|
| 852 |
+
data=citations,
|
| 853 |
+
file_name=f"oklahoma_flood_citations_{datetime.now().strftime('%Y%m%d')}.txt",
|
| 854 |
+
mime="text/plain"
|
| 855 |
+
)
|
| 856 |
+
|
| 857 |
+
else:
|
| 858 |
+
# Simple mode - Tab 4: Event Records
|
| 859 |
+
with tabs[3]:
|
| 860 |
+
st.markdown("### π **Event Records**")
|
| 861 |
+
|
| 862 |
+
# Display table
|
| 863 |
+
display_df = filtered_df[['date', 'county', 'type', 'severity_level', 'damage_usd',
|
| 864 |
+
'fatalities', 'injuries', 'rain_inches']].copy()
|
| 865 |
+
display_df['county'] = display_df['county'].map(lambda x: county_data[x]['full_name'])
|
| 866 |
+
display_df['damage_millions'] = display_df['damage_usd'] / 1e6
|
| 867 |
+
display_df['date'] = display_df['date'].dt.strftime('%Y-%m-%d')
|
| 868 |
+
|
| 869 |
+
st.dataframe(
|
| 870 |
+
display_df[['date', 'county', 'type', 'severity_level', 'damage_millions',
|
| 871 |
+
'fatalities', 'injuries', 'rain_inches']],
|
| 872 |
+
column_config={
|
| 873 |
+
'date': 'Date',
|
| 874 |
+
'county': 'County',
|
| 875 |
+
'type': 'Flood Type',
|
| 876 |
+
'severity_level': 'Severity',
|
| 877 |
+
'damage_millions': st.column_config.NumberColumn('Damage ($M)', format="%.2f"),
|
| 878 |
+
'fatalities': 'Fatalities',
|
| 879 |
+
'injuries': 'Injuries',
|
| 880 |
+
'rain_inches': st.column_config.NumberColumn('Rainfall (in)', format="%.1f")
|
| 881 |
+
},
|
| 882 |
+
use_container_width=True
|
| 883 |
+
)
|
| 884 |
+
|
| 885 |
+
if __name__ == "__main__":
|
| 886 |
+
main()
|