Spaces:
Sleeping
Sleeping
ok
Browse files
app.py
CHANGED
@@ -169,6 +169,15 @@ class ECMWFWindDataProcessor:
|
|
169 |
u_values = u_values[::-1, :]
|
170 |
v_values = v_values[::-1, :]
|
171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
# Convert to lists and flatten in row-major order
|
173 |
u_data = u_values.flatten().tolist()
|
174 |
v_data = v_values.flatten().tolist()
|
@@ -1233,8 +1242,24 @@ def create_wind_map(region="global", forecast_mode=False):
|
|
1233 |
|
1234 |
return m._repr_html_()
|
1235 |
|
|
|
|
|
|
|
1236 |
def update_visualization(region, forecast_mode=False):
|
1237 |
"""Update wind visualization for selected region and mode"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1238 |
try:
|
1239 |
mode_str = "forecast" if forecast_mode else "current"
|
1240 |
print(f"🔄 Creating {mode_str} wind visualization for {region}")
|
@@ -1252,6 +1277,9 @@ def update_visualization(region, forecast_mode=False):
|
|
1252 |
error_msg = f"❌ Error: {str(e)}"
|
1253 |
print(error_msg)
|
1254 |
return f"<div style='padding: 20px; color: red;'>Error: {str(e)}</div>", error_msg
|
|
|
|
|
|
|
1255 |
|
1256 |
# Create Gradio interface
|
1257 |
with gr.Blocks(title="Wind Particle Visualization") as app:
|
|
|
169 |
u_values = u_values[::-1, :]
|
170 |
v_values = v_values[::-1, :]
|
171 |
|
172 |
+
# Downsample to reduce data size for better performance
|
173 |
+
# Skip every 4th point to reduce from 1M+ to ~65k points
|
174 |
+
downsample_factor = 4
|
175 |
+
lats = lats[::downsample_factor]
|
176 |
+
lons = lons[::downsample_factor]
|
177 |
+
u_values = u_values[::downsample_factor, ::downsample_factor]
|
178 |
+
v_values = v_values[::downsample_factor, ::downsample_factor]
|
179 |
+
|
180 |
+
|
181 |
# Convert to lists and flatten in row-major order
|
182 |
u_data = u_values.flatten().tolist()
|
183 |
v_data = v_values.flatten().tolist()
|
|
|
1242 |
|
1243 |
return m._repr_html_()
|
1244 |
|
1245 |
+
# Global state to prevent duplicate processing
|
1246 |
+
_processing_state = {"is_processing": False, "last_request": None}
|
1247 |
+
|
1248 |
def update_visualization(region, forecast_mode=False):
|
1249 |
"""Update wind visualization for selected region and mode"""
|
1250 |
+
global _processing_state
|
1251 |
+
|
1252 |
+
# Create unique request identifier
|
1253 |
+
request_id = f"{region}_{forecast_mode}"
|
1254 |
+
|
1255 |
+
# Prevent duplicate processing
|
1256 |
+
if _processing_state["is_processing"] and _processing_state["last_request"] == request_id:
|
1257 |
+
print(f"⚠️ Skipping duplicate request: {request_id}")
|
1258 |
+
return "⏳ Processing previous request...", "⏳ Processing..."
|
1259 |
+
|
1260 |
+
_processing_state["is_processing"] = True
|
1261 |
+
_processing_state["last_request"] = request_id
|
1262 |
+
|
1263 |
try:
|
1264 |
mode_str = "forecast" if forecast_mode else "current"
|
1265 |
print(f"🔄 Creating {mode_str} wind visualization for {region}")
|
|
|
1277 |
error_msg = f"❌ Error: {str(e)}"
|
1278 |
print(error_msg)
|
1279 |
return f"<div style='padding: 20px; color: red;'>Error: {str(e)}</div>", error_msg
|
1280 |
+
finally:
|
1281 |
+
# Reset processing state
|
1282 |
+
_processing_state["is_processing"] = False
|
1283 |
|
1284 |
# Create Gradio interface
|
1285 |
with gr.Blocks(title="Wind Particle Visualization") as app:
|