Which agricultural regions are experiencing vegetation stress?
A Flask API runs Google Earth Engine (GEE) analysis. A static dashboard (Leaflet map, Chart.js charts) shows the results.
Browser (frontend) --fetch--> Flask API (backend) --ee.*--> Google Earth Engine
map, KPIs, charts gee_processor.py Sentinel-2, MODIS, CHIRPS,
WorldCover, your District_Boundary
agrowatch-dashboard/
├── gee/AgroWatch.js Code Editor version of the same analysis (already working for you)
├── frontend/
│ ├── index.html layout: top nav, filter bar, map, KPI cards, side panels, charts
│ ├── css/style.css dark control-room theme, responsive
│ ├── js/main.js API calls, KPI cards, insights, wiring
│ ├── js/map.js Leaflet: basemaps, GEE tiles, district outlines, legend
│ ├── js/charts.js sparklines, trend, VCI bars, rainfall, donut, risk gauge
│ ├── js/filters.js region/district/year/season filters, layer tabs
│ └── assets/favicon.svg
├── backend/
│ ├── app.py routes, validation, errors
│ ├── gee_processor.py all Earth Engine logic + rule-based insights
│ ├── authentication.py GEE login (service account) + optional dashboard login
│ ├── requirements.txt
│ └── .env.example
└── README.md
| Area | Content |
|---|---|
| Map tabs | Stress classes, Sentinel-2 NDVI and EVI, MODIS NDVI, NDVI anomaly, VCI, rainfall, rainfall % of normal |
| KPI cards | Cropland area, mean NDVI (with sparkline), crop health index (VCI), season rainfall, % cropland under stress |
| Risk gauge and insights | Low / Moderate / High / Severe drought risk, plus plain-language alerts |
| Charts | NDVI and EVI by season since 2001, VCI by season, monthly rainfall vs normal, stress class share |
| Filters | Region, district (or click a district on the map), season year, Kharif or Rabi, cropland-only mask |
How the numbers work:
build_insights): Severe if 40% or more cropland is stressed or mean VCI is below 20; High at 25% or VCI below 35; Moderate at 10% or VCI below 50; otherwise Low. Edit the numbers to suit you.GEE_PROJECT.District_Boundary with the service account email (Reader). Without this, the backend cannot read your districts.PROVINCE_FIELD and DISTRICT_FIELD in .env.frontend/ folder separately (Netlify, GitHub Pages, your own site), set window.AGROWATCH_API_BASE in index.html to the backend URL.ALLOWED_ORIGINS.AUTH_ENABLED=true, a long JWT_SECRET, DASH_USER and DASH_PASS_HASH.The backend also serves the dashboard, so there is one terminal and one address.
cd backend
python -m venv venv
venv\Scripts\activate # macOS/Linux: source venv/bin/activate
pip install -r requirements.txt
earthengine authenticate # one time: sign in with the Google account that owns the asset
python app.py
Open http://localhost:5000.
backend/.env is already filled in with your project (semiotic-timer-429307-g6) and asset path. Change it only if you use a different project.
The first load of a province can take 30 to 90 seconds because Earth Engine computes statistics over 25 seasons. Results are cached for 6 hours, so repeats are fast. Pick a single district for quicker results.
| Endpoint | Params | Returns |
|---|---|---|
GET /api/meta |
- | provinces, years, seasons, layer list, classes |
GET /api/districts |
province |
district names |
GET /api/boundary |
province, district |
simplified GeoJSON outline |
GET /api/tiles |
layer, province, district, year, season, crop |
map tile URL, legend info |
GET /api/stats |
province, district, year, season |
cropland area, class areas, mean indices |
GET /api/series |
same | NDVI, EVI, VCI, rainfall per season since 2001 |
GET /api/rainfall |
province, district, year |
monthly rainfall vs normal |
GET /api/insights |
province, district, year, season |
risk level, alerts |
GET /api/sources |
- | latest image date per source |
POST /api/login |
username, password |
token (when auth is enabled) |
LAYERS and _vis in gee_processor.py, and an image in _analysis. A tab appears automatically.BASE_START and BASE_END in gee_processor.py (also in gee/AgroWatch.js).style.css.| Symptom | Fix |
|---|---|
| “Cannot reach the backend” | Backend not running, wrong AGROWATCH_API_BASE, or CORS origin missing |
| “No district-name column found” | Set DISTRICT_FIELD in .env to the exact column name |
| Asset not found or access denied | Share the asset with the service account (step 3) |
| Request times out | Pick one district, shorten the wait, raise gunicorn --timeout |
| Rainfall looks too low for the newest season | The season is not finished; CHIRPS and MODIS lag a few weeks |
| Blank page | Open http://localhost:5000, not the HTML file directly |