euler314 commited on
Commit
941ecf3
·
verified ·
1 Parent(s): 1c62817

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -29
app.py CHANGED
@@ -130,37 +130,38 @@ def load_ibtracs_data():
130
  with open(CACHE_FILE, 'rb') as f:
131
  return pickle.load(f)
132
 
133
- # Define both paths we might need
134
  all_basins_path = os.path.join(DATA_PATH, 'ibtracs.ALL.list.v04r01.csv')
135
 
136
- # Try to load all basins file first
137
- if os.path.exists(all_basins_path):
138
- print("Loading ALL basins file...")
139
- ibtracs = tracks.TrackDataset(source='ibtracs', ibtracs_url=all_basins_path)
140
- else:
141
- print("Downloading ALL basins file...")
142
- response = requests.get(iBtrace_uri)
143
- response.raise_for_status()
144
- with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.csv') as temp_file:
145
- temp_file.write(response.text)
146
- shutil.move(temp_file.name, all_basins_path)
147
- # Make sure we load the full ALL dataset
148
- ibtracs = tracks.TrackDataset(source='ibtracs', ibtracs_url=all_basins_path)
149
-
150
- # Check if we have all basins
151
- available_basins = set()
152
- for storm_id in ibtracs.keys():
153
- if len(storm_id) >= 2:
154
- basin_code = storm_id[:2] # First two characters are usually basin code
155
- available_basins.add(basin_code)
156
-
157
- print(f"Available basin codes: {available_basins}")
158
-
159
- # Save to cache
160
- with open(CACHE_FILE, 'wb') as f:
161
- pickle.dump(ibtracs, f)
162
-
163
- return ibtracs
 
164
 
165
  def convert_typhoondata(input_file, output_file):
166
  with open(input_file, 'r') as infile:
 
130
  with open(CACHE_FILE, 'rb') as f:
131
  return pickle.load(f)
132
 
133
+ # Define the path for the all basins file
134
  all_basins_path = os.path.join(DATA_PATH, 'ibtracs.ALL.list.v04r01.csv')
135
 
136
+ try:
137
+ # Try to load all basins file first
138
+ if os.path.exists(all_basins_path):
139
+ print("Loading ALL basins file...")
140
+ ibtracs = tracks.TrackDataset(source='ibtracs', ibtracs_url=all_basins_path)
141
+ else:
142
+ print("Downloading ALL basins file...")
143
+ response = requests.get(iBtrace_uri)
144
+ response.raise_for_status()
145
+ with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.csv') as temp_file:
146
+ temp_file.write(response.text)
147
+ shutil.move(temp_file.name, all_basins_path)
148
+ # Load the full ALL dataset
149
+ ibtracs = tracks.TrackDataset(source='ibtracs', ibtracs_url=all_basins_path)
150
+
151
+ # Save to cache
152
+ with open(CACHE_FILE, 'wb') as f:
153
+ pickle.dump(ibtracs, f)
154
+
155
+ return ibtracs
156
+
157
+ except Exception as e:
158
+ print(f"Error loading IBTrACS data: {e}")
159
+ # As a fallback, try loading just the default data that comes with tropycal
160
+ print("Attempting to load default dataset...")
161
+ ibtracs = tracks.TrackDataset(basin='all')
162
+ with open(CACHE_FILE, 'wb') as f:
163
+ pickle.dump(ibtracs, f)
164
+ return ibtracs
165
 
166
  def convert_typhoondata(input_file, output_file):
167
  with open(input_file, 'r') as infile: