Skip to content

Nitesh-debug/jk_disaster_response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿšจ AI-Powered Disaster Response & Resource Allocation System

For Jammu & Kashmir

A comprehensive disaster management system that uses machine learning to predict flood risks and optimize resource allocation in real-time.


๐ŸŽฏ Features

๐Ÿ“Š Live Weather Monitoring

  • Fetches real-time rainfall data from India Meteorological Department (IMD)
  • Integrates with Meteomatics API and OpenWeatherMap for comprehensive weather data
  • Monitors temperature, humidity, wind speed, and precipitation
  • Parses IMD weather warnings and alerts

๐Ÿค– AI-Powered Risk Prediction

  • Random Forest machine learning model trained on historical weather data
  • Predicts flood risk scores (0-100) for each district
  • Classifies risk levels: Low, Medium, High, Critical
  • Feature importance analysis for rainfall, temperature, and humidity

๐Ÿ“ Real-Time Dashboard

  • Interactive Streamlit web interface
  • Top 5 affected districts visualization
  • Live rainfall bar charts and graphs
  • Color-coded alert level map (๐ŸŸข๐ŸŸก๐ŸŸ ๐Ÿ”ด)
  • 3-day rainfall forecast with confidence scores
  • District-wise risk score distribution

๐Ÿš Intelligent Resource Allocation

  • Optimally distributes rescue teams, medical units, and shelters
  • Priority-based allocation considering risk scores and population
  • Real-time resource utilization tracking
  • Exportable allocation reports

๐Ÿ’พ Data Management

  • SQLite database for structured data storage
  • CSV exports for all data (rainfall, warnings, forecasts, allocations)
  • Historical data tracking and analysis
  • Automated data refresh with timestamps

๐Ÿ“ Project Structure

/project
โ”œโ”€โ”€ data/                        # Data storage directory
โ”‚   โ”œโ”€โ”€ disaster_response.db     # SQLite database
โ”‚   โ”œโ”€โ”€ rainfall.csv             # Current rainfall data
โ”‚   โ”œโ”€โ”€ forecast.csv             # 3-day forecast data
โ”‚   โ”œโ”€โ”€ warnings.csv             # Weather warnings
โ”‚   โ”œโ”€โ”€ resource_allocation.csv  # Resource distribution
โ”‚   โ””โ”€โ”€ visualizations/          # Generated charts
โ”‚
โ”œโ”€โ”€ model/                       # ML models
โ”‚   โ”œโ”€โ”€ train_model.py           # Model training script
โ”‚   โ””โ”€โ”€ risk_predictor.pkl       # Trained model file
โ”‚
โ”œโ”€โ”€ scripts/                     # Core modules
โ”‚   โ”œโ”€โ”€ fetch_imd.py             # IMD data fetcher
โ”‚   โ”œโ”€โ”€ fetch_forecast.py        # Forecast API fetcher
โ”‚   โ”œโ”€โ”€ process_data.py          # Data processing & DB
โ”‚   โ””โ”€โ”€ resource_allocator.py    # Resource optimization
โ”‚
โ”œโ”€โ”€ app.py                       # Streamlit dashboard
โ”œโ”€โ”€ main.py                      # Main orchestrator
โ”œโ”€โ”€ requirements.txt             # Python dependencies
โ””โ”€โ”€ README.md                    # Documentation

๐Ÿš€ Quick Start

1. Installation

All required packages are already installed:

  • pandas, numpy, matplotlib, plotly
  • scikit-learn, requests, beautifulsoup4
  • streamlit, lxml

2. Run the System

Option A: Interactive Dashboard (Recommended)

streamlit run app.py --server.port 5000

The dashboard will open automatically and show:

  • Real-time weather data
  • Risk predictions
  • Resource allocations
  • Interactive charts

Option B: Command-Line Interface

python main.py

This will:

  1. Generate historical training data
  2. Train ML models
  3. Fetch live weather data
  4. Predict risk scores
  5. Allocate resources
  6. Generate reports and visualizations

๐Ÿ”‘ API Configuration (Optional)

For enhanced data accuracy, you can configure API keys:

Meteomatics API

export METEOMATICS_USER="your_username"
export METEOMATICS_PASSWORD="your_password"

OpenWeatherMap API

export OPENWEATHER_API_KEY="your_api_key"

Note: The system works with sample data if API keys are not provided.


๐Ÿ“Š How It Works

Data Flow Pipeline

[ IMD + Meteomatics APIs ]
         โ†“
[ Data Fetch Module ]
         โ†“
[ Data Cleaning + Merge ]
         โ†“
[ ML Prediction Engine ]
         โ†“
[ Risk Scoring + Warning Logic ]
         โ†“
[ Streamlit Dashboard ]
         โ†“
[ Resource Allocation Optimizer ]
         โ†“
[ CSV/SQLite Storage ]

Machine Learning Model

Algorithm: Random Forest (Classification + Regression)

Features:

  • Rainfall (mm in last 24 hours)
  • Temperature (ยฐC)
  • Humidity (%)

Output:

  • Risk Score: 0-100 (continuous)
  • Risk Level: Low / Medium / High / Critical (categorical)

