euler314 commited on
Commit
919234d
·
verified ·
1 Parent(s): 9af3c2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -5
app.py CHANGED
@@ -634,15 +634,37 @@ def get_available_years():
634
  # Function to get available typhoons for a selected year
635
  # Function to get available typhoons for a selected year
636
 
637
- # Create animation for typhoon path
638
  def create_typhoon_path_animation(year, typhoon_id, standard):
 
639
  if not year or not typhoon_id:
640
- return None
 
 
 
641
 
642
  try:
643
- storm = ibtracs.get_storm(typhoon_id)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
644
  fig = go.Figure()
645
 
 
646
  fig.add_trace(
647
  go.Scattergeo(
648
  lon=storm.lon,
@@ -654,6 +676,7 @@ def create_typhoon_path_animation(year, typhoon_id, standard):
654
  )
655
  )
656
 
 
657
  fig.add_trace(
658
  go.Scattergeo(
659
  lon=[storm.lon[0]],
@@ -666,6 +689,7 @@ def create_typhoon_path_animation(year, typhoon_id, standard):
666
  )
667
  )
668
 
 
669
  frames = []
670
  for i in range(len(storm.time)):
671
  category, color = categorize_typhoon_by_standard(storm.vmax[i], standard)
@@ -711,6 +735,7 @@ def create_typhoon_path_animation(year, typhoon_id, standard):
711
 
712
  fig.frames = frames
713
 
 
714
  fig.update_layout(
715
  title=f"{year} Year {storm.name} Typhoon Path",
716
  showlegend=False,
@@ -781,8 +806,12 @@ def create_typhoon_path_animation(year, typhoon_id, standard):
781
 
782
  return fig
783
  except Exception as e:
784
- print(f"Error creating typhoon path animation: {e}")
785
- return None
 
 
 
 
786
 
787
  # Function to analyze typhoon tracks
788
  # Function to analyze typhoon tracks
 
634
  # Function to get available typhoons for a selected year
635
  # Function to get available typhoons for a selected year
636
 
 
637
  def create_typhoon_path_animation(year, typhoon_id, standard):
638
+ """Create animation for typhoon path using a similar approach to the Dash version"""
639
  if not year or not typhoon_id:
640
+ empty_fig = go.Figure()
641
+ empty_fig.add_annotation(text="Please select a year and typhoon",
642
+ xref="paper", yref="paper", x=0.5, y=0.5, showarrow=False)
643
+ return empty_fig
644
 
645
  try:
646
+ # For debugging
647
+ print(f"Creating animation for year: {year}, typhoon: {typhoon_id}, standard: {standard}")
648
+
649
+ # If the input is a display name instead of an ID, extract the ID
650
+ if isinstance(typhoon_id, str) and "(" in typhoon_id and ")" in typhoon_id:
651
+ storm_id = typhoon_id.split("(")[-1].split(")")[0].strip()
652
+ else:
653
+ storm_id = typhoon_id
654
+
655
+ print(f"Using storm ID: {storm_id}")
656
+
657
+ storm = ibtracs.get_storm(storm_id)
658
+ if storm is None:
659
+ print(f"Storm not found with ID: {storm_id}")
660
+ empty_fig = go.Figure()
661
+ empty_fig.add_annotation(text=f"Storm not found with ID: {storm_id}",
662
+ xref="paper", yref="paper", x=0.5, y=0.5, showarrow=False)
663
+ return empty_fig
664
+
665
  fig = go.Figure()
666
 
667
+ # Add the full path
668
  fig.add_trace(
669
  go.Scattergeo(
670
  lon=storm.lon,
 
676
  )
677
  )
678
 
679
+ # Add the starting point
680
  fig.add_trace(
681
  go.Scattergeo(
682
  lon=[storm.lon[0]],
 
689
  )
690
  )
691
 
692
+ # Create frames for animation
693
  frames = []
694
  for i in range(len(storm.time)):
695
  category, color = categorize_typhoon_by_standard(storm.vmax[i], standard)
 
735
 
736
  fig.frames = frames
737
 
738
+ # Update layout with animation controls
739
  fig.update_layout(
740
  title=f"{year} Year {storm.name} Typhoon Path",
741
  showlegend=False,
 
806
 
807
  return fig
808
  except Exception as e:
809
+ print(f"Error creating typhoon path animation: {str(e)}")
810
+ error_fig = go.Figure()
811
+ error_fig.add_annotation(text=f"Error: {str(e)}",
812
+ xref="paper", yref="paper", x=0.5, y=0.5, showarrow=False)
813
+ return error_fig
814
+
815
 
816
  # Function to analyze typhoon tracks
817
  # Function to analyze typhoon tracks