Spaces:
Running
Running
Update app.py
Browse files
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
|
134 |
all_basins_path = os.path.join(DATA_PATH, 'ibtracs.ALL.list.v04r01.csv')
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
|
|
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:
|