Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -237,20 +237,43 @@ class TyphoonAnalyzer:
|
|
237 |
return fig
|
238 |
def create_typhoon_animation(self, year, typhoon_id):
|
239 |
"""Create animated visualization of typhoon path"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
if not typhoon_id:
|
241 |
-
return
|
242 |
|
|
|
243 |
storm_data = self.typhoon_data[self.typhoon_data['SID'] == typhoon_id]
|
244 |
if storm_data.empty:
|
245 |
-
return
|
246 |
|
247 |
storm_data = storm_data.sort_values('ISO_TIME')
|
|
|
248 |
|
249 |
fig = go.Figure()
|
250 |
|
251 |
# Base map settings
|
252 |
fig.update_layout(
|
253 |
-
title=f"Typhoon Path Animation - {
|
254 |
showlegend=True,
|
255 |
geo=dict(
|
256 |
projection_type='mercator',
|
@@ -321,13 +344,26 @@ class TyphoonAnalyzer:
|
|
321 |
}]
|
322 |
)
|
323 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
info_text = f"""
|
325 |
### Typhoon Information
|
326 |
-
- Name: {
|
327 |
- Start Date: {storm_data['ISO_TIME'].iloc[0]:%Y-%m-%d %H:%M}
|
328 |
- End Date: {storm_data['ISO_TIME'].iloc[-1]:%Y-%m-%d %H:%M}
|
329 |
- Maximum Wind Speed: {storm_data['USA_WIND'].max():.1f} kt
|
330 |
- Minimum Pressure: {storm_data['WMO_PRES'].min():.1f} hPa
|
|
|
331 |
"""
|
332 |
|
333 |
return fig, info_text
|
|
|
237 |
return fig
|
238 |
def create_typhoon_animation(self, year, typhoon_id):
|
239 |
"""Create animated visualization of typhoon path"""
|
240 |
+
# Create default empty figure
|
241 |
+
empty_fig = go.Figure()
|
242 |
+
empty_fig.update_layout(
|
243 |
+
title="No Data Available",
|
244 |
+
showlegend=False,
|
245 |
+
geo=dict(
|
246 |
+
projection_type='mercator',
|
247 |
+
showland=True,
|
248 |
+
showcoastlines=True,
|
249 |
+
landcolor='rgb(243, 243, 243)',
|
250 |
+
countrycolor='rgb(204, 204, 204)',
|
251 |
+
coastlinecolor='rgb(214, 214, 214)',
|
252 |
+
showocean=True,
|
253 |
+
oceancolor='rgb(230, 250, 255)',
|
254 |
+
lataxis=dict(range=[0, 50]),
|
255 |
+
lonaxis=dict(range=[100, 180]),
|
256 |
+
center=dict(lat=20, lon=140)
|
257 |
+
)
|
258 |
+
)
|
259 |
+
|
260 |
+
# Input validation
|
261 |
if not typhoon_id:
|
262 |
+
return empty_fig, "Please select a typhoon"
|
263 |
|
264 |
+
# Get storm data
|
265 |
storm_data = self.typhoon_data[self.typhoon_data['SID'] == typhoon_id]
|
266 |
if storm_data.empty:
|
267 |
+
return empty_fig, "No data available for selected typhoon"
|
268 |
|
269 |
storm_data = storm_data.sort_values('ISO_TIME')
|
270 |
+
storm_name = storm_data['NAME'].iloc[0] if not storm_data.empty else "Unknown"
|
271 |
|
272 |
fig = go.Figure()
|
273 |
|
274 |
# Base map settings
|
275 |
fig.update_layout(
|
276 |
+
title=f"Typhoon Path Animation - {storm_name}",
|
277 |
showlegend=True,
|
278 |
geo=dict(
|
279 |
projection_type='mercator',
|
|
|
344 |
}]
|
345 |
)
|
346 |
|
347 |
+
# Add initial data
|
348 |
+
fig.add_trace(
|
349 |
+
go.Scattergeo(
|
350 |
+
lon=[storm_data['LON'].iloc[0]],
|
351 |
+
lat=[storm_data['LAT'].iloc[0]],
|
352 |
+
mode='markers',
|
353 |
+
marker=dict(size=8, color='red'),
|
354 |
+
name='Start Point',
|
355 |
+
showlegend=True
|
356 |
+
)
|
357 |
+
)
|
358 |
+
|
359 |
info_text = f"""
|
360 |
### Typhoon Information
|
361 |
+
- Name: {storm_name}
|
362 |
- Start Date: {storm_data['ISO_TIME'].iloc[0]:%Y-%m-%d %H:%M}
|
363 |
- End Date: {storm_data['ISO_TIME'].iloc[-1]:%Y-%m-%d %H:%M}
|
364 |
- Maximum Wind Speed: {storm_data['USA_WIND'].max():.1f} kt
|
365 |
- Minimum Pressure: {storm_data['WMO_PRES'].min():.1f} hPa
|
366 |
+
- Duration: {(storm_data['ISO_TIME'].iloc[-1] - storm_data['ISO_TIME'].iloc[0]).total_seconds() / 3600:.1f} hours
|
367 |
"""
|
368 |
|
369 |
return fig, info_text
|