Spaces:
Sleeping
Sleeping
Fix advisories generation error in NOAA text forecasting
Browse files- Fix ValueError in generate_advisories when finding max wind speed
- Correct event property access using proper dictionary keys
- Add additional advisory types (freeze warning, heat advisory)
- Improve error handling for empty event sequences
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -843,23 +843,30 @@ def generate_advisories(events):
|
|
| 843 |
"""
|
| 844 |
advisories = []
|
| 845 |
|
| 846 |
-
# Check for significant events
|
| 847 |
-
|
| 848 |
-
max_precip = max([e.get('precipitation', 0) for e in events if 'precipitation' in str(e)])
|
| 849 |
-
severe_events = [e for e in events if e['severity'] == 'significant']
|
| 850 |
-
|
| 851 |
-
if any('very_windy' in str(e) for e in events):
|
| 852 |
advisories.append("• **Wind Advisory:** Sustained winds 15-25 m/s with gusts up to 30 m/s possible")
|
| 853 |
|
| 854 |
-
if any('
|
| 855 |
advisories.append("• **Heavy Rain:** Rainfall rates may exceed 5mm/h, leading to localized flooding")
|
| 856 |
|
| 857 |
-
if any('
|
| 858 |
advisories.append("• **Thunderstorm Watch:** Conditions favorable for thunderstorm development")
|
| 859 |
|
| 860 |
-
if any('
|
| 861 |
advisories.append("• **Winter Weather:** Snow accumulation possible, use caution when traveling")
|
| 862 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 863 |
return '\n'.join(advisories)
|
| 864 |
|
| 865 |
def create_forecast_plot(forecast_data):
|
|
|
|
| 843 |
"""
|
| 844 |
advisories = []
|
| 845 |
|
| 846 |
+
# Check for significant events based on wind descriptors and conditions
|
| 847 |
+
if any(e.get('wind_descriptor') == 'very_windy' for e in events):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 848 |
advisories.append("• **Wind Advisory:** Sustained winds 15-25 m/s with gusts up to 30 m/s possible")
|
| 849 |
|
| 850 |
+
if any(e.get('precipitation_type') == 'heavy_rain' for e in events):
|
| 851 |
advisories.append("• **Heavy Rain:** Rainfall rates may exceed 5mm/h, leading to localized flooding")
|
| 852 |
|
| 853 |
+
if any(e.get('precipitation_type') == 'thunderstorms' for e in events):
|
| 854 |
advisories.append("• **Thunderstorm Watch:** Conditions favorable for thunderstorm development")
|
| 855 |
|
| 856 |
+
if any(e.get('precipitation_type') == 'snow' for e in events):
|
| 857 |
advisories.append("• **Winter Weather:** Snow accumulation possible, use caution when traveling")
|
| 858 |
|
| 859 |
+
if any(e.get('temperature_descriptor') == 'freezing' for e in events):
|
| 860 |
+
advisories.append("• **Freeze Warning:** Temperatures at or below freezing expected")
|
| 861 |
+
|
| 862 |
+
if any(e.get('temperature_descriptor') == 'hot' for e in events):
|
| 863 |
+
advisories.append("• **Heat Advisory:** High temperatures may cause heat stress")
|
| 864 |
+
|
| 865 |
+
# Check for significant severity events
|
| 866 |
+
severe_events = [e for e in events if e.get('severity') == 'significant']
|
| 867 |
+
if severe_events and not advisories:
|
| 868 |
+
advisories.append("• **Weather Advisory:** Significant weather conditions expected")
|
| 869 |
+
|
| 870 |
return '\n'.join(advisories)
|
| 871 |
|
| 872 |
def create_forecast_plot(forecast_data):
|