Spaces:
Sleeping
Sleeping
Fix missing parameter errors by using defaults for removed variables
Browse files- Remove pressure (pmsl) processing since not downloaded
- Use default values for rain types, lightning, solar radiation
- Keep only downloaded parameters: temp, wind, precip, snow, clouds, cape, gusts
- Fixes KeyError crashes while maintaining fast downloads
app.py
CHANGED
|
@@ -434,15 +434,8 @@ def process_real_dwd_data(dwd_data, lat, lon):
|
|
| 434 |
vmax = data['vmax_10m'][i]
|
| 435 |
wind_gust.append(vmax if vmax is not None else wind_speed_val * 1.5)
|
| 436 |
|
| 437 |
-
# Pressure
|
| 438 |
-
|
| 439 |
-
if pmsl is not None:
|
| 440 |
-
if pmsl > 50000: # Pa
|
| 441 |
-
pressure.append(pmsl / 100)
|
| 442 |
-
else: # Already hPa
|
| 443 |
-
pressure.append(pmsl)
|
| 444 |
-
else:
|
| 445 |
-
pressure.append(1013.25) # Default
|
| 446 |
|
| 447 |
# Precipitation (convert from kg/m²/s to mm/h if needed)
|
| 448 |
tot_prec = data['tot_prec'][i]
|
|
@@ -454,35 +447,10 @@ def process_real_dwd_data(dwd_data, lat, lon):
|
|
| 454 |
else:
|
| 455 |
precipitation.append(0.0)
|
| 456 |
|
| 457 |
-
#
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
rain_convective.append(rain_con * 3600) # Convert to mm/h
|
| 462 |
-
else:
|
| 463 |
-
rain_convective.append(rain_con)
|
| 464 |
-
else:
|
| 465 |
-
rain_convective.append(0.0)
|
| 466 |
-
|
| 467 |
-
# Grid-scale rain
|
| 468 |
-
rain_gsp = data.get('rain_gsp', [None])[i] if 'rain_gsp' in data else None
|
| 469 |
-
if rain_gsp is not None:
|
| 470 |
-
if rain_gsp < 1: # kg/m²/s
|
| 471 |
-
rain_gridscale.append(rain_gsp * 3600) # Convert to mm/h
|
| 472 |
-
else:
|
| 473 |
-
rain_gridscale.append(rain_gsp)
|
| 474 |
-
else:
|
| 475 |
-
rain_gridscale.append(0.0)
|
| 476 |
-
|
| 477 |
-
# Convective snow
|
| 478 |
-
snow_con = data.get('snow_con', [None])[i] if 'snow_con' in data else None
|
| 479 |
-
if snow_con is not None:
|
| 480 |
-
if snow_con < 1: # kg/m²/s
|
| 481 |
-
snow_convective.append(snow_con * 3600) # Convert to mm/h
|
| 482 |
-
else:
|
| 483 |
-
snow_convective.append(snow_con)
|
| 484 |
-
else:
|
| 485 |
-
snow_convective.append(0.0)
|
| 486 |
|
| 487 |
# Grid-scale snow
|
| 488 |
snow_gsp = data.get('snow_gsp', [None])[i] if 'snow_gsp' in data else None
|
|
@@ -501,15 +469,11 @@ def process_real_dwd_data(dwd_data, lat, lon):
|
|
| 501 |
else:
|
| 502 |
cape.append(0.0)
|
| 503 |
|
| 504 |
-
# Lightning Potential
|
| 505 |
-
|
| 506 |
-
if lpi_con is not None:
|
| 507 |
-
lightning_potential.append(lpi_con)
|
| 508 |
-
else:
|
| 509 |
-
lightning_potential.append(0.0)
|
| 510 |
|
| 511 |
# Cloud cover (convert from fraction to percentage if needed)
|
| 512 |
-
clct = data
|
| 513 |
if clct is not None:
|
| 514 |
if clct <= 1.0: # Fraction
|
| 515 |
cloud_cover.append(clct * 100)
|
|
@@ -518,12 +482,8 @@ def process_real_dwd_data(dwd_data, lat, lon):
|
|
| 518 |
else:
|
| 519 |
cloud_cover.append(50.0) # Default
|
| 520 |
|
| 521 |
-
# Solar radiation
|
| 522 |
-
|
| 523 |
-
if asob_s is not None:
|
| 524 |
-
solar_radiation.append(max(0, asob_s)) # Ensure non-negative
|
| 525 |
-
else:
|
| 526 |
-
solar_radiation.append(0.0)
|
| 527 |
|
| 528 |
result = {
|
| 529 |
'timestamps': timestamps,
|
|
|
|
| 434 |
vmax = data['vmax_10m'][i]
|
| 435 |
wind_gust.append(vmax if vmax is not None else wind_speed_val * 1.5)
|
| 436 |
|
| 437 |
+
# Pressure - use default since we don't download it for speed
|
| 438 |
+
pressure.append(1013.25) # Default pressure for faster processing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 439 |
|
| 440 |
# Precipitation (convert from kg/m²/s to mm/h if needed)
|
| 441 |
tot_prec = data['tot_prec'][i]
|
|
|
|
| 447 |
else:
|
| 448 |
precipitation.append(0.0)
|
| 449 |
|
| 450 |
+
# Rain data - use defaults for faster processing
|
| 451 |
+
rain_convective.append(0.0) # Default - not downloaded
|
| 452 |
+
rain_gridscale.append(0.0) # Default - not downloaded
|
| 453 |
+
snow_convective.append(0.0) # Default - not downloaded
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
|
| 455 |
# Grid-scale snow
|
| 456 |
snow_gsp = data.get('snow_gsp', [None])[i] if 'snow_gsp' in data else None
|
|
|
|
| 469 |
else:
|
| 470 |
cape.append(0.0)
|
| 471 |
|
| 472 |
+
# Lightning Potential - use default for faster processing
|
| 473 |
+
lightning_potential.append(0.0) # Default - not downloaded
|
|
|
|
|
|
|
|
|
|
|
|
|
| 474 |
|
| 475 |
# Cloud cover (convert from fraction to percentage if needed)
|
| 476 |
+
clct = data.get('clct', [None])[i] if 'clct' in data else None
|
| 477 |
if clct is not None:
|
| 478 |
if clct <= 1.0: # Fraction
|
| 479 |
cloud_cover.append(clct * 100)
|
|
|
|
| 482 |
else:
|
| 483 |
cloud_cover.append(50.0) # Default
|
| 484 |
|
| 485 |
+
# Solar radiation - use default for faster processing
|
| 486 |
+
solar_radiation.append(0.0) # Default - not downloaded
|
|
|
|
|
|
|
|
|
|
|
|
|
| 487 |
|
| 488 |
result = {
|
| 489 |
'timestamps': timestamps,
|