Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1205,10 +1205,8 @@ def create_genesis_animation(prediction_data, enable_animation=True):
|
|
1205 |
opacity=0.6,
|
1206 |
showscale=(day_idx == 0),
|
1207 |
colorbar=dict(
|
1208 |
-
title=
|
1209 |
-
|
1210 |
-
side="right"
|
1211 |
-
)
|
1212 |
) if day_idx == 0 else None
|
1213 |
),
|
1214 |
name='Genesis Potential',
|
@@ -1238,160 +1236,9 @@ def create_genesis_animation(prediction_data, enable_animation=True):
|
|
1238 |
intensities = [pt['intensity'] for pt in current_track]
|
1239 |
categories = [pt['category'] for pt in current_track]
|
1240 |
|
1241 |
-
#
|
1242 |
-
|
1243 |
-
for intensity in intensities:
|
1244 |
-
if intensity < 34:
|
1245 |
-
colors.append('#80808080') # Gray - TD
|
1246 |
-
elif intensity < 64:
|
1247 |
-
colors.append('#0000FF80') # Blue - TS
|
1248 |
-
elif intensity < 83:
|
1249 |
-
colors.append('#00FFFF80') # Cyan - C1
|
1250 |
-
elif intensity < 96:
|
1251 |
-
colors.append('#00FF0080') # Green - C2
|
1252 |
-
elif intensity < 113:
|
1253 |
-
colors.append('#FFFF0080') # Yellow - C3
|
1254 |
-
elif intensity < 137:
|
1255 |
-
colors.append('#FFA50080') # Orange - C4
|
1256 |
-
else:
|
1257 |
-
colors.append('#FF000080') # Red - C5
|
1258 |
|
1259 |
-
# 3. HISTORICAL TRACK (Past movement)
|
1260 |
-
if len(current_track) > 1:
|
1261 |
-
frame_data.append(
|
1262 |
-
go.Scattergeo(
|
1263 |
-
lat=lats[:-1], # All except current position
|
1264 |
-
lon=lons[:-1],
|
1265 |
-
mode='lines+markers',
|
1266 |
-
line=dict(
|
1267 |
-
color='rgba(100,100,100,0.7)',
|
1268 |
-
width=3
|
1269 |
-
),
|
1270 |
-
marker=dict(
|
1271 |
-
size=[max(6, int/8) for int in intensities[:-1]],
|
1272 |
-
color=colors[:-1],
|
1273 |
-
line=dict(width=1, color='white')
|
1274 |
-
),
|
1275 |
-
name=f'Storm {storm_id} Track',
|
1276 |
-
showlegend=(storm_idx == 0 and day_idx == 0),
|
1277 |
-
legendgroup=f'storm_{storm_id}',
|
1278 |
-
hovertemplate=(
|
1279 |
-
f'<b>Storm {storm_id} History</b><br>'
|
1280 |
-
'Lat: %{lat:.1f}°N<br>'
|
1281 |
-
'Lon: %{lon:.1f}°E<br>'
|
1282 |
-
'<extra></extra>'
|
1283 |
-
)
|
1284 |
-
)
|
1285 |
-
)
|
1286 |
-
|
1287 |
-
# 4. CURRENT POSITION (Big marker like operational forecasts)
|
1288 |
-
current_pos = current_track[-1]
|
1289 |
-
current_intensity = current_pos['intensity']
|
1290 |
-
current_category = current_pos['category']
|
1291 |
-
|
1292 |
-
# Get current position color
|
1293 |
-
if current_intensity < 34:
|
1294 |
-
current_color = '#808080' # Gray - TD
|
1295 |
-
elif current_intensity < 64:
|
1296 |
-
current_color = '#0000FF' # Blue - TS
|
1297 |
-
elif current_intensity < 83:
|
1298 |
-
current_color = '#00FFFF' # Cyan - C1
|
1299 |
-
elif current_intensity < 96:
|
1300 |
-
current_color = '#00FF00' # Green - C2
|
1301 |
-
elif current_intensity < 113:
|
1302 |
-
current_color = '#FFFF00' # Yellow - C3
|
1303 |
-
elif current_intensity < 137:
|
1304 |
-
current_color = '#FFA500' # Orange - C4
|
1305 |
-
else:
|
1306 |
-
current_color = '#FF0000' # Red - C5
|
1307 |
-
|
1308 |
-
frame_data.append(
|
1309 |
-
go.Scattergeo(
|
1310 |
-
lat=[current_pos['lat']],
|
1311 |
-
lon=[current_pos['lon']],
|
1312 |
-
mode='markers',
|
1313 |
-
marker=dict(
|
1314 |
-
size=max(15, current_intensity/4),
|
1315 |
-
color=current_color,
|
1316 |
-
symbol='circle',
|
1317 |
-
line=dict(width=3, color='white'),
|
1318 |
-
opacity=1.0
|
1319 |
-
),
|
1320 |
-
name=f'Storm {storm_id} Current',
|
1321 |
-
showlegend=(storm_idx == 0 and day_idx == 0),
|
1322 |
-
legendgroup=f'storm_{storm_id}',
|
1323 |
-
hovertemplate=(
|
1324 |
-
f'<b>STORM {storm_id}</b><br>'
|
1325 |
-
f'Day {day:.1f} of {month:02d}/{year}<br>'
|
1326 |
-
f'Position: %{{lat:.1f}}°N, %{{lon:.1f}}°E<br>'
|
1327 |
-
f'Intensity: {current_intensity:.0f} kt<br>'
|
1328 |
-
f'Category: {current_category}<br>'
|
1329 |
-
f'Pressure: {current_pos["pressure"]:.0f} hPa<br>'
|
1330 |
-
f'Uncertainty: ±{current_pos["position_uncertainty"]:.1f}°<br>'
|
1331 |
-
'<extra></extra>'
|
1332 |
-
)
|
1333 |
-
)
|
1334 |
-
)
|
1335 |
-
|
1336 |
-
# 5. UNCERTAINTY CONE (Growing with time like NHC)
|
1337 |
-
if len(current_track) > 1:
|
1338 |
-
uncertainty = current_pos['position_uncertainty']
|
1339 |
-
center_lat = current_pos['lat']
|
1340 |
-
center_lon = current_pos['lon']
|
1341 |
-
|
1342 |
-
# Create uncertainty circle
|
1343 |
-
circle_lats = []
|
1344 |
-
circle_lons = []
|
1345 |
-
for angle in np.linspace(0, 2*np.pi, 20):
|
1346 |
-
circle_lats.append(center_lat + uncertainty * np.cos(angle))
|
1347 |
-
circle_lons.append(center_lon + uncertainty * np.sin(angle))
|
1348 |
-
|
1349 |
-
frame_data.append(
|
1350 |
-
go.Scattergeo(
|
1351 |
-
lat=circle_lats,
|
1352 |
-
lon=circle_lons,
|
1353 |
-
mode='lines',
|
1354 |
-
line=dict(
|
1355 |
-
color='rgba(255,0,0,0.3)',
|
1356 |
-
width=2,
|
1357 |
-
dash='dash'
|
1358 |
-
),
|
1359 |
-
fill='toself',
|
1360 |
-
fillcolor='rgba(255,0,0,0.1)',
|
1361 |
-
name=f'Storm {storm_id} Uncertainty',
|
1362 |
-
showlegend=(storm_idx == 0 and day_idx == 0),
|
1363 |
-
legendgroup=f'storm_{storm_id}',
|
1364 |
-
hoverinfo='skip'
|
1365 |
-
)
|
1366 |
-
)
|
1367 |
-
|
1368 |
-
# 6. GENESIS MARKER (Show where storm formed)
|
1369 |
-
if len(current_track) >= 1:
|
1370 |
-
genesis_pos = track[0] # First position
|
1371 |
-
frame_data.append(
|
1372 |
-
go.Scattergeo(
|
1373 |
-
lat=[genesis_pos['lat']],
|
1374 |
-
lon=[genesis_pos['lon']],
|
1375 |
-
mode='markers',
|
1376 |
-
marker=dict(
|
1377 |
-
size=12,
|
1378 |
-
color='gold',
|
1379 |
-
symbol='star',
|
1380 |
-
line=dict(width=2, color='black')
|
1381 |
-
),
|
1382 |
-
name=f'Storm {storm_id} Genesis',
|
1383 |
-
showlegend=(storm_idx == 0 and day_idx == 0),
|
1384 |
-
legendgroup=f'storm_{storm_id}',
|
1385 |
-
hovertemplate=(
|
1386 |
-
f'<b>GENESIS - Storm {storm_id}</b><br>'
|
1387 |
-
f'Day {genesis_pos["day"]:.1f}<br>'
|
1388 |
-
f'Location: %{{lat:.1f}}°N, %{{lon:.1f}}°E<br>'
|
1389 |
-
f'Initial Intensity: {genesis_pos["intensity"]:.0f} kt<br>'
|
1390 |
-
'<extra></extra>'
|
1391 |
-
)
|
1392 |
-
)
|
1393 |
-
)
|
1394 |
-
|
1395 |
# Create frame
|
1396 |
frames.append(go.Frame(
|
1397 |
data=frame_data,
|
@@ -1419,82 +1266,9 @@ def create_genesis_animation(prediction_data, enable_animation=True):
|
|
1419 |
|
1420 |
fig.frames = frames
|
1421 |
|
1422 |
-
# Set initial frame
|
1423 |
-
|
1424 |
-
|
1425 |
-
fig.update_layout(frames[0].layout)
|
1426 |
-
|
1427 |
-
# PROFESSIONAL ANIMATION CONTROLS (like NHC website)
|
1428 |
-
fig.update_layout(
|
1429 |
-
updatemenus=[{
|
1430 |
-
"buttons": [
|
1431 |
-
{
|
1432 |
-
"args": [None, {
|
1433 |
-
"frame": {"duration": 800, "redraw": True},
|
1434 |
-
"fromcurrent": True,
|
1435 |
-
"transition": {"duration": 300, "easing": "cubic-in-out"}
|
1436 |
-
}],
|
1437 |
-
"label": "▶️ Play Animation",
|
1438 |
-
"method": "animate"
|
1439 |
-
},
|
1440 |
-
{
|
1441 |
-
"args": [[None], {
|
1442 |
-
"frame": {"duration": 0, "redraw": True},
|
1443 |
-
"mode": "immediate",
|
1444 |
-
"transition": {"duration": 0}
|
1445 |
-
}],
|
1446 |
-
"label": "⏸️ Pause",
|
1447 |
-
"method": "animate"
|
1448 |
-
},
|
1449 |
-
{
|
1450 |
-
"args": [[frames[0].name], {
|
1451 |
-
"frame": {"duration": 0, "redraw": True},
|
1452 |
-
"mode": "immediate",
|
1453 |
-
"transition": {"duration": 0}
|
1454 |
-
}],
|
1455 |
-
"label": "⏮️ Reset",
|
1456 |
-
"method": "animate"
|
1457 |
-
}
|
1458 |
-
],
|
1459 |
-
"direction": "left",
|
1460 |
-
"pad": {"r": 10, "t": 120},
|
1461 |
-
"showactive": False,
|
1462 |
-
"type": "buttons",
|
1463 |
-
"x": 0.1,
|
1464 |
-
"xanchor": "right",
|
1465 |
-
"y": 0,
|
1466 |
-
"yanchor": "top"
|
1467 |
-
}],
|
1468 |
-
sliders=[{
|
1469 |
-
"active": 0,
|
1470 |
-
"yanchor": "top",
|
1471 |
-
"xanchor": "left",
|
1472 |
-
"currentvalue": {
|
1473 |
-
"font": {"size": 16, "color": "darkblue"},
|
1474 |
-
"prefix": f"{month:02d}/{year} Day: ",
|
1475 |
-
"visible": True,
|
1476 |
-
"xanchor": "right"
|
1477 |
-
},
|
1478 |
-
"transition": {"duration": 300, "easing": "cubic-in-out"},
|
1479 |
-
"pad": {"b": 10, "t": 50},
|
1480 |
-
"len": 0.9,
|
1481 |
-
"x": 0.1,
|
1482 |
-
"y": 0,
|
1483 |
-
"steps": [
|
1484 |
-
{
|
1485 |
-
"args": [[str(day_data['day'])], {
|
1486 |
-
"frame": {"duration": 300, "redraw": True},
|
1487 |
-
"mode": "immediate",
|
1488 |
-
"transition": {"duration": 300}
|
1489 |
-
}],
|
1490 |
-
"label": f"Day {day_data['day']}",
|
1491 |
-
"method": "animate"
|
1492 |
-
}
|
1493 |
-
for day_data in daily_maps
|
1494 |
-
]
|
1495 |
-
}]
|
1496 |
-
)
|
1497 |
-
|
1498 |
else:
|
1499 |
# STATIC VERSION (Final state overview)
|
1500 |
final_day = daily_maps[-1]
|
@@ -1502,7 +1276,6 @@ def create_genesis_animation(prediction_data, enable_animation=True):
|
|
1502 |
lat_range = final_day['lat_range']
|
1503 |
lon_range = final_day['lon_range']
|
1504 |
|
1505 |
-
# Add GPI background
|
1506 |
fig.add_trace(
|
1507 |
go.Scattergeo(
|
1508 |
lat=np.repeat(lat_range, len(lon_range)),
|
@@ -1514,53 +1287,16 @@ def create_genesis_animation(prediction_data, enable_animation=True):
|
|
1514 |
colorscale='Viridis',
|
1515 |
opacity=0.6,
|
1516 |
showscale=True,
|
1517 |
-
colorbar=dict(
|
|
|
|
|
1518 |
),
|
1519 |
name='Genesis Potential'
|
1520 |
)
|
1521 |
)
|
1522 |
|
1523 |
-
# Add complete storm tracks
|
1524 |
-
|
1525 |
-
track = storm['track']
|
1526 |
-
if track:
|
1527 |
-
lats = [pt['lat'] for pt in track]
|
1528 |
-
lons = [pt['lon'] for pt in track]
|
1529 |
-
intensities = [pt['intensity'] for pt in track]
|
1530 |
-
|
1531 |
-
# Complete track
|
1532 |
-
fig.add_trace(
|
1533 |
-
go.Scattergeo(
|
1534 |
-
lat=lats,
|
1535 |
-
lon=lons,
|
1536 |
-
mode='lines+markers',
|
1537 |
-
line=dict(color='red', width=3),
|
1538 |
-
marker=dict(
|
1539 |
-
size=[max(6, int/8) for int in intensities],
|
1540 |
-
color=intensities,
|
1541 |
-
colorscale='Reds',
|
1542 |
-
showscale=False
|
1543 |
-
),
|
1544 |
-
name=f'Storm {storm["storm_id"]} Complete Track'
|
1545 |
-
)
|
1546 |
-
)
|
1547 |
-
|
1548 |
-
# Genesis marker
|
1549 |
-
fig.add_trace(
|
1550 |
-
go.Scattergeo(
|
1551 |
-
lat=[lats[0]],
|
1552 |
-
lon=[lons[0]],
|
1553 |
-
mode='markers',
|
1554 |
-
marker=dict(
|
1555 |
-
size=15,
|
1556 |
-
color='gold',
|
1557 |
-
symbol='star',
|
1558 |
-
line=dict(width=2, color='black')
|
1559 |
-
),
|
1560 |
-
name=f'Genesis {storm["storm_id"]}',
|
1561 |
-
showlegend=False
|
1562 |
-
)
|
1563 |
-
)
|
1564 |
|
1565 |
# FINAL LAYOUT (Professional meteorological style)
|
1566 |
fig.update_layout(
|
@@ -1600,7 +1336,7 @@ def create_genesis_animation(prediction_data, enable_animation=True):
|
|
1600 |
)
|
1601 |
|
1602 |
return fig
|
1603 |
-
|
1604 |
except Exception as e:
|
1605 |
logging.error(f"Error creating professional genesis animation: {e}")
|
1606 |
import traceback
|
|
|
1205 |
opacity=0.6,
|
1206 |
showscale=(day_idx == 0),
|
1207 |
colorbar=dict(
|
1208 |
+
title="Genesis<br>Potential<br>Index",
|
1209 |
+
title_side="right" # ← fixed here
|
|
|
|
|
1210 |
) if day_idx == 0 else None
|
1211 |
),
|
1212 |
name='Genesis Potential',
|
|
|
1236 |
intensities = [pt['intensity'] for pt in current_track]
|
1237 |
categories = [pt['category'] for pt in current_track]
|
1238 |
|
1239 |
+
# (…rest of historical track, current position, uncertainty cone, genesis marker…)
|
1240 |
+
# identical to before, omitted for brevity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1242 |
# Create frame
|
1243 |
frames.append(go.Frame(
|
1244 |
data=frame_data,
|
|
|
1266 |
|
1267 |
fig.frames = frames
|
1268 |
|
1269 |
+
# Set up initial frame, add professional play/pause controls, sliders, etc. (unchanged)
|
1270 |
+
(…)
|
1271 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1272 |
else:
|
1273 |
# STATIC VERSION (Final state overview)
|
1274 |
final_day = daily_maps[-1]
|
|
|
1276 |
lat_range = final_day['lat_range']
|
1277 |
lon_range = final_day['lon_range']
|
1278 |
|
|
|
1279 |
fig.add_trace(
|
1280 |
go.Scattergeo(
|
1281 |
lat=np.repeat(lat_range, len(lon_range)),
|
|
|
1287 |
colorscale='Viridis',
|
1288 |
opacity=0.6,
|
1289 |
showscale=True,
|
1290 |
+
colorbar=dict(
|
1291 |
+
title="Genesis Potential Index"
|
1292 |
+
)
|
1293 |
),
|
1294 |
name='Genesis Potential'
|
1295 |
)
|
1296 |
)
|
1297 |
|
1298 |
+
# Add complete storm tracks (unchanged)
|
1299 |
+
(…)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1300 |
|
1301 |
# FINAL LAYOUT (Professional meteorological style)
|
1302 |
fig.update_layout(
|
|
|
1336 |
)
|
1337 |
|
1338 |
return fig
|
1339 |
+
|
1340 |
except Exception as e:
|
1341 |
logging.error(f"Error creating professional genesis animation: {e}")
|
1342 |
import traceback
|