-
-
Irrigation Advisor
-
-
WAIT: on 1 Jan 2025 in Amritsar, soil should stay wet for the next 3 days, so no irrigation is needed.
-
IRRIGATE: on 19 Feb 2025, soil is expected to get too dry within 3 days, so the advisor says to water now.
-
Tested on unseen years: at every safety level, the AI advisor skips more irrigations than just checking today's soil.
-
Muktsar, wheat 2024-25: a fixed calendar irrigates 8 times. The advisor says WAIT on 7 of them (green marks).
-
The AI's 3-day-ahead soil moisture prediction (green) closely follows what really happened (black) across a full wheat season.
Inspiration
Punjab grows food for the country, and it is draining the ground beneath it. Groundwater extraction is at 156% of what recharges each year, 111 of 153 assessment units are over-exploited, and about 95% of the water pumped goes to irrigation through roughly 1.45 million tubewells. The water table keeps falling, and every pump that runs when the soil doesn't need it pulls from an aquifer that isn't refilling.
What struck me is how much of this pumping is decided by habit: a fixed calendar says "irrigate every 20 days," so the field gets water whether the soil is already wet or not. I wanted to build something that answers one simple question a farmer actually has: should I irrigate today, or can I wait?
What it does
Punjab Irrigation Advisor is a web app that gives wheat farmers a clear WAIT or IRRIGATE answer for the next 3 days. You pick your district, a date and a safety level, and it shows:
- today's soil moisture, the moisture expected in 3 days, and that district's "too dry" limit
- a big WAIT or IRRIGATE banner with the reason in plain words
- a chart explaining why it gave that answer
- how many calendar irrigations could have been skipped over the season
The safety level lets the user choose their own risk, from Save more water to Maximum safety. Someone who can't afford a dry spell can pick the safe end. Someone who wants to conserve can pick the other.
It's built for wheat farmers deciding when to run their pumps, and for district officers or agriculture advisors who want to cut groundwater use without asking farmers to take blind risks. The aim is simple: less water pumped, with crops still safe.
How I built it
- Data: daily weather and soil moisture for all 23 Punjab districts, 2015-2025, from the Open-Meteo historical API (ERA5/ERA5-Land). I dropped an early synthetic dataset and built everything on this real data.
- Prediction: an XGBoost model predicts how top-soil moisture (0-7 cm) will change over the next 3 days, using only information available today: soil moisture and its trends at several depths, recent rain, evaporation, temperature, days since sowing and time of year. It was tuned with Optuna and split by time (train up to 2022, safety level chosen on 2023, tested on 2024-25).
- Decision: each district gets a "too dry" limit, the 25th percentile of its historical wheat-season moisture. With safety margin $\delta$, the rule is:
$$\text{WAIT if } \hat{m}_{t+3} \ge \theta_d + \delta, \quad \text{otherwise IRRIGATE}$$
where $\hat{m}_{t+3}$ is the predicted moisture in 3 days and $\theta_d$ is the dry limit for district $d$. A bigger $\delta$ means the advisor irrigates earlier and misses fewer needed irrigations.
- Explanation: SHAP turns the model's reasoning into a simple waterfall chart. Red bars push soil moisture up (favouring WAIT), blue bars push it down (favouring IRRIGATE), and longer bars matter more.
- App: a Streamlit app with Advisor, Results and About pages, deployed on Streamlit Cloud, with the code, model and results in an open GitHub repo.
Challenges I ran into
- Tuning the model. I tuned XGBoost with Optuna (40 trials) using expanding-year validation on 2019-2022, so no test data leaked into the search. The search ran on the 1-day task, and I reused its best settings for the 3-day model, so the headline results come from a model that wasn't separately tuned for 3 days.
- The first model barely beat the baseline. My 1-day model predicted soil moisture about 15% better than "nothing changes," but when I turned predictions into irrigate/wait decisions, it did about the same as simply looking at today's soil. I changed the approach in two ways: I moved to a 3-day horizon with extra lag features, where early warning matters more, and I rebuilt the comparison so both rules get a tuned safety margin. That gave a result I could trust.
- Resisting a shortcut. A perfect rain forecast made the model look much better (24% error reduction at 1 day), but a farmer can't get a perfect forecast. I left it out and kept the advisor past-data-only.
- Making it readable. The first deployed version was nearly unreadable in browser dark mode, so I redesigned the interface for contrast and plain language.
Accomplishments that we're proud of
- It beats a fair baseline, at every safety level. I tested on two years the model never saw (2024-25) and compared it with the obvious alternative: just checking today's soil. Both rules got a safety margin chosen on a separate year. The AI skips more irrigations at the same safety, and the gap grows as safety increases. At about 8% of needed irrigations missed, it skips 57% of scheduled irrigations versus 51% for the simple rule. At the balanced setting it skips 65% of calendar irrigations while missing 15.6% of the ones crops needed.
- It looks ahead. Predicting 3 days out reduces error by 8.8% compared with assuming "soil stays the same," and the prediction follows real wet spells and dry stretches.
- It never uses a rain forecast. The advisor works from past data only, so what I tested is what a farmer could get today.
- It explains itself. Every answer comes with a plain-language chart, so the farmer or district officer can see why, not just what.
- It's live and open. The app is deployed, and the code, model and results are public.
What I learned
- A model that scores better isn't automatically a better decision tool. What matters is how it performs on the decision, against a fair baseline.
- Tuning the safety trade-off honestly (on one year, reported on another) is what makes the results believable.
- Explanations matter as much as accuracy. People trust advice they can read.
- Good design is part of the model's impact: advice nobody can read doesn't save water.
What's next for Punjab Irrigation Advisor
- Connect the live Open-Meteo forecast feed so the advisor gives advice for today and uses upcoming rain.
- Extend from wheat to paddy, where the biggest water savings are.
- Turn skipped irrigations into estimated litres and energy saved per district.
- Deliver the daily WAIT/IRRIGATE answer to farmers by phone message.
Built With
- era5-land
- explainable-ai
- github
- jupyter-notebook
- kaggle
- machine-learning
- matplotlib
- numpy
- open-meteo
- optuna
- pandas
- python
- scikit-learn
- shap
- streamlit
- streamlit-cloud
- xgboost