Version: 1.0.0
Date: January 2024
Status: MVP (Minimum Viable Product)
License: MIT License
The AI Climate Advisory System is an innovative technology solution designed to empower Tanzanian smallholder farmers with free, accessible, and actionable climate information. The system delivers personalized, crop-specific farming advice directly to farmers' mobile phones via SMS in Swahili, helping them make better decisions about planting, irrigation, and crop protection.
For Farmers:
- Receive timely weather forecasts and farming advice
- Reduce crop losses from weather-related risks
- Improve crop yields through better decision-making
- Access information in Swahili on basic mobile phones
For Government & Donors:
- Scalable solution using free data sources
- Low operational costs
- Transparent, open-source implementation
- Measurable impact on food security
To empower Tanzanian farmers with free, accessible, and actionable climate information that helps them make better farming decisions and improve food security.
A future where every farmer in Tanzania has access to personalized, crop-specific climate advice delivered directly to their mobile phone in their own language.
1. System collects weather data from satellites daily
↓
2. AI analyzes data and predicts weather for next 14 days
↓
3. System checks farmer's crop type and growth stage
↓
4. System generates personalized advice based on:
- Weather forecast
- Crop needs
- Risk assessment
↓
5. Advice sent to farmer's phone via SMS in Swahili
Swahili:
Habari! Hali ya mvua kwa Mahindi:
Mwagilia mazao yako mara mbili kwa wiki. Angalia udongo
ukiwa na unyevu wa kutosha.
Kuna hatari ya ukame. Uhakika: Juu.
English Translation:
Hello! Rainfall conditions for Maize:
Water your crops twice per week. Ensure soil has adequate
moisture.
Dry spell risk detected. Confidence: High.
┌─────────────────────────────────────────────────────────────┐
│ DATA SOURCES │
│ CHIRPS │ ERA5 │ MODIS │ FAO │
└─────────┴──────┴───────┴────────────────────────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────────────────────────────┐
│ DATA INGESTION LAYER │
│ • Scheduled pipelines (daily/weekly) │
│ • District-level extraction │
│ • Local caching │
└──────────────────────┬───────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ FEATURE ENGINEERING LAYER │
│ • Rainfall totals (7d, 14d, 30d) │
│ • Rainfall anomalies │
│ • NDVI trends │
│ • Soil moisture proxy │
│ • Risk indicators │
└──────────────────────┬───────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ AI/ML LAYER │
│ • Rainfall forecasting (Prophet/Linear Regression) │
│ • Risk classification (Random Forest) │
│ • Dry spell detection │
│ • Flood risk assessment │
└──────────────────────┬───────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ DECISION ENGINE │
│ • Crop-specific rules │
│ • Growth stage awareness │
│ • Risk-based action generation │
│ • Swahili message generation │
└──────────────────────┬───────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ ADVISORY DELIVERY LAYER │
│ • SMS (Twilio/Africa's Talking) │
│ • WhatsApp (optional) │
│ • REST API │
└──────────────────────┬───────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ FARMERS │
│ Mobile Phones (SMS/WhatsApp) │
└─────────────────────────────────────────────────────────────┘
Purpose: Fetch and cache climate and satellite data from free sources
Components:
- CHIRPSIngester: Daily rainfall data for Africa
- ERA5Ingester: Temperature and weather variables from Copernicus
- MODISIngester: NDVI and land surface temperature
- FAOIngester: Crop calendars and historical yield data
Features:
- Local caching for reliability
- District-level data extraction
- Scheduled daily/weekly updates
- Graceful error handling
Purpose: Transform raw climate data into meaningful features
Features Calculated:
- Rainfall Totals: 7-day, 14-day, 30-day rolling sums
- Rainfall Anomaly: Percentage deviation from historical mean
- NDVI Trend: Rate of change in vegetation index
- Soil Moisture Proxy: Rainfall minus evapotranspiration
- Dry Spell Indicators: Consecutive dry days, risk probability
- Flood Risk Indicators: Excess rainfall, consecutive wet days
Purpose: Generate forecasts and classify risks
Models:
- RainfallForecaster: Time-series forecasting using Prophet or simple linear regression
- Forecasts 14 days ahead
- Handles seasonal patterns
- Provides confidence intervals
Purpose: Convert predictions into actionable farming advice
Logic:
- Crop-specific rules based on growth stages
- Risk assessment (dry spell, flood, vegetation stress)
- Action generation (planting, irrigation, drainage, etc.)
- Swahili and English message generation
Purpose: Deliver advisories via multiple channels
Channels:
- SMS: Primary delivery method (Twilio or Africa's Talking)
- WhatsApp: Optional delivery method
- REST API: JSON output for web/mobile apps
Features:
- Swahili-first communication
- Message length optimization (160 chars for SMS)
- Delivery status tracking
POST /api/v1/advisory - Generate advisory for a farmerGET /api/v1/advisory/{farmer_id} - Get latest advisoryPOST /api/v1/advisory/batch - Generate batch advisoriesGET /api/v1/data/latest - Get latest climate dataPOST /api/v1/data/ingest/{district_id} - Ingest data for districtPOST /api/v1/farmers - Register farmerGET /api/v1/farmers/{farmer_id} - Get farmer infoPOST /api/v1/districts - Add districtGET /api/v1/districts - List districtsTell them your district
Receive Confirmation
Messages come in Swahili
Read the Advice
Shows confidence level
Take Action
Scenario 1: Good Planting Time
Message: "Hali ya mvua ni nzuri. Unaweza kuanza kupanda mazao yako."
Action: Start planting your crops
Scenario 2: Dry Spell Warning
Message: "Kuna hatari ya ukame. Mwagilia mazao yako mara mbili kwa wiki."
Action: Water your crops twice per week
Scenario 3: Flood Warning
Message: "Mvua nyingi inatarajiwa. Fanya mifereji ya maji."
Action: Create drainage channels
Planting date (if known)
Use API or Web Interface
POST /api/v1/farmersOr use web interface (if available)
Confirm Registration
# Navigate to project directory
cd CWMS
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Linux/Mac:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Copy example configuration
cp config/config.example.yaml config/config.yaml
# Edit config/config.yaml with your settings
# - Database URL
# - SMS provider credentials
# - Data source credentials (if using real APIs)
# Create database tables
python scripts/setup_db.py
# Ingest climate data for all districts
python scripts/ingest_chirps.py
python scripts/ingest_era5.py
python scripts/ingest_modis.py
# Development mode
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
# Production mode
uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 4
# Build and start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down
# Build image
docker build -t climate-advisory .
# Run container
docker run -p 8000:8000 climate-advisory
# Start scheduler service
python scripts/scheduler.py
Add to crontab:
# Daily CHIRPS ingestion at 6 AM
0 6 * * * cd /path/to/CWMS && python scripts/ingest_chirps.py
# Daily ERA5 ingestion at 7 AM
0 7 * * * cd /path/to/CWMS && python scripts/ingest_era5.py
# Weekly MODIS ingestion on Sunday at 8 AM
0 8 * * 0 cd /path/to/CWMS && python scripts/ingest_modis.py
# Daily advisory generation at 10 AM
0 10 * * * cd /path/to/CWMS && python scripts/generate_advisories.py
config/config.yaml:sms:
provider: "twilio"
twilio:
account_sid: "your_account_sid"
auth_token: "your_auth_token"
from_number: "+1234567890"
config/config.yaml:sms:
provider: "africas_talking"
africas_talking:
api_key: "your_api_key"
username: "your_username"
from_number: "CLIMATE"
CHIRPS: Climate Hazards Group InfraRed Precipitation with Station data - Daily rainfall dataset for Africa
ERA5: Fifth generation ECMWF reanalysis - Global climate dataset from Copernicus
MODIS: Moderate Resolution Imaging Spectroradiometer - NASA satellite sensor for vegetation monitoring
NDVI: Normalized Difference Vegetation Index - Measure of vegetation health (0-1 scale)
Dry Spell: Period of consecutive days with little or no rainfall
Masika: Long rainy season in Tanzania (March-May)
Vuli: Short rainy season in Tanzania (October-December)
MVP: Minimum Viable Product - Initial working version of the system
pip install cdsapi~/.cdsapircSee docs/API.md for complete API documentation.
See docs/ARCHITECTURE.md for detailed system architecture.
See docs/DEPLOYMENT.md for production deployment instructions.
QUICKSTART.mdPROJECT_STATEMENT.mdHOW_IT_WORKS.mdABOUT.mddocs/ARCHITECTURE.mddocs/API.mddocs/DEPLOYMENT.mdDocument Version: 1.0.0
Last Updated: January 2024
Status: MVP Ready for Evaluation
This project is designed to be evaluated by government institutions and international donors, with the goal of scaling to support all Tanzanian farmers.