Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -45,22 +45,40 @@ color_map = {
|
|
45 |
'Tropical Depression': 'rgb(173, 216, 230)'
|
46 |
}
|
47 |
|
48 |
-
# Classification standards
|
49 |
atlantic_standard = {
|
50 |
-
'C5 Super Typhoon': {'wind_speed': 137, 'color': '
|
51 |
-
'C4 Very Strong Typhoon': {'wind_speed': 113, 'color': '
|
52 |
-
'C3 Strong Typhoon': {'wind_speed': 96, 'color': '
|
53 |
-
'C2 Typhoon': {'wind_speed': 83, 'color': '
|
54 |
-
'C1 Typhoon': {'wind_speed': 64, 'color': '
|
55 |
-
'Tropical Storm': {'wind_speed': 34, 'color': '
|
56 |
-
'Tropical Depression': {'wind_speed': 0, 'color': '
|
57 |
}
|
58 |
|
59 |
taiwan_standard = {
|
60 |
-
'Strong Typhoon': {'wind_speed': 51.0, 'color': '
|
61 |
-
'Medium Typhoon': {'wind_speed': 33.7, 'color': '
|
62 |
-
'Mild Typhoon': {'wind_speed': 17.2, 'color': '
|
63 |
-
'Tropical Depression': {'wind_speed': 0, 'color': '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
}
|
65 |
|
66 |
# Data loading and preprocessing functions
|
@@ -302,31 +320,31 @@ def generate_main_analysis(start_year, start_month, end_year, end_month, enso_ph
|
|
302 |
|
303 |
return tracks_fig, wind_scatter, pressure_scatter, regression_fig, slopes_text
|
304 |
|
305 |
-
# Video animation function with
|
306 |
def categorize_typhoon_by_standard(wind_speed, standard):
|
307 |
if standard == 'taiwan':
|
308 |
wind_speed_ms = wind_speed * 0.514444
|
309 |
if wind_speed_ms >= 51.0:
|
310 |
-
return 'Strong Typhoon',
|
311 |
elif wind_speed_ms >= 33.7:
|
312 |
-
return 'Medium Typhoon',
|
313 |
elif wind_speed_ms >= 17.2:
|
314 |
-
return 'Mild Typhoon',
|
315 |
-
return 'Tropical Depression',
|
316 |
else:
|
317 |
if wind_speed >= 137:
|
318 |
-
return 'C5 Super Typhoon',
|
319 |
elif wind_speed >= 113:
|
320 |
-
return 'C4 Very Strong Typhoon',
|
321 |
elif wind_speed >= 96:
|
322 |
-
return 'C3 Strong Typhoon',
|
323 |
elif wind_speed >= 83:
|
324 |
-
return 'C2 Typhoon',
|
325 |
elif wind_speed >= 64:
|
326 |
-
return 'C1 Typhoon',
|
327 |
elif wind_speed >= 34:
|
328 |
-
return 'Tropical Storm',
|
329 |
-
return 'Tropical Depression',
|
330 |
|
331 |
def generate_track_video(year, typhoon, standard):
|
332 |
if not typhoon:
|
@@ -341,9 +359,9 @@ def generate_track_video(year, typhoon, standard):
|
|
341 |
lat_padding = max((max_lat - min_lat) * 0.3, 5)
|
342 |
lon_padding = max((max_lon - min_lon) * 0.3, 5)
|
343 |
|
344 |
-
# Set up the figure with Gradio
|
345 |
-
fig = plt.figure(figsize=(
|
346 |
-
ax = plt.axes([0.05, 0.
|
347 |
ax.set_extent([min_lon - lon_padding, max_lon + lon_padding, min_lat - lat_padding, max_lat + lat_padding], crs=ccrs.PlateCarree())
|
348 |
|
349 |
# Add world map features
|
@@ -358,17 +376,17 @@ def generate_track_video(year, typhoon, standard):
|
|
358 |
# Initialize the line and point
|
359 |
line, = ax.plot([], [], 'b-', linewidth=2, transform=ccrs.PlateCarree())
|
360 |
point, = ax.plot([], [], 'o', markersize=8, transform=ccrs.PlateCarree())
|
361 |
-
date_text = ax.text(0.02, 0.02, '', transform=ax.transAxes, fontsize=
|
362 |
|
363 |
# Add sidebar with typhoon details on the right
|
364 |
-
details_title = fig.text(0.
|
365 |
-
details_text = fig.text(0.
|
366 |
bbox=dict(facecolor='white', alpha=0.8, boxstyle='round,pad=0.5'))
|
367 |
|
368 |
# Add color legend below the details
|
369 |
standard_dict = atlantic_standard if standard == 'atlantic' else taiwan_standard
|
370 |
color_legend_text = "\n".join([f"{cat}: {details['color']}" for cat, details in standard_dict.items()])
|
371 |
-
color_legend = fig.text(0.
|
372 |
bbox=dict(facecolor='white', alpha=0.8, boxstyle='round,pad=0.5'))
|
373 |
|
374 |
def init():
|
@@ -621,7 +639,7 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
|
621 |
5. The animation shows the typhoon track growing over a world map, with:
|
622 |
- Date on the bottom left
|
623 |
- Sidebar on the right showing typhoon details (name, date, wind speed, category)
|
624 |
-
- Color legend below the sidebar
|
625 |
""")
|
626 |
|
627 |
def update_typhoon_options(year):
|
|
|
45 |
'Tropical Depression': 'rgb(173, 216, 230)'
|
46 |
}
|
47 |
|
48 |
+
# Classification standards with color names for Matplotlib
|
49 |
atlantic_standard = {
|
50 |
+
'C5 Super Typhoon': {'wind_speed': 137, 'color': 'Red'},
|
51 |
+
'C4 Very Strong Typhoon': {'wind_speed': 113, 'color': 'Orange-Red'},
|
52 |
+
'C3 Strong Typhoon': {'wind_speed': 96, 'color': 'Orange'},
|
53 |
+
'C2 Typhoon': {'wind_speed': 83, 'color': 'Light Orange'},
|
54 |
+
'C1 Typhoon': {'wind_speed': 64, 'color': 'Yellow'},
|
55 |
+
'Tropical Storm': {'wind_speed': 34, 'color': 'Cyan'},
|
56 |
+
'Tropical Depression': {'wind_speed': 0, 'color': 'Light Blue'}
|
57 |
}
|
58 |
|
59 |
taiwan_standard = {
|
60 |
+
'Strong Typhoon': {'wind_speed': 51.0, 'color': 'Red'},
|
61 |
+
'Medium Typhoon': {'wind_speed': 33.7, 'color': 'Orange'},
|
62 |
+
'Mild Typhoon': {'wind_speed': 17.2, 'color': 'Yellow'},
|
63 |
+
'Tropical Depression': {'wind_speed': 0, 'color': 'Light Blue'}
|
64 |
+
}
|
65 |
+
|
66 |
+
# HEX codes for Matplotlib plotting (unchanged)
|
67 |
+
atlantic_hex = {
|
68 |
+
'C5 Super Typhoon': '#FF0000',
|
69 |
+
'C4 Very Strong Typhoon': '#FF3F00',
|
70 |
+
'C3 Strong Typhoon': '#FF7F00',
|
71 |
+
'C2 Typhoon': '#FFBF00',
|
72 |
+
'C1 Typhoon': '#FFFF00',
|
73 |
+
'Tropical Storm': '#00FFFF',
|
74 |
+
'Tropical Depression': '#ADD8E6'
|
75 |
+
}
|
76 |
+
|
77 |
+
taiwan_hex = {
|
78 |
+
'Strong Typhoon': '#FF0000',
|
79 |
+
'Medium Typhoon': '#FF7F00',
|
80 |
+
'Mild Typhoon': '#FFFF00',
|
81 |
+
'Tropical Depression': '#ADD8E6'
|
82 |
}
|
83 |
|
84 |
# Data loading and preprocessing functions
|
|
|
320 |
|
321 |
return tracks_fig, wind_scatter, pressure_scatter, regression_fig, slopes_text
|
322 |
|
323 |
+
# Video animation function with adjusted size, color names, and sidebar
|
324 |
def categorize_typhoon_by_standard(wind_speed, standard):
|
325 |
if standard == 'taiwan':
|
326 |
wind_speed_ms = wind_speed * 0.514444
|
327 |
if wind_speed_ms >= 51.0:
|
328 |
+
return 'Strong Typhoon', taiwan_hex['Strong Typhoon']
|
329 |
elif wind_speed_ms >= 33.7:
|
330 |
+
return 'Medium Typhoon', taiwan_hex['Medium Typhoon']
|
331 |
elif wind_speed_ms >= 17.2:
|
332 |
+
return 'Mild Typhoon', taiwan_hex['Mild Typhoon']
|
333 |
+
return 'Tropical Depression', taiwan_hex['Tropical Depression']
|
334 |
else:
|
335 |
if wind_speed >= 137:
|
336 |
+
return 'C5 Super Typhoon', atlantic_hex['C5 Super Typhoon']
|
337 |
elif wind_speed >= 113:
|
338 |
+
return 'C4 Very Strong Typhoon', atlantic_hex['C4 Very Strong Typhoon']
|
339 |
elif wind_speed >= 96:
|
340 |
+
return 'C3 Strong Typhoon', atlantic_hex['C3 Strong Typhoon']
|
341 |
elif wind_speed >= 83:
|
342 |
+
return 'C2 Typhoon', atlantic_hex['C2 Typhoon']
|
343 |
elif wind_speed >= 64:
|
344 |
+
return 'C1 Typhoon', atlantic_hex['C1 Typhoon']
|
345 |
elif wind_speed >= 34:
|
346 |
+
return 'Tropical Storm', atlantic_hex['Tropical Storm']
|
347 |
+
return 'Tropical Depression', atlantic_hex['Tropical Depression']
|
348 |
|
349 |
def generate_track_video(year, typhoon, standard):
|
350 |
if not typhoon:
|
|
|
359 |
lat_padding = max((max_lat - min_lat) * 0.3, 5)
|
360 |
lon_padding = max((max_lon - min_lon) * 0.3, 5)
|
361 |
|
362 |
+
# Set up the figure with adjusted size to fit Gradio (900x700 pixels at 100 DPI)
|
363 |
+
fig = plt.figure(figsize=(9, 7), dpi=100) # 9x7 inches = 900x700 pixels
|
364 |
+
ax = plt.axes([0.05, 0.15, 0.60, 0.80], projection=ccrs.PlateCarree()) # Map on left 60%, adjusted for legend space
|
365 |
ax.set_extent([min_lon - lon_padding, max_lon + lon_padding, min_lat - lat_padding, max_lat + lat_padding], crs=ccrs.PlateCarree())
|
366 |
|
367 |
# Add world map features
|
|
|
376 |
# Initialize the line and point
|
377 |
line, = ax.plot([], [], 'b-', linewidth=2, transform=ccrs.PlateCarree())
|
378 |
point, = ax.plot([], [], 'o', markersize=8, transform=ccrs.PlateCarree())
|
379 |
+
date_text = ax.text(0.02, 0.02, '', transform=ax.transAxes, fontsize=10, bbox=dict(facecolor='white', alpha=0.8))
|
380 |
|
381 |
# Add sidebar with typhoon details on the right
|
382 |
+
details_title = fig.text(0.70, 0.90, "Typhoon Details", fontsize=12, fontweight='bold', verticalalignment='top', horizontalalignment='left')
|
383 |
+
details_text = fig.text(0.70, 0.85, '', fontsize=10, verticalalignment='top', horizontalalignment='left',
|
384 |
bbox=dict(facecolor='white', alpha=0.8, boxstyle='round,pad=0.5'))
|
385 |
|
386 |
# Add color legend below the details
|
387 |
standard_dict = atlantic_standard if standard == 'atlantic' else taiwan_standard
|
388 |
color_legend_text = "\n".join([f"{cat}: {details['color']}" for cat, details in standard_dict.items()])
|
389 |
+
color_legend = fig.text(0.70, 0.60, f"Color Legend\n{color_legend_text}", fontsize=10, verticalalignment='top', horizontalalignment='left',
|
390 |
bbox=dict(facecolor='white', alpha=0.8, boxstyle='round,pad=0.5'))
|
391 |
|
392 |
def init():
|
|
|
639 |
5. The animation shows the typhoon track growing over a world map, with:
|
640 |
- Date on the bottom left
|
641 |
- Sidebar on the right showing typhoon details (name, date, wind speed, category)
|
642 |
+
- Color legend below the sidebar using color names (e.g., "Red: C5 Super Typhoon")
|
643 |
""")
|
644 |
|
645 |
def update_typhoon_options(year):
|