Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -897,7 +897,6 @@ def update_route_clusters(start_year, start_month, end_year, end_month, enso_val
|
|
897 |
cluster_info_text = "\n".join(cluster_info_lines)
|
898 |
return fig_tsne, fig_routes, fig_stats, cluster_info_text
|
899 |
|
900 |
-
# Gradio Interface
|
901 |
# Gradio Interface
|
902 |
with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
903 |
gr.Markdown("# Typhoon Analysis Dashboard")
|
@@ -913,7 +912,7 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
|
913 |
- **Wind Analysis**: Examine wind speed vs ONI relationships
|
914 |
- **Pressure Analysis**: Analyze pressure vs ONI relationships
|
915 |
- **Longitude Analysis**: Study typhoon generation longitude vs ONI
|
916 |
-
- **Path Animation**: Watch animated
|
917 |
- **TSNE Cluster**: Perform t-SNE clustering on typhoon routes with mean routes and region analysis
|
918 |
|
919 |
Select a tab above to begin your analysis.
|
@@ -1067,9 +1066,23 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
|
1067 |
outputs=[regression_plot, slopes_text, lon_regression_results]
|
1068 |
)
|
1069 |
|
1070 |
-
with gr.Tab("
|
1071 |
with gr.Row():
|
1072 |
year_dropdown = gr.Dropdown(label="Year", choices=[str(y) for y in range(1950, 2025)], value="2000")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1073 |
typhoon_dropdown = gr.Dropdown(label="Tropical Cyclone")
|
1074 |
standard_dropdown = gr.Dropdown(label="Classification Standard", choices=['atlantic', 'taiwan'], value='atlantic')
|
1075 |
|
@@ -1077,7 +1090,7 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
|
1077 |
path_video = gr.Video(label="Tropical Cyclone Path Animation", elem_id="path_video")
|
1078 |
animation_info = gr.Markdown("""
|
1079 |
### Animation Instructions
|
1080 |
-
1. Select a year from the
|
1081 |
2. Choose a tropical cyclone from the populated list
|
1082 |
3. Select a classification standard (Atlantic or Taiwan)
|
1083 |
4. Click "Generate Animation"
|
@@ -1092,18 +1105,36 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
|
1092 |
Different agencies use different wind speed averaging periods: USA (1-min), JTWC (1-min), JMA (10-min), IMD (3-min).
|
1093 |
""")
|
1094 |
|
1095 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1096 |
try:
|
1097 |
season = ibtracs.get_season(int(year))
|
1098 |
storm_summary = season.summary()
|
1099 |
|
1100 |
-
#
|
|
|
|
|
|
|
1101 |
options = []
|
1102 |
for i in range(len(storm_summary)):
|
1103 |
try:
|
1104 |
name = storm_summary['name'][i] if not pd.isna(storm_summary['name'][i]) else "Unnamed"
|
1105 |
storm_id = storm_summary['id'][i]
|
1106 |
-
|
|
|
|
|
|
|
1107 |
except:
|
1108 |
continue
|
1109 |
|
@@ -1112,19 +1143,20 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
|
1112 |
print(f"Error updating typhoon options: {e}")
|
1113 |
return gr.update(choices=[], value=None)
|
1114 |
|
1115 |
-
year_dropdown.change(fn=update_typhoon_options, inputs=year_dropdown, outputs=typhoon_dropdown)
|
|
|
1116 |
|
1117 |
-
def simplified_track_video(year, typhoon, standard):
|
1118 |
if not typhoon:
|
1119 |
return None
|
1120 |
|
1121 |
# Extract storm ID and generate video
|
1122 |
typhoon_id = typhoon.split('(')[-1].strip(')')
|
1123 |
-
return generate_track_video(year, "All", typhoon, standard) # Pass "All" as basin
|
1124 |
|
1125 |
animate_btn.click(
|
1126 |
fn=simplified_track_video,
|
1127 |
-
inputs=[year_dropdown, typhoon_dropdown, standard_dropdown],
|
1128 |
outputs=path_video
|
1129 |
)
|
1130 |
|
|
|
897 |
cluster_info_text = "\n".join(cluster_info_lines)
|
898 |
return fig_tsne, fig_routes, fig_stats, cluster_info_text
|
899 |
|
|
|
900 |
# Gradio Interface
|
901 |
with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
902 |
gr.Markdown("# Typhoon Analysis Dashboard")
|
|
|
912 |
- **Wind Analysis**: Examine wind speed vs ONI relationships
|
913 |
- **Pressure Analysis**: Analyze pressure vs ONI relationships
|
914 |
- **Longitude Analysis**: Study typhoon generation longitude vs ONI
|
915 |
+
- **Path Animation**: Watch animated tropical cyclone paths with wind radius visualization
|
916 |
- **TSNE Cluster**: Perform t-SNE clustering on typhoon routes with mean routes and region analysis
|
917 |
|
918 |
Select a tab above to begin your analysis.
|
|
|
1066 |
outputs=[regression_plot, slopes_text, lon_regression_results]
|
1067 |
)
|
1068 |
|
1069 |
+
with gr.Tab("Tropical Cyclone Path Animation"):
|
1070 |
with gr.Row():
|
1071 |
year_dropdown = gr.Dropdown(label="Year", choices=[str(y) for y in range(1950, 2025)], value="2000")
|
1072 |
+
basin_dropdown = gr.Dropdown(
|
1073 |
+
label="Basin",
|
1074 |
+
choices=[
|
1075 |
+
"All Basins",
|
1076 |
+
"NA - North Atlantic",
|
1077 |
+
"EP - Eastern North Pacific",
|
1078 |
+
"WP - Western North Pacific",
|
1079 |
+
"NI - North Indian",
|
1080 |
+
"SI - South Indian",
|
1081 |
+
"SP - Southern Pacific",
|
1082 |
+
"SA - South Atlantic"
|
1083 |
+
],
|
1084 |
+
value="WP - Western North Pacific"
|
1085 |
+
)
|
1086 |
typhoon_dropdown = gr.Dropdown(label="Tropical Cyclone")
|
1087 |
standard_dropdown = gr.Dropdown(label="Classification Standard", choices=['atlantic', 'taiwan'], value='atlantic')
|
1088 |
|
|
|
1090 |
path_video = gr.Video(label="Tropical Cyclone Path Animation", elem_id="path_video")
|
1091 |
animation_info = gr.Markdown("""
|
1092 |
### Animation Instructions
|
1093 |
+
1. Select a year and basin from the dropdowns
|
1094 |
2. Choose a tropical cyclone from the populated list
|
1095 |
3. Select a classification standard (Atlantic or Taiwan)
|
1096 |
4. Click "Generate Animation"
|
|
|
1105 |
Different agencies use different wind speed averaging periods: USA (1-min), JTWC (1-min), JMA (10-min), IMD (3-min).
|
1106 |
""")
|
1107 |
|
1108 |
+
# Define the mapping from basin labels to ID prefixes
|
1109 |
+
basin_to_prefix = {
|
1110 |
+
"All Basins": None,
|
1111 |
+
"NA - North Atlantic": "AL",
|
1112 |
+
"EP - Eastern North Pacific": "EP",
|
1113 |
+
"WP - Western North Pacific": "WP",
|
1114 |
+
"NI - North Indian": ["IO", "BB", "AS"], # Multiple prefixes for North Indian
|
1115 |
+
"SI - South Indian": "SI",
|
1116 |
+
"SP - Southern Pacific": "SP",
|
1117 |
+
"SA - South Atlantic": "SL"
|
1118 |
+
}
|
1119 |
+
|
1120 |
+
def update_typhoon_options(year, basin):
|
1121 |
try:
|
1122 |
season = ibtracs.get_season(int(year))
|
1123 |
storm_summary = season.summary()
|
1124 |
|
1125 |
+
# Get the prefix for filtering
|
1126 |
+
prefix = basin_to_prefix.get(basin)
|
1127 |
+
|
1128 |
+
# Get all storms for the year
|
1129 |
options = []
|
1130 |
for i in range(len(storm_summary)):
|
1131 |
try:
|
1132 |
name = storm_summary['name'][i] if not pd.isna(storm_summary['name'][i]) else "Unnamed"
|
1133 |
storm_id = storm_summary['id'][i]
|
1134 |
+
|
1135 |
+
# Filter by basin if a specific basin is selected
|
1136 |
+
if prefix is None or (isinstance(prefix, list) and any(storm_id.startswith(p) for p in prefix)) or (not isinstance(prefix, list) and storm_id.startswith(prefix)):
|
1137 |
+
options.append(f"{name} ({storm_id})")
|
1138 |
except:
|
1139 |
continue
|
1140 |
|
|
|
1143 |
print(f"Error updating typhoon options: {e}")
|
1144 |
return gr.update(choices=[], value=None)
|
1145 |
|
1146 |
+
year_dropdown.change(fn=update_typhoon_options, inputs=[year_dropdown, basin_dropdown], outputs=typhoon_dropdown)
|
1147 |
+
basin_dropdown.change(fn=update_typhoon_options, inputs=[year_dropdown, basin_dropdown], outputs=typhoon_dropdown)
|
1148 |
|
1149 |
+
def simplified_track_video(year, basin, typhoon, standard):
|
1150 |
if not typhoon:
|
1151 |
return None
|
1152 |
|
1153 |
# Extract storm ID and generate video
|
1154 |
typhoon_id = typhoon.split('(')[-1].strip(')')
|
1155 |
+
return generate_track_video(year, "All", typhoon, standard) # Pass "All" as basin parameter for compatibility
|
1156 |
|
1157 |
animate_btn.click(
|
1158 |
fn=simplified_track_video,
|
1159 |
+
inputs=[year_dropdown, basin_dropdown, typhoon_dropdown, standard_dropdown],
|
1160 |
outputs=path_video
|
1161 |
)
|
1162 |
|