euler314 commited on
Commit
ffc184a
·
verified ·
1 Parent(s): a74a30d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -302,7 +302,7 @@ 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 world map (using Matplotlib and Cartopy)
306
  def categorize_typhoon_by_standard(wind_speed, standard):
307
  if standard == 'taiwan':
308
  wind_speed_ms = wind_speed * 0.514444
@@ -341,9 +341,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 Cartopy
345
- fig = plt.figure(figsize=(10, 7))
346
- ax = plt.axes(projection=ccrs.PlateCarree())
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
@@ -359,18 +359,23 @@ def generate_track_video(year, typhoon, standard):
359
  standard_dict = atlantic_standard if standard == 'atlantic' else taiwan_standard
360
  for cat, details in standard_dict.items():
361
  ax.plot([], [], 'o', color=details['color'], label=cat)
362
- ax.legend(loc='upper left', bbox_to_anchor=(1, 1))
363
 
364
  # Initialize the line and point
365
  line, = ax.plot([], [], 'b-', linewidth=2, transform=ccrs.PlateCarree())
366
  point, = ax.plot([], [], 'o', markersize=8, transform=ccrs.PlateCarree())
367
  date_text = ax.text(0.02, 0.02, '', transform=ax.transAxes, fontsize=12, bbox=dict(facecolor='white', alpha=0.8))
368
 
 
 
 
 
369
  def init():
370
  line.set_data([], [])
371
  point.set_data([], [])
372
  date_text.set_text('')
373
- return line, point, date_text
 
374
 
375
  def update(frame):
376
  line.set_data(storm.lon[:frame+1], storm.lat[:frame+1])
@@ -378,7 +383,12 @@ def generate_track_video(year, typhoon, standard):
378
  point.set_data([storm.lon[frame]], [storm.lat[frame]])
379
  point.set_color(color)
380
  date_text.set_text(storm.time[frame].strftime('%Y-%m-%d %H:%M'))
381
- return line, point, date_text
 
 
 
 
 
382
 
383
  # Create animation
384
  ani = animation.FuncAnimation(fig, update, init_func=init, frames=len(storm.time),
@@ -439,7 +449,7 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
439
  ### Features:
440
  - **Track Visualization**: View typhoon tracks by time period and ENSO phase
441
  - **Statistical Analysis**: Examine relationships between ONI values and typhoon characteristics
442
- - **Path Animation**: Watch an animated typhoon path with video controls and world map background
443
  - **Regression Analysis**: Perform statistical regression on typhoon data
444
 
445
  Select a tab above to begin your analysis.
@@ -607,7 +617,7 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
607
  2. Choose a classification standard (Atlantic or Taiwan)
608
  3. Click "Generate Animation"
609
  4. Use the video player's built-in controls to play, pause, or scrub through the animation
610
- 5. The animation shows the typhoon track growing over a world map, with the date displayed and intensity markers
611
  """)
612
 
613
  def update_typhoon_options(year):
 
302
 
303
  return tracks_fig, wind_scatter, pressure_scatter, regression_fig, slopes_text
304
 
305
+ # Video animation function with world map and details sidebar
306
  def categorize_typhoon_by_standard(wind_speed, standard):
307
  if standard == 'taiwan':
308
  wind_speed_ms = wind_speed * 0.514444
 
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 space for sidebar
345
+ fig = plt.figure(figsize=(14, 7)) # Wider figure to accommodate sidebar
346
+ ax = plt.axes([0.05, 0.05, 0.65, 0.9], projection=ccrs.PlateCarree()) # Map on left 65% of figure
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
 
359
  standard_dict = atlantic_standard if standard == 'atlantic' else taiwan_standard
360
  for cat, details in standard_dict.items():
361
  ax.plot([], [], 'o', color=details['color'], label=cat)
362
+ ax.legend(loc='upper left', bbox_to_anchor=(1.7, 1))
363
 
364
  # Initialize the line and point
365
  line, = ax.plot([], [], 'b-', linewidth=2, transform=ccrs.PlateCarree())
366
  point, = ax.plot([], [], 'o', markersize=8, transform=ccrs.PlateCarree())
367
  date_text = ax.text(0.02, 0.02, '', transform=ax.transAxes, fontsize=12, bbox=dict(facecolor='white', alpha=0.8))
368
 
369
+ # Add details text box on the right side
370
+ details_text = fig.text(0.75, 0.5, '', fontsize=12, verticalalignment='center', horizontalalignment='left',
371
+ bbox=dict(facecolor='white', alpha=0.8, boxstyle='round,pad=0.5'))
372
+
373
  def init():
374
  line.set_data([], [])
375
  point.set_data([], [])
376
  date_text.set_text('')
377
+ details_text.set_text('')
378
+ return line, point, date_text, details_text
379
 
380
  def update(frame):
381
  line.set_data(storm.lon[:frame+1], storm.lat[:frame+1])
 
383
  point.set_data([storm.lon[frame]], [storm.lat[frame]])
384
  point.set_color(color)
385
  date_text.set_text(storm.time[frame].strftime('%Y-%m-%d %H:%M'))
386
+ details = f"Typhoon: {storm.name}\n" \
387
+ f"Date: {storm.time[frame].strftime('%Y-%m-%d %H:%M')}\n" \
388
+ f"Wind Speed: {storm.vmax[frame]:.1f} kt\n" \
389
+ f"Category: {category}"
390
+ details_text.set_text(details)
391
+ return line, point, date_text, details_text
392
 
393
  # Create animation
394
  ani = animation.FuncAnimation(fig, update, init_func=init, frames=len(storm.time),
 
449
  ### Features:
450
  - **Track Visualization**: View typhoon tracks by time period and ENSO phase
451
  - **Statistical Analysis**: Examine relationships between ONI values and typhoon characteristics
452
+ - **Path Animation**: Watch an animated typhoon path with video controls, world map, and details sidebar
453
  - **Regression Analysis**: Perform statistical regression on typhoon data
454
 
455
  Select a tab above to begin your analysis.
 
617
  2. Choose a classification standard (Atlantic or Taiwan)
618
  3. Click "Generate Animation"
619
  4. Use the video player's built-in controls to play, pause, or scrub through the animation
620
+ 5. The animation shows the typhoon track growing over a world map, with date on the bottom left and details on the right
621
  """)
622
 
623
  def update_typhoon_options(year):