Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,8 @@ import numpy as np
|
|
4 |
import matplotlib.pyplot as plt
|
5 |
import matplotlib.animation as animation
|
6 |
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
|
|
|
|
|
7 |
import plotly.graph_objects as go
|
8 |
import plotly.express as px
|
9 |
import tropycal.tracks as tracks
|
@@ -300,7 +302,7 @@ def generate_main_analysis(start_year, start_month, end_year, end_month, enso_ph
|
|
300 |
|
301 |
return tracks_fig, wind_scatter, pressure_scatter, regression_fig, slopes_text
|
302 |
|
303 |
-
# Video animation function (using Matplotlib)
|
304 |
def categorize_typhoon_by_standard(wind_speed, standard):
|
305 |
if standard == 'taiwan':
|
306 |
wind_speed_ms = wind_speed * 0.514444
|
@@ -339,17 +341,19 @@ def generate_track_video(year, typhoon, standard):
|
|
339 |
lat_padding = max((max_lat - min_lat) * 0.3, 5)
|
340 |
lon_padding = max((max_lon - min_lon) * 0.3, 5)
|
341 |
|
342 |
-
# Set up the figure
|
343 |
-
fig
|
344 |
-
ax.
|
345 |
-
ax.
|
346 |
-
|
347 |
-
|
348 |
-
ax.
|
349 |
-
ax.
|
|
|
|
|
|
|
350 |
|
351 |
-
|
352 |
-
ax.plot([], [], 'b-', label='Track') # Placeholder for legend
|
353 |
|
354 |
# Legend for categories
|
355 |
standard_dict = atlantic_standard if standard == 'atlantic' else taiwan_standard
|
@@ -358,9 +362,9 @@ def generate_track_video(year, typhoon, standard):
|
|
358 |
ax.legend(loc='upper left', bbox_to_anchor=(1, 1))
|
359 |
|
360 |
# Initialize the line and point
|
361 |
-
line, = ax.plot([], [], 'b-', linewidth=2)
|
362 |
-
point, = ax.plot([], [], 'o', markersize=8)
|
363 |
-
date_text = ax.text(0.02, 0.02, '', transform=ax.transAxes, fontsize=12)
|
364 |
|
365 |
def init():
|
366 |
line.set_data([], [])
|
@@ -435,7 +439,7 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
|
435 |
### Features:
|
436 |
- **Track Visualization**: View typhoon tracks by time period and ENSO phase
|
437 |
- **Statistical Analysis**: Examine relationships between ONI values and typhoon characteristics
|
438 |
-
- **Path Animation**: Watch an animated typhoon path with video controls
|
439 |
- **Regression Analysis**: Perform statistical regression on typhoon data
|
440 |
|
441 |
Select a tab above to begin your analysis.
|
@@ -603,7 +607,7 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
|
603 |
2. Choose a classification standard (Atlantic or Taiwan)
|
604 |
3. Click "Generate Animation"
|
605 |
4. Use the video player's built-in controls to play, pause, or scrub through the animation
|
606 |
-
5. The
|
607 |
""")
|
608 |
|
609 |
def update_typhoon_options(year):
|
|
|
4 |
import matplotlib.pyplot as plt
|
5 |
import matplotlib.animation as animation
|
6 |
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
|
7 |
+
import cartopy.crs as ccrs
|
8 |
+
import cartopy.feature as cfeature
|
9 |
import plotly.graph_objects as go
|
10 |
import plotly.express as px
|
11 |
import tropycal.tracks as tracks
|
|
|
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 |
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
|
350 |
+
ax.add_feature(cfeature.LAND, facecolor='lightgray')
|
351 |
+
ax.add_feature(cfeature.OCEAN, facecolor='lightblue')
|
352 |
+
ax.add_feature(cfeature.COASTLINE, edgecolor='black')
|
353 |
+
ax.add_feature(cfeature.BORDERS, linestyle=':', edgecolor='gray')
|
354 |
+
ax.gridlines(draw_labels=True, linestyle='--', color='gray', alpha=0.5)
|
355 |
|
356 |
+
ax.set_title(f"{year} {storm.name} Typhoon Path")
|
|
|
357 |
|
358 |
# Legend for categories
|
359 |
standard_dict = atlantic_standard if standard == 'atlantic' else taiwan_standard
|
|
|
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([], [])
|
|
|
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 |
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):
|