Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1069,8 +1069,7 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
|
1069 |
|
1070 |
with gr.Tab("Typhoon Path Animation"):
|
1071 |
with gr.Row():
|
1072 |
-
year_dropdown = gr.Dropdown(label="Year", choices=[str(y) for y in range(1950, 2025)], value="
|
1073 |
-
basin_dropdown = gr.Dropdown(label="Basin", choices=["NA", "EP", "WP", "NI", "SI", "SP", "SA", "All"], value="WP")
|
1074 |
typhoon_dropdown = gr.Dropdown(label="Tropical Cyclone")
|
1075 |
standard_dropdown = gr.Dropdown(label="Classification Standard", choices=['atlantic', 'taiwan'], value='atlantic')
|
1076 |
|
@@ -1078,7 +1077,7 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
|
1078 |
path_video = gr.Video(label="Tropical Cyclone Path Animation", elem_id="path_video")
|
1079 |
animation_info = gr.Markdown("""
|
1080 |
### Animation Instructions
|
1081 |
-
1. Select a year
|
1082 |
2. Choose a tropical cyclone from the populated list
|
1083 |
3. Select a classification standard (Atlantic or Taiwan)
|
1084 |
4. Click "Generate Animation"
|
@@ -1093,35 +1092,39 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
|
1093 |
Different agencies use different wind speed averaging periods: USA (1-min), JTWC (1-min), JMA (10-min), IMD (3-min).
|
1094 |
""")
|
1095 |
|
1096 |
-
def update_typhoon_options(year
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
# Check if this storm matches the selected basin
|
1106 |
-
if basin == "All" or storm_id.startswith(basin):
|
1107 |
name = storm_summary['name'][i] if not pd.isna(storm_summary['name'][i]) else "Unnamed"
|
|
|
1108 |
options.append(f"{name} ({storm_id})")
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
return gr.update(value="WP")
|
1117 |
|
1118 |
-
year_dropdown.change(fn=
|
1119 |
-
basin_dropdown.change(fn=update_typhoon_options, inputs=[year_dropdown, basin_dropdown], outputs=typhoon_dropdown)
|
1120 |
-
year_dropdown.change(fn=update_typhoon_options, inputs=[year_dropdown, basin_dropdown], outputs=typhoon_dropdown)
|
1121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1122 |
animate_btn.click(
|
1123 |
-
fn=
|
1124 |
-
inputs=[year_dropdown,
|
1125 |
outputs=path_video
|
1126 |
)
|
1127 |
|
@@ -1145,4 +1148,4 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
|
1145 |
outputs=[tsne_plot, routes_plot, stats_plot, cluster_info]
|
1146 |
)
|
1147 |
|
1148 |
-
demo.launch(share=True)
|
|
|
1069 |
|
1070 |
with gr.Tab("Typhoon Path Animation"):
|
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 |
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 dropdown
|
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 |
Different agencies use different wind speed averaging periods: USA (1-min), JTWC (1-min), JMA (10-min), IMD (3-min).
|
1093 |
""")
|
1094 |
|
1095 |
+
def update_typhoon_options(year):
|
1096 |
+
try:
|
1097 |
+
season = ibtracs.get_season(int(year))
|
1098 |
+
storm_summary = season.summary()
|
1099 |
+
|
1100 |
+
# Simply get all storms for the year
|
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 |
options.append(f"{name} ({storm_id})")
|
1107 |
+
except:
|
1108 |
+
continue
|
1109 |
+
|
1110 |
+
return gr.update(choices=options, value=options[0] if options else None)
|
1111 |
+
except Exception as e:
|
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 |
|
|
|
1148 |
outputs=[tsne_plot, routes_plot, stats_plot, cluster_info]
|
1149 |
)
|
1150 |
|
1151 |
+
demo.launch(share=True)
|