You need to modify the weather forecasting system so that:
- Days 1-5: Use real weather API data (OpenWeatherMap) - already working
- Months 2-7 (6 months): Use continent/hemisphere climate pattern data for temperature charts and forecasts
- Frontend (
unified_dashboard.js): Displays 6-month forecast but expects different data formats - Backend APIs:
src/api.py: Main API with NASA POWER data integrationsrc/professional_api.py: Has forecast endpoint but uses ML models
- Data Sources:
data/continents/: 7 continent files (asia.json, europe.json, etc.)data/hemispheres/: northern_hemisphere.json, southern_hemisphere.json- Weather APIs: OpenWeatherMap for current/short-term
- Frontend expects temperature charts but backend doesn't provide them properly
- No clear separation between short-term (1-5 days) and long-term (6 months) forecasting
- Continent/hemisphere data exists but isn't integrated into the forecasting pipeline
Task 1.1: Add new endpoint /forecast/hybrid that intelligently chooses data source:
@app.post("/forecast/hybrid")
async def hybrid_forecast(request: ForecastRequest):
"""
Hybrid forecast that uses different data sources based on time range:
- Days 1-5: Weather API data
- Months 2-7: Climate pattern data from continents/hemispheres
"""Task 1.2: Implement time-based data source selection:
- If
days_ahead <= 5: UseWeatherDataFetcher.fetch_forecast_data() - If
days_ahead > 5: Use continent/hemisphere climate patterns
Task 1.3: Create climate pattern data fetcher class:
class ClimatePatternFetcher:
@staticmethod
def load_continent_data():
# Load all continent JSON files
@staticmethod
def load_hemisphere_data():
# Load hemisphere JSON files
@staticmethod
def get_region_from_coordinates(lat, lon):
# Determine continent and hemisphere from coordinates
# Return: {"continent": "asia", "hemisphere": "northern"}
@staticmethod
def generate_monthly_forecast(continent, hemisphere, start_month, months=6):
# Generate 6-month forecast using climate patterns
# Return temperature, precipitation, humidity, wind dataTask 2.1: Update /forecast endpoint to use hybrid approach:
- Keep existing logic but add fallback to climate patterns for longer ranges
- Ensure response format matches frontend expectations
Task 2.2: Add temperature chart data to forecast response:
# In forecast response, add:
"temperature_chart": {
"daily_temperatures": [...], # For first 5 days
"monthly_temperatures": [...], # For 6 months
"data_source": "weather_api" | "climate_patterns"
}Task 3.1: Create new file for climate pattern logic:
# src/climate_service.py
import json
import os
from datetime import datetime, timedelta
class ClimatePatternService:
def __init__(self):
self.continent_data = {}
self.hemisphere_data = {}
self.load_climate_data()
def load_climate_data(self):
# Load all continent and hemisphere JSON files
# Handle file paths and parsing
def get_region_info(self, lat, lon):
# Determine continent and hemisphere
# Use coordinate ranges from location_mapping.json
def generate_six_month_forecast(self, lat, lon, start_date=None):
# Generate 6-month forecast using climate patterns
# Return structured data for frontend chartsTask 4.1: Modify existing weather_data_manager.js to work with backend:
- Keep existing continent/hemisphere data loading
- Add method to fetch data from backend API
- Ensure data format compatibility
Task 4.2: Update forecast data structure to include:
{
month: "Jan",
temperature: { min: 15, max: 25, avg: 20 },
precipitation: { avg: 120 },
humidity: { avg: 65 },
data_source: "🌍 Asia Climate Pattern",
// Add temperature chart data
temperature_chart: [20, 21, 19, 22, 20, 21, ...]
}Task 5.1: Ensure all forecast endpoints return consistent format:
{
"forecasts": [
{
"month": "Jan",
"temperature": {"min": 15, "max": 25, "avg": 20},
"humidity": {"avg": 65},
"precipitation": {"avg": 120},
"wind_speed": {"avg": 18},
"extreme_weather_risk": {...},
"data_source": "🌍 Asia Climate Pattern",
"temperature_chart": [20, 21, 19, 22, ...],
"confidence": 0.75
}
],
"metadata": {
"generated_at": "2025-01-01T00:00:00",
"location": {"lat": 19.076, "lon": 72.877}
}
}- Verify all data files exist:
data/continents/*.json(7 files)data/hemispheres/*.json(2 files)data/location_mapping.json
- Create
src/climate_service.py - Implement data loading methods
- Implement coordinate-to-region mapping
- Implement forecast generation logic
- Modify
src/api.pyforecast endpoint - Add hybrid forecast endpoint
- Ensure proper error handling
- Add temperature chart data to responses
- Test short-term forecasts (1-5 days) use weather API
- Test long-term forecasts (6 months) use climate patterns
- Verify frontend displays temperature charts correctly
- Check data source indicators work properly
User Request (Frontend)
↓
API Endpoint (/forecast/hybrid)
↓
Time-based Routing:
├── Days 1-5: Weather API
└── Months 2-7: Climate Patterns
↓
Data Integration:
├── Short-term: Real weather data
└── Long-term: Continent/Hemisphere patterns
↓
Response Formatting:
├── Temperature charts
├── Monthly averages
└── Data source indicators
↓
Frontend Display:
├── Current weather (weather API)
└── 6-month forecast (climate patterns)
- Create:
src/climate_service.py- Climate pattern logic - Modify:
src/api.py- Add hybrid forecast endpoint - Modify:
src/professional_api.py- Update forecast logic (if needed) - No Changes:
frontend/unified_dashboard.js- Keep as-is
After implementation:
- Days 1-5: Accurate weather API data with real forecasts
- Months 2-7: Climate pattern-based forecasts with temperature charts
- Frontend displays both seamlessly
- Clear data source indicators (🌍 for climate patterns, 🌐 for weather API)
- Temperature charts show different patterns for short vs long term
- Short-term forecast (1-5 days) uses weather API
- Long-term forecast (6 months) uses climate patterns
- Temperature charts display correctly in frontend
- Data source indicators work properly
- No frontend code changes required
- All continent/hemisphere data files are utilized
- Error handling for missing data
- Coordinate-to-region mapping works correctly