Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -293,7 +293,7 @@ def generate_main_analysis(start_year, start_month, end_year, end_month, enso_ph
|
|
293 |
|
294 |
return tracks_fig, wind_scatter, pressure_scatter, regression_fig, slopes_text
|
295 |
|
296 |
-
# Path animation function
|
297 |
def categorize_typhoon_by_standard(wind_speed, standard):
|
298 |
if standard == 'taiwan':
|
299 |
wind_speed_ms = wind_speed * 0.514444
|
@@ -326,53 +326,35 @@ def generate_improved_animation(year, typhoon, standard):
|
|
326 |
typhoon_id = typhoon.split('(')[-1].strip(')')
|
327 |
storm = ibtracs.get_storm(typhoon_id)
|
328 |
|
329 |
-
# Create frames
|
330 |
frames = []
|
331 |
for i in range(len(storm.time)):
|
332 |
category, color = categorize_typhoon_by_standard(storm.vmax[i], standard)
|
333 |
frame_data = [
|
334 |
go.Scattergeo(
|
335 |
-
lon=storm.lon[:i+1],
|
336 |
-
lat=storm.lat[:i+1],
|
337 |
-
mode='lines',
|
338 |
line=dict(width=2, color='blue'),
|
339 |
-
|
340 |
-
|
341 |
-
),
|
342 |
-
go.Scattergeo(
|
343 |
-
lon=[storm.lon[i]],
|
344 |
-
lat=[storm.lat[i]],
|
345 |
-
mode='markers',
|
346 |
-
marker=dict(size=12, color=color),
|
347 |
-
name=f"Current Position",
|
348 |
text=[f"Time: {storm.time[i].strftime('%Y-%m-%d %H:%M')}<br>Wind: {storm.vmax[i]:.1f} kt<br>Category: {category}"],
|
349 |
hoverinfo="text"
|
350 |
)
|
351 |
]
|
352 |
-
if i > 0:
|
353 |
-
frame_data.append(
|
354 |
-
go.Scattergeo(
|
355 |
-
lon=storm.lon[:i],
|
356 |
-
lat=storm.lat[:i],
|
357 |
-
mode='markers',
|
358 |
-
marker=dict(size=5, color='rgba(100,100,100,0.5)'),
|
359 |
-
name="Previous Positions",
|
360 |
-
hoverinfo="none",
|
361 |
-
showlegend=False
|
362 |
-
)
|
363 |
-
)
|
364 |
frames.append(go.Frame(data=frame_data, name=str(i)))
|
365 |
|
366 |
-
# Initial figure
|
|
|
367 |
fig = go.Figure(
|
368 |
data=[
|
369 |
go.Scattergeo(
|
370 |
lon=[storm.lon[0]],
|
371 |
lat=[storm.lat[0]],
|
372 |
-
mode='markers',
|
373 |
-
marker=dict(size=12, color=
|
374 |
name="Start",
|
375 |
-
text=[f"Start: {storm.time[0].strftime('%Y-%m-%d %H:%M')}"],
|
376 |
hoverinfo="text"
|
377 |
)
|
378 |
],
|
@@ -397,7 +379,7 @@ def generate_improved_animation(year, typhoon, standard):
|
|
397 |
|
398 |
# Update layout with animation controls
|
399 |
fig.update_layout(
|
400 |
-
title=f"{year} {storm.name} Typhoon Path",
|
401 |
geo=dict(
|
402 |
projection_type='natural earth',
|
403 |
showland=True,
|
@@ -415,7 +397,7 @@ def generate_improved_animation(year, typhoon, standard):
|
|
415 |
{
|
416 |
"args": [None, {"frame": {"duration": 200, "redraw": True},
|
417 |
"fromcurrent": True,
|
418 |
-
"transition": {"duration": 0},
|
419 |
"mode": "immediate"}],
|
420 |
"label": "Play",
|
421 |
"method": "animate"
|
@@ -447,7 +429,7 @@ def generate_improved_animation(year, typhoon, standard):
|
|
447 |
"visible": True,
|
448 |
"xanchor": "right"
|
449 |
},
|
450 |
-
"transition": {"duration": 0},
|
451 |
"pad": {"b": 10, "t": 50},
|
452 |
"len": 0.9,
|
453 |
"x": 0.1,
|
@@ -457,7 +439,7 @@ def generate_improved_animation(year, typhoon, standard):
|
|
457 |
"args": [[str(i)], {"frame": {"duration": 200, "redraw": True},
|
458 |
"mode": "immediate",
|
459 |
"transition": {"duration": 0}}],
|
460 |
-
"label": storm.time[i].strftime('%m/%d %H:%M')
|
461 |
"method": "animate"
|
462 |
} for i in range(len(storm.time))
|
463 |
]
|
@@ -471,8 +453,6 @@ def generate_improved_animation(year, typhoon, standard):
|
|
471 |
x=0.01,
|
472 |
bgcolor="rgba(255, 255, 255, 0.8)"
|
473 |
),
|
474 |
-
# Ensure animation starts automatically
|
475 |
-
autosize=True
|
476 |
)
|
477 |
|
478 |
return fig
|
@@ -691,8 +671,9 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
|
691 |
1. Select a year and typhoon from the dropdowns
|
692 |
2. Choose a classification standard (Atlantic or Taiwan)
|
693 |
3. Click "Generate Animation"
|
694 |
-
4. Use the "Play" button to
|
695 |
-
5.
|
|
|
696 |
""")
|
697 |
|
698 |
def update_typhoon_options(year):
|
|
|
293 |
|
294 |
return tracks_fig, wind_scatter, pressure_scatter, regression_fig, slopes_text
|
295 |
|
296 |
+
# Path animation function with moving track
|
297 |
def categorize_typhoon_by_standard(wind_speed, standard):
|
298 |
if standard == 'taiwan':
|
299 |
wind_speed_ms = wind_speed * 0.514444
|
|
|
326 |
typhoon_id = typhoon.split('(')[-1].strip(')')
|
327 |
storm = ibtracs.get_storm(typhoon_id)
|
328 |
|
329 |
+
# Create animation frames with growing track
|
330 |
frames = []
|
331 |
for i in range(len(storm.time)):
|
332 |
category, color = categorize_typhoon_by_standard(storm.vmax[i], standard)
|
333 |
frame_data = [
|
334 |
go.Scattergeo(
|
335 |
+
lon=storm.lon[:i+1], # Only include points up to current time
|
336 |
+
lat=storm.lat[:i+1],
|
337 |
+
mode='lines+markers',
|
338 |
line=dict(width=2, color='blue'),
|
339 |
+
marker=dict(size=8, color=color),
|
340 |
+
name=f"{storm.name} at {storm.time[i].strftime('%Y-%m-%d %H:%M')}",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
text=[f"Time: {storm.time[i].strftime('%Y-%m-%d %H:%M')}<br>Wind: {storm.vmax[i]:.1f} kt<br>Category: {category}"],
|
342 |
hoverinfo="text"
|
343 |
)
|
344 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
frames.append(go.Frame(data=frame_data, name=str(i)))
|
346 |
|
347 |
+
# Initial figure with just the starting point
|
348 |
+
category, color = categorize_typhoon_by_standard(storm.vmax[0], standard)
|
349 |
fig = go.Figure(
|
350 |
data=[
|
351 |
go.Scattergeo(
|
352 |
lon=[storm.lon[0]],
|
353 |
lat=[storm.lat[0]],
|
354 |
+
mode='markers',
|
355 |
+
marker=dict(size=12, color=color),
|
356 |
name="Start",
|
357 |
+
text=[f"Start: {storm.time[0].strftime('%Y-%m-%d %H:%M')}<br>Wind: {storm.vmax[0]:.1f} kt<br>Category: {category}"],
|
358 |
hoverinfo="text"
|
359 |
)
|
360 |
],
|
|
|
379 |
|
380 |
# Update layout with animation controls
|
381 |
fig.update_layout(
|
382 |
+
title=f"{year} {storm.name} Typhoon Path Animation",
|
383 |
geo=dict(
|
384 |
projection_type='natural earth',
|
385 |
showland=True,
|
|
|
397 |
{
|
398 |
"args": [None, {"frame": {"duration": 200, "redraw": True},
|
399 |
"fromcurrent": True,
|
400 |
+
"transition": {"duration": 0, "easing": "linear"},
|
401 |
"mode": "immediate"}],
|
402 |
"label": "Play",
|
403 |
"method": "animate"
|
|
|
429 |
"visible": True,
|
430 |
"xanchor": "right"
|
431 |
},
|
432 |
+
"transition": {"duration": 0, "easing": "linear"},
|
433 |
"pad": {"b": 10, "t": 50},
|
434 |
"len": 0.9,
|
435 |
"x": 0.1,
|
|
|
439 |
"args": [[str(i)], {"frame": {"duration": 200, "redraw": True},
|
440 |
"mode": "immediate",
|
441 |
"transition": {"duration": 0}}],
|
442 |
+
"label": storm.time[i].strftime('%m/%d %H:%M'),
|
443 |
"method": "animate"
|
444 |
} for i in range(len(storm.time))
|
445 |
]
|
|
|
453 |
x=0.01,
|
454 |
bgcolor="rgba(255, 255, 255, 0.8)"
|
455 |
),
|
|
|
|
|
456 |
)
|
457 |
|
458 |
return fig
|
|
|
671 |
1. Select a year and typhoon from the dropdowns
|
672 |
2. Choose a classification standard (Atlantic or Taiwan)
|
673 |
3. Click "Generate Animation"
|
674 |
+
4. Use the "Play" button to watch the typhoon track grow over time
|
675 |
+
5. Use the slider to manually navigate through the typhoon's path
|
676 |
+
6. The blue line represents the growing track, with markers colored by intensity
|
677 |
""")
|
678 |
|
679 |
def update_typhoon_options(year):
|