Training Data: 60 days of historical weather patterns


๐ŸŽ›๏ธ Dashboard Features

1. Control Panel

  • Refresh data button
  • Resource configuration (rescue teams, medical units, shelters)
  • Last update timestamp

2. Summary Metrics

  • Total districts monitored
  • Critical risk district count
  • Average rainfall and risk score

3. Visualizations

  • Top 5 Affected Districts: Quick overview with risk scores
  • Rainfall Bar Chart: District-wise rainfall comparison
  • Risk Distribution: Scatter plot of rainfall vs. risk
  • Alert Level Map: Color-coded district grid
  • 3-Day Forecast: Line chart for top risky districts
  • Resource Allocation: Distribution across districts

4. Data Export

  • Download weather data as CSV
  • Download forecast as CSV
  • Download resource allocation as CSV

๐Ÿ“ˆ Sample Output

Console Output (main.py)

================================================================================
  ๐Ÿšจ AI-Powered Disaster Response System for Jammu & Kashmir ๐Ÿšจ
================================================================================

โœ“ All components initialized successfully

โœ“ Models trained successfully
  - Classification Accuracy: 94.50%
  - Regression RMSE: 8.23

Top 5 High-Risk Districts:
--------------------------------------------------------------------------------
district    rainfall_24h  temperature  risk_score  risk_level
Anantnag           142.3         18.5        92.4    Critical
Pulwama            135.7         17.2        89.1    Critical
Kupwara            128.4         16.8        85.7    Critical
Srinagar           112.9         19.3        78.2    High
Baramulla          98.6          20.1        71.5    High

Resource Allocation Summary

Total Districts: 15
Critical Risk Districts: 3
Rescue Teams: 48/50 (96.0%)
Medical Units: 29/30 (96.7%)
Shelters: 38/40 (95.0%)

๐Ÿงช Testing Individual Modules

Test IMD Data Fetcher

python scripts/fetch_imd.py

Test Forecast Fetcher

python scripts/fetch_forecast.py

Test Data Processor

python scripts/process_data.py

Test ML Model

python model/train_model.py

Test Resource Allocator

python scripts/resource_allocator.py

๐Ÿ”ง Customization

Adjust Available Resources

In the dashboard sidebar or in scripts/resource_allocator.py:

allocator.set_available_resources({
    'rescue_teams': 100,
    'medical_units': 60,
    'shelters': 80,
    'food_supplies': 200,
    'water_tankers': 50
})

Add More Districts

Modify the district lists in:

  • scripts/fetch_imd.py
  • scripts/fetch_forecast.py

Modify Risk Thresholds

In model/train_model.py:

risk_score_map = {
    'Low': 25,      # 0-25
    'Medium': 50,   # 25-50
    'High': 75,     # 50-75
    'Critical': 95  # 75-100
}

๐Ÿ“ Data Sources

  1. IMD (India Meteorological Department)

  2. Meteomatics API

    • Temperature, humidity, wind speed
    • Hourly precipitation forecasts
  3. OpenWeatherMap API (Backup)

    • Current weather conditions
    • Alternative data source

๐ŸŽ“ Technical Details

Libraries Used

  • pandas: Data manipulation and analysis
  • numpy: Numerical computations
  • scikit-learn: Machine learning (Random Forest)
  • matplotlib: Static visualizations
  • plotly: Interactive charts
  • streamlit: Web dashboard framework
  • requests: HTTP API calls
  • beautifulsoup4: Web scraping (IMD data)
  • sqlite3: Database management (built-in)

Model Performance

  • Accuracy: ~94% on test data
  • RMSE: ~8 points (on 0-100 scale)
  • Training Time: < 5 seconds
  • Prediction Time: < 1 second for all districts

๐Ÿ›ก๏ธ Error Handling

The system includes robust error handling:

  • API Failures: Falls back to sample data
  • Network Errors: Retries with timeout
  • Missing Data: Fills with reasonable defaults
  • Database Errors: Logs and continues operation

๐Ÿ“ž Support

For issues or questions:

  1. Check console output for error messages
  2. Verify API credentials (if using real APIs)
  3. Ensure all dependencies are installed
  4. Check data/ directory for generated files

๐Ÿ”ฎ Future Enhancements

  • SMS/Email alert notifications
  • GIS mapping with geographical coordinates
  • Historical trend analysis (weeks/months)
  • Mobile app integration
  • Multi-language support
  • Advanced ML models (LSTM, XGBoost)
  • Real-time satellite imagery integration
  • Drone deployment coordination

๐Ÿ“œ License

This project is built for disaster management and public safety purposes.


๐Ÿ™ Acknowledgments

  • India Meteorological Department (IMD) for weather data
  • Jammu & Kashmir government for regional specifications
  • Open-source community for excellent libraries

Built with โค๏ธ for disaster preparedness and community safety


๐Ÿš€ Quick Commands

# Run dashboard
streamlit run app.py --server.port 5000

# Run full pipeline
python main.py

# Test individual components
python scripts/fetch_imd.py
python model/train_model.py
python scripts/resource_allocator.py

Stay Safe, Stay Prepared! ๐Ÿšจ

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages