https://github.com/namanxdev/atmopredict
Machine learning weather prediction platform leveraging NASA POWER API data. Features: 5 binary classifiers, 100+ engineered features, interactive React UI with Leaflet maps, FastAPI backend. Predicts extreme weather events with probability scores.
https://github.com/namanxdev/atmopredict
fastapi nasa nasa-spaceapps-challenge prediction-model react weather
Last synced: 2 months ago
JSON representation
Machine learning weather prediction platform leveraging NASA POWER API data. Features: 5 binary classifiers, 100+ engineered features, interactive React UI with Leaflet maps, FastAPI backend. Predicts extreme weather events with probability scores.
- Host: GitHub
- URL: https://github.com/namanxdev/atmopredict
- Owner: namanxdev
- Created: 2025-10-05T16:27:52.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-10-05T16:48:14.000Z (9 months ago)
- Last Synced: 2025-10-05T18:35:46.586Z (9 months ago)
- Topics: fastapi, nasa, nasa-spaceapps-challenge, prediction-model, react, weather
- Language: Python
- Homepage:
- Size: 222 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ AtmoPredict - Extreme Weather Forecasting System
> An intelligent weather prediction system using **LSTM deep learning** to forecast extreme weather conditions with NASA POWER data
[](https://www.python.org/)
[](https://fastapi.tiangolo.com/)
[](https://reactjs.org/)
[](https://www.tensorflow.org/)
[](LICENSE)
## ๐ Table of Contents
- [Overview](#-overview)
- [Features](#-features)
- [Technology Stack](#-technology-stack)
- [System Architecture](#-system-architecture)
- [Installation](#-installation)
- [Usage](#-usage)
- [API Documentation](#-api-documentation)
- [Model Details](#-model-details)
- [Project Structure](#-project-structure)
- [Contributing](#-contributing)
## ๐ฏ Overview
**AtmoPredict** is an advanced weather forecasting system that uses a **trained LSTM (Long Short-Term Memory) deep learning model** to predict climate anomalies and extreme weather conditions:
- ๐ฅ **Very Hot** - High temperature events
- โ๏ธ **Very Cold** - Low temperature events
- ๐จ **Very Windy** - High wind speed events
- ๐ง๏ธ **Very Wet** - Heavy precipitation events
- ๐ฅต **Very Uncomfortable** - High heat index conditions
The system uses an **LSTM neural network** trained on historical NASA POWER weather data (2010-2024) to predict **temperature and precipitation anomalies**, which are then converted to extreme weather probabilities. Predictions are delivered through an interactive web interface.
## โจ Features
### ๐ค LSTM Deep Learning Model
- **LSTM Neural Network**: Advanced time-series prediction using TensorFlow/Keras
- **Climate Anomaly Prediction**: Forecasts temperature and precipitation anomalies
- **Model Performance**:
- Temperature Anomaly: Rยฒ = 0.35, RMSE = 0.107
- Precipitation Anomaly: Rยฒ = 0.79, RMSE = 0.237
- **18 Input Features**: Including temporal patterns, weather parameters, and location data
- **Trained on NASA POWER Data**: 2010-2024, 10 major global cities
- **Automatic Probability Conversion**: Converts anomalies to extreme weather probabilities
### ๐ Web Interface
- **Modern React UI** with Tailwind CSS and DaisyUI
- **Interactive Maps** using Leaflet for location selection
- **Real-time Forecasts** with probability visualizations
- **Multi-day Predictions** with detailed weather insights
- **Responsive Design** for desktop and mobile
### ๐ Backend API
- **FastAPI** for high-performance async operations
- **LSTM Model Integration** for intelligent predictions
- **RESTful Endpoints** for forecasting and climate data
- **Automatic Documentation** with Swagger UI
- **CORS Enabled** for cross-origin requests
- **Health Check** and monitoring endpoints
### ๐ Data Sources
- **NASA POWER API** - Historical climate data (2010-2024)
- **OpenWeatherMap API** - Real-time current weather
- **Continental Climate Patterns** - Long-term forecasting (6 months)
- **Hemisphere Data** - Global climate context
## ๐ Technology Stack
### Backend
- **Python 3.8+** - Core programming language
- **FastAPI** - Modern async web framework
- **Uvicorn** - ASGI server
- **TensorFlow 2.15+** - Deep learning framework
- **Keras 3.0+** - Neural network API
- **scikit-learn** - Data preprocessing and utilities
- **pandas/numpy** - Data manipulation
### Frontend
- **React 19** - UI library
- **Vite** - Build tool and dev server
- **Tailwind CSS** - Utility-first CSS framework
- **DaisyUI** - Component library
- **Leaflet** - Interactive maps
- **Axios** - HTTP client
- **Plotly.js** - Data visualization
### Data Source
- **NASA POWER API** - Global weather and solar data
- **OpenWeatherMap API** - Real-time weather data
- **Coverage**: 2010-2024 historical data
- **Resolution**: Daily/Monthly temporal granularity
- **Parameters**: Temperature, precipitation, wind, humidity, pressure, cloud cover, radiation
## ๐ System Architecture
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ USER INTERFACE โ
โ (React + Tailwind + Leaflet) โ
โ http://localhost:5173 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HTTP/JSON
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ BACKEND API โ
โ (FastAPI + Uvicorn) โ
โ http://127.0.0.1:8000 โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Endpoints: โ โ
โ โ โข POST /predict - LSTM predictions โ โ
โ โ โข POST /forecast/hybrid - Hybrid forecasts โ โ
โ โ โข POST /forecast - Long-term forecasts โ โ
โ โ โข GET /climate/summary - Climate information โ โ
โ โ โข GET /docs - API documentation โ โ
โ โ โข GET /health - Health check โ โ
โ โ โข GET /model/info - LSTM model info โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ LSTM DEEP LEARNING MODEL โ
โ (ml nasa/models/climate_lstm_model.keras) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ LSTM Neural Network: โ โ
โ โ โข Input: 18 features (weather + temporal) โ โ
โ โ โข Output: 2 predictions โ โ
โ โ - Temperature Anomaly โ โ
โ โ - Precipitation Anomaly โ โ
โ โ โ โ
โ โ Converted to 5 Extreme Weather Probabilities: โ โ
โ โ โข very_hot (hot temperature events) โ โ
โ โ โข very_cold (cold temperature events) โ โ
โ โ โข very_windy (high wind conditions) โ โ
โ โ โข very_wet (heavy precipitation) โ โ
โ โ โข very_uncomfortable (high heat index) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DATA SOURCES โ
โ โ
โ โข NASA POWER API (historical 2010-2024) โ
โ โข OpenWeatherMap API (current weather) โ
โ โข Continental Climate Patterns (data/continents/) โ
โ โข Hemisphere Data (data/hemispheres/) โ
โ โข Location Mappings (data/location_mapping.json) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
## ๐ฅ Installation
### Prerequisites
- **Python 3.8+** installed
- **Node.js 16+** and npm installed
- **Git** installed
- **Windows OS** (batch files provided) or adapt for Linux/Mac
### Step 1: Clone the Repository
```bash
git clone https://github.com/namanxdev/AtmoPredict.git
cd AtmoPredict
```
### Step 2: Backend Setup
#### Option A: Using Batch File (Windows)
```bash
INSTALL_FIRST.bat
```
This will:
- Create a Python virtual environment
- Install all required Python packages
- Verify installation
#### Option B: Manual Installation
```bash
# Create virtual environment
python -m venv venv
# Activate virtual environment
venv\Scripts\activate # Windows
# source venv/bin/activate # Linux/Mac
# Install dependencies
pip install -r requirements.txt
```
### Step 3: Frontend Setup
```bash
cd Frontend_nasa
# Install Node.js dependencies
npm install
cd ..
```
### Step 4: Verify Installation
```bash
python check_installation.py
```
## ๐ Usage
### Quick Start (Recommended)
Use the provided batch files to start the entire system:
#### Option 1: Complete System
```bash
START_COMPLETE_SYSTEM.bat
```
This starts both the backend API and frontend development server.
#### Option 2: Manual Start
**Terminal 1 - Start Backend API:**
```bash
venv\Scripts\activate
uvicorn src.api:app --host 127.0.0.1 --port 8000 --reload
```
**Terminal 2 - Start Frontend:**
```bash
cd Frontend_nasa
npm run dev
```
### Access the Application
- **Frontend UI**: http://localhost:5173
- **Backend API**: http://127.0.0.1:8000
- **API Documentation**: http://127.0.0.1:8000/docs
- **Alternative API Docs**: http://127.0.0.1:8000/redoc
### Using the Web Interface
1. **Open the Application**: Navigate to http://localhost:5173
2. **Enter Location**:
- Click on the map to select a location
- Or enter latitude/longitude manually
3. **View Current Weather**: See real-time weather conditions
4. **Get Forecast**: Click "Get Forecast" to see predictions
5. **Analyze Results**: View probabilities and risk levels for each extreme condition
## ๐ก API Documentation
### Main Forecast Endpoint
**POST** `/forecast/hybrid`
Request body:
```json
{
"latitude": 40.7128,
"longitude": -74.0060,
"forecast_days": 7,
"location_name": "New York"
}
```
Response:
```json
{
"location": {
"name": "New York",
"latitude": 40.7128,
"longitude": -74.006,
"continent": "North America",
"hemisphere": "Northern"
},
"current_weather": {
"temperature": 22.5,
"feels_like": 24.3,
"humidity": 65,
"wind_speed": 3.2,
"description": "Partly cloudy"
},
"forecast": [
{
"date": "2024-10-06",
"predictions": {
"very_hot": 0.12,
"very_cold": 0.05,
"very_windy": 0.18,
"very_wet": 0.35,
"very_uncomfortable": 0.09
},
"risk_level": "MODERATE",
"max_risk_category": "very_wet"
}
],
"summary": {
"highest_risk_day": "2024-10-08",
"dominant_risk": "very_wet",
"average_risk_level": "MODERATE"
}
}
```
### Climate Summary Endpoint
**GET** `/climate/summary`
Query parameters:
- `latitude` (required): Latitude coordinate
- `longitude` (required): Longitude coordinate
Response:
```json
{
"location": {
"latitude": 40.7128,
"longitude": -74.006,
"continent": "North America",
"hemisphere": "Northern"
},
"climate_info": {
"description": "Humid subtropical climate",
"temperature_range": "Cold winters, hot summers",
"precipitation": "Evenly distributed throughout year"
}
}
```
### Health Check Endpoint
**GET** `/health`
Response:
```json
{
"status": "healthy",
"models_loaded": 5,
"timestamp": "2024-10-05T12:00:00"
}
```
## ๐ค Model Details
### LSTM Neural Network Architecture
The system uses a trained **LSTM (Long Short-Term Memory)** deep learning model for climate prediction:
#### Model Specifications
- **Type**: LSTM Neural Network (TensorFlow/Keras)
- **Input Shape**: (timesteps=1, features=18)
- **Output Shape**: 2 predictions (temperature anomaly, precipitation anomaly)
- **Training Data**: NASA POWER climate data (2010-2024)
- **Locations**: 10 major global cities
- **Total Samples**: ~1,800 data points
#### Performance Metrics
- **Temperature Anomaly Prediction**:
- Rยฒ Score: 0.35
- RMSE: 0.107
- MAE: 0.085
- **Precipitation Anomaly Prediction**:
- Rยฒ Score: 0.79
- RMSE: 0.237
- MAE: 0.178
#### Input Features (18 total)
1. **Weather Parameters** (scaled):
- T2M (mean temperature)
- T2M_MAX (maximum temperature)
- T2M_MIN (minimum temperature)
- PRECTOTCORR (precipitation, log-transformed)
- ALLSKY_SFC_SW_DWN (solar radiation)
- RH2M (relative humidity)
- QV2M (specific humidity)
- T2M_range (temperature range)
2. **Temporal Features**:
- month_sin (cyclical month encoding)
- month_cos (cyclical month encoding)
- season (encoded)
3. **Location Features**:
- latitude (scaled)
- longitude (scaled)
4. **Derived Features**:
- precip_log (log-transformed precipitation)
- heat_index components
#### Prediction Pipeline
```
Input Weather Data
โ
Feature Extraction (18 features)
โ
Feature Scaling (StandardScaler)
โ
LSTM Model Inference
โ
Output: [temp_anomaly, precip_anomaly]
โ
Probability Conversion
โ
5 Extreme Weather Probabilities:
โข very_hot (0.0 - 1.0)
โข very_cold (0.0 - 1.0)
โข very_windy (0.0 - 1.0)
โข very_wet (0.0 - 1.0)
โข very_uncomfortable (0.0 - 1.0)
```
#### Anomaly to Probability Conversion
The LSTM model predicts **temperature and precipitation anomalies** (deviations from normal). These are converted to extreme weather probabilities using:
1. **Very Hot**: Based on adjusted temperature (base_temp + anomaly) and positive temperature anomaly
2. **Very Cold**: Based on adjusted temperature and negative temperature anomaly
3. **Very Wet**: Based on adjusted precipitation (base_precip ร (1 + anomaly)) and positive precipitation anomaly
4. **Very Windy**: Based on current wind speed measurements
5. **Very Uncomfortable**: Based on calculated heat index (temperature + humidity interaction)
### Risk Level Calculation
```python
max_probability = max(all_predictions)
if max_probability >= 0.8: risk_level = "EXTREME"
elif max_probability >= 0.6: risk_level = "HIGH"
elif max_probability >= 0.4: risk_level = "MODERATE"
elif max_probability >= 0.2: risk_level = "LOW"
else: risk_level = "MINIMAL"
```
### Model Files Location
- **LSTM Model**: `ml nasa/models/climate_lstm_model.keras` (3.79 MB)
- **Feature Scaler**: `ml nasa/models/lstm_scaler.pkl`
- **Model Metadata**: `ml nasa/models/lstm_model_metadata.json`
- **Model Configuration**: `ml nasa/data/model_configuration.json`
## ๐ Project Structure
```
AtmoPredict/
โ
โโโ ๐ README.md # This file
โโโ ๐ ARCHITECTURE.md # Detailed system architecture
โโโ ๐ requirements.txt # Python dependencies
โโโ ๐ config.yaml # Configuration file
โโโ ๐ .gitignore # Git ignore rules
โ
โโโ ๐ INSTALL_FIRST.bat # Installation script
โโโ ๐ START_COMPLETE_SYSTEM.bat # Start entire system
โโโ ๐ START_HYBRID_API.bat # Start backend only
โ
โโโ ๐ src/ # Backend source code
โ โโโ __init__.py
โ โโโ api.py # Main FastAPI application (LSTM integrated)
โ โโโ lstm_model_loader.py # LSTM model loader and predictor
โ โโโ data_collection.py # NASA API data fetching
โ โโโ feature_engineering.py # Feature creation
โ โโโ data_router.py # Location data routing
โ โโโ climate_service.py # Climate information service
โ
โโโ ๐ Frontend_nasa/ # React frontend
โ โโโ package.json # Node dependencies
โ โโโ vite.config.js # Vite configuration
โ โโโ tailwind.config.js # Tailwind CSS config
โ โโโ index.html # Entry HTML
โ โโโ src/
โ โ โโโ App.jsx # Main React component
โ โ โโโ components/ # React components
โ โ โ โโโ WeatherMap.jsx # Map component
โ โ โ โโโ CurrentWeather.jsx # Current weather display
โ โ โ โโโ ForecastMini.jsx # Forecast cards
โ โ โ โโโ ModelResponse.jsx # ML predictions display
โ โ โโโ services/ # API services
โ โ โ โโโ weatherApi.js # Backend API calls
โ โ โ โโโ weatherDataManager.js # Data management
โ โ โโโ utils/
โ โ โโโ constants.js # Configuration constants
โ โโโ public/ # Static assets
โ
โโโ ๐ ml nasa/ # LSTM Model & Training Pipeline
โ โโโ local_inference.py # Run LSTM predictions locally
โ โโโ main_pipeline.py # Data collection pipeline
โ โโโ cleaning_pipeline.py # Data cleaning workflow
โ โโโ test_project.py # Comprehensive tests
โ โโโ models/ # Trained models
โ โ โโโ climate_lstm_model.keras # ๐ค Main LSTM model (3.79 MB)
โ โ โโโ lstm_scaler.pkl # Feature scaler
โ โ โโโ lstm_model_metadata.json # Performance metrics
โ โ โโโ lstm_training_history.pkl # Training logs
โ โโโ data/ # Training data
โ โ โโโ climate_model_ready_transformed.csv
โ โ โโโ model_configuration.json # Feature configuration
โ โ โโโ locations_major_cities.csv
โ โโโ src/ # Pipeline modules
โ โโโ location_grid.py
โ โโโ data_fetcher.py
โ โโโ data_processor.py
โ
โโโ ๐ data/ # Climate pattern data
โ โโโ location_mapping.json # Location metadata
โ โโโ continents/ # Continental climate data
โ โ โโโ asia.json
โ โ โโโ europe.json
โ โ โโโ north_america.json
โ โ โโโ south_america.json
โ โ โโโ africa.json
โ โ โโโ australia.json
โ โ โโโ antarctica.json
โ โโโ hemispheres/ # Hemisphere climate data
โ โโโ northern_hemisphere.json
โ โโโ southern_hemisphere.json
โ
โโโ ๐ FloatChatMap/ # Additional dashboard tools
โโโ ... # Climate visualization tools
```
## ๐ LSTM Model Information
The LSTM model is **pre-trained** on NASA POWER climate data (2010-2024). The model files are located in `ml nasa/models/`:
- **Model File**: `climate_lstm_model.keras` (3.79 MB)
- **Scaler**: `lstm_scaler.pkl`
- **Metadata**: `lstm_model_metadata.json`
- **Configuration**: `../data/model_configuration.json`
### Running Local Inference
To test the LSTM model independently:
```bash
cd "ml nasa"
python local_inference.py
```
This generates predictions for all samples and creates visualizations in `ml nasa/results/`.
### Model Training (Advanced)
The model was trained using Google Colab with the data collection pipeline. To retrain (advanced users):
```bash
cd "ml nasa"
# 1. Collect new data
python main_pipeline.py --grid cities --start 2010 --end 2024
# 2. Clean and process data
python cleaning_pipeline.py
# 3. Train model (requires Google Colab or local GPU)
# See ml nasa/README.md for detailed training instructions
```
## ๐งช Testing
### Test Backend Connection
```bash
TEST_BACKEND_CONNECTION.bat
# Or manually
python test_backend_api.py
```
### Test Hybrid Forecast
```bash
TEST_HYBRID_FORECAST.bat
# Or manually
python test_hybrid_forecast.py
```
## ๐ Key Features Explained
### 1. Multi-Location Support
The system uses a data router to map any latitude/longitude to the nearest trained location, ensuring predictions work globally.
### 2. Real-time Weather Integration
Current weather conditions are fetched from external APIs and displayed alongside ML predictions.
### 3. Climate-Aware Predictions
The system considers continental and hemispheric climate patterns to adjust predictions.
### 4. Interactive Visualization
- Leaflet maps for location selection
- Plotly charts for trend visualization
- Progress bars for probability display
- Color-coded risk levels
### 5. Responsive Design
The interface adapts to different screen sizes, from mobile phones to desktop monitors.
## ๐ฎ Future Enhancements
- [ ] Enhanced LSTM model with attention mechanisms
- [ ] Multi-timestep predictions (sequence forecasting)
- [ ] Real-time NASA data integration
- [ ] Extended forecast range (14+ days)
- [ ] Ensemble model combining LSTM with traditional ML
- [ ] Historical trend comparison and visualization
- [ ] Email/SMS alerts for extreme conditions
- [ ] Mobile app (React Native)
- [ ] User accounts and saved locations
- [ ] Integration with more weather data sources (ERA5, MERRA-2)
- [ ] Multi-language support
- [ ] Export reports as PDF
- [ ] Model explainability (SHAP, LIME)
- [ ] Transfer learning for regional models
## ๐ค Contributing
Contributions are welcome! Please follow these steps:
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## ๐ Acknowledgments
- **NASA POWER** - For providing free access to global weather data
- **FastAPI** - For the excellent async web framework
- **React Team** - For the powerful UI library
- **scikit-learn, XGBoost, LightGBM** - For robust ML algorithms
- **Leaflet** - For beautiful interactive maps
## ๐ง Contact
For questions, suggestions, or collaboration:
- **GitHub**: [@namanxdev](https://github.com/namanxdev)
- **Repository**: [AtmoPredict](https://github.com/namanxdev/AtmoPredict)
## ๐ NASA Space Apps Challenge
This project was developed for the NASA Space Apps Challenge 2025. It demonstrates the practical application of machine learning for climate science and extreme weather prediction using NASA's open data.
---
**Made with โค๏ธ for better weather prediction**
๐ Predicting tomorrow's weather, today ๐ค๏ธ