""" Test WeatherWise with REAL weather data from NASA POWER API This simulates exactly what the API does """ import sys import os sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'server')) import numpy as np # Import the actual services and models from models.weather_model import WeatherDataModel, WeatherRequest from models.feature_engineering_model import FeatureEngineeringModel from services.weather_service import WeatherService from services.feature_engineering_service import FeatureEngineeringService print("Initializing services...") weather_model = WeatherDataModel() weather_service = WeatherService(weather_model) feature_model = FeatureEngineeringModel() feature_service = FeatureEngineeringService(feature_model) # Field mappings (same as in weatherwise_prediction_service.py) field_mappings = { 'humidity_perc': 'humidity_%', 'cloud_amount_perc': 'cloud_amount_%', 'surface_soil_wetness_perc': 'surface_soil_wetness_%', 'root_zone_soil_moisture_perc': 'root_zone_soil_moisture_%', 'adjusted_humidity': 'adjusted_humidity' # This one has no suffix change } def apply_field_mappings(data): mapped_data = {} for key, value in data.items(): mapped_key = field_mappings.get(key, key) mapped_data[mapped_key] = value return mapped_data # Test two different locations locations = [ ("Delhi", 28.6139, 77.2090), ("Sydney", -33.8688, 151.2093), ] results = [] for name, lat, lon in locations: print(f"\n=== Testing {name} ({lat}, {lon}) ===") # Fetch weather data weather_request = WeatherRequest( latitude=lat, longitude=lon, disaster_date="2026-03-22", # Recent date days_before=60 ) weather_success, weather_result = weather_service.fetch_weather_data(weather_request) if not weather_success: print(f"Weather fetch failed for {name}: {weather_result}") continue weather_data = weather_result.get('weather_data', {}) print(f"Weather data variables: {len(weather_data)}") # Get engineered features feature_success, feature_result = feature_service.process_weather_features( weather_data=weather_data, event_duration=1.0, include_metadata=True ) if not feature_success: print(f"Feature engineering failed for {name}: {feature_result}") continue feature_data = feature_result.get('engineered_features', {}) print(f"Engineered features: {len(feature_data)}") # Apply field mappings mapped_weather = apply_field_mappings(weather_data) # Print first values of key features print(f"\nFirst values of key features for {name}:") for key in ['temperature_C', 'humidity_%', 'precipitation_mm']: if key in mapped_weather: print(f" {key}: {mapped_weather[key][0]:.2f}") elif key in feature_data: print(f" {key}: {feature_data[key][0]:.2f}") results.append({ 'name': name, 'temp': mapped_weather.get('temperature_C', [0])[0], 'precip': mapped_weather.get('precipitation_mm', [0])[0] }) # Compare results print("\n=== Comparison ===") for r in results: print(f"{r['name']}: temp={r['temp']:.2f}°C, precip={r['precip']:.2f}mm") if len(results) == 2: temp_diff = abs(results[0]['temp'] - results[1]['temp']) print(f"\nTemperature difference: {temp_diff:.2f}°C") if temp_diff < 1: print("*** WARNING: Temperature difference is very small - possible data issue ***") else: print("*** Weather data varies correctly between locations ***")