Lesson 4 · 13:30–15:00
When should we warn?
Satellites can't see tomorrow, so the alert uses air temperature (2 m above the ground):
will tomorrow's forecast high cross Bengaluru's heat gauge?
First, each day's highest (tmax) and lowest (tmin) air temperature since 1991 from ERA5, Europe's hour-by-hour
rebuild of past weather on ~25 km squares (it reads about 1.5 °C below the city's weather station on summer afternoons).
See it, get it. Climate Pulse maps ERA5 for the whole world, day by day, and
Open-Meteo gives any place's daily values as a CSV, which is what
we download for Bengaluru (35 years in 0.2 MB):era5 = datapack.table("era5_daily") # each day's highest and lowest air temperature (ERA5, via Open-Meteo), °C
era5[["tmax", "tmin"]].tail()
| tmax | tmin | |
|---|---|---|
| time | ||
| 2026-09-26 | 29.8 | 20.7 |
| 2026-09-27 | 30.7 | 19.4 |
| 2026-09-28 | 30 | 21.8 |
| 2026-09-29 | 28.8 | 21.9 |
| 2026-09-30 | 29.1 | 21.5 |
How this file was made · making it reads 35 years of daily ERA5 from Open-Meteo, a few seconds
The chart reads a small prepared file (0.2 MB): your copy in data/ if you have one, otherwise it downloads once. To make it yourself from the original data, run uv run wardheat datapack build --step climate --force. This is the code that runs:
def era5_daily(start: str = "1991-01-01", end: str = "2025-12-31", point=CITY_POINT, model: str = "era5") -> pd.DataFrame: """Daily ERA5 history for one point (°C, %).""" r = requests.get( "https://archive-api.open-meteo.com/v1/archive", params=dict(latitude=point[0], longitude=point[1], start_date=start, end_date=end, daily=",".join(DAILY_VARS), timezone="Asia/Kolkata", models=model), timeout=120, ) r.raise_for_status() return _to_frame(r.json()) def step_climate(force=False): from . import climate if datapack.exists("era5_daily") and not force: return d = climate.era5_daily("1991-01-01", "2026-09-30") d.to_parquet(_out("era5_daily")) _log(f"climate: {len(d)} days of ERA5")
40 °C never comes
In 35 years no day in Bengaluru reached 40 °C, so India's 40 °C rule would never warn the city. So we use one Bengaluru gauge for every day of the year: a forecast high from 33 °C is warm, 34 °C hot, 35 °C very hot and 36 °C extreme; 33 °C is hotter than 9 in 10 days of 1991–2020, and each level is one degree more:normal = warning.climatology(era5, base=(1991, 2020)) # the average high for every date, 1991-2020
# a level for every day since 1991, from its highest air temperature
levels = warning.levels(era5.loc["1991":], lines=(33, 34, 35, 36))
Here is 23 April 2026, this year's hottest day, on the gauge:
Every March–May since 1991 on the same gauge:
2024 had the longest run of very hot or extreme days (16 in a row). Hot-or-worse days each
March–May: 12.9 a year on average in 1991–2000, 18.2 in 2011–2020.
Tomorrow's forecast
Open-Meteo's free forecast gives the coming days' highest air temperature, read straight off the gauge:forecast = climate.forecast(days=7) # today and the next 6 days, as Open-Meteo gives them
week = warning.levels(forecast, lines=(33, 34, 35, 36), normal=normal)
week[["tmax", "tmax_normal", "in words"]].round(1).rename(columns={
"tmax": "high °C", "tmax_normal": "average high for the date °C", "in words": "level"})
| high °C | average high for the date °C | level | |
|---|---|---|---|
| time | |||
| 2026-10-14 | 31.7 | 27 | below the alert line |
| 2026-10-15 | 29.5 | 27 | below the alert line |
| 2026-10-16 | 26.1 | 27 | below the alert line |
| 2026-10-17 | 26.9 | 26.9 | below the alert line |
| 2026-10-18 | 27.3 | 26.9 | below the alert line |
| 2026-10-19 | 25.7 | 26.9 | below the alert line |
| 2026-10-20 | 26.4 | 26.9 | below the alert line |
369 ward alerts
Each ward's alert combines the city's level with the ward's risk class from lesson 3:| Tomorrow's high is… | below 33 °C | 33 °C+ warm | 34 °C+ hot | 35 °C+ very hot | 36 °C+ extreme |
|---|---|---|---|---|---|
| High-risk ward | – | take care | heat alert | emergency | emergency |
| Medium-risk ward | – | take care | take care | heat alert | emergency |
| Low-risk ward | – | – | take care | heat alert | emergency |
wards_risk = indices.ward_risk(indices.ward_table())["risk"] # High / Medium / Low, as in lesson 3
tomorrow = week.iloc[1] # row 0 is today
this_year = era5.loc[str(era5.index[-1].year), "tmax"]
hot_day = levels.loc[this_year.idxmax()] # the example above: this year's hottest day (ERA5)
alerts = pd.DataFrame({
"tomorrow": warning.ward_alerts(int(tomorrow.level), wards_risk),
"hot_day": warning.ward_alerts(int(hot_day.level), wards_risk),
})
alerts.apply(lambda alert: alert.value_counts()).fillna(0).astype(int) # how many wards get each alert
| tomorrow | hot_day | |
|---|---|---|
| Emergency | 0 | 111 |
| Heat alert | 0 | 258 |
| No alert | 369 | 0 |
Sending the alerts
Every warned ward gets a message for its officers and residents; when tomorrow has no alerts, the cell shows what this year's hottest day would have sent:day, when = ("tomorrow", tomorrow) if (alerts.tomorrow != "No alert").any() else ("hot_day", hot_day)
advice = {
"Take care": "drink water often and stay out of the sun from 12 noon to 3 pm.",
"Heat alert": "stay out of the sun from 12 noon to 3 pm, drink water and ORS, check on older neighbours and outdoor workers.",
"Emergency": "stay indoors from 12 noon to 3 pm, drink water and ORS, call 108 for anyone who collapses in the heat.",
}
send = alerts.loc[alerts[day] != "No alert", [day]].rename(columns={day: "alert"})
send.insert(0, "ward", load_wards().set_index("ward_uid")["label"])
send["message"] = send.alert.map(lambda a: f"{a} for {when.name:%d %B}: {when.tmax:.0f} °C air temperature; " + advice[a])
send.sort_values(["alert", "ward"]).head(10)
| ward | alert | message | |
|---|---|---|---|
| ward_uid | |||
| 26 | Central 26 · Vannarpet | Emergency | Emergency for 23 April: 35 °C air temperature; stay indoors from 12 noon to 3 pm, drink water and ORS, call 108 for anyone who collapses in the heat. |
| 27 | Central 27 · Ambedkarnagar | Emergency | Emergency for 23 April: 35 °C air temperature; stay indoors from 12 noon to 3 pm, drink water and ORS, call 108 for anyone who collapses in the heat. |
| 28 | Central 28 · Neelasandra | Emergency | Emergency for 23 April: 35 °C air temperature; stay indoors from 12 noon to 3 pm, drink water and ORS, call 108 for anyone who collapses in the heat. |
| 32 | Central 32 · SilverJubilee Park Ward | Emergency | Emergency for 23 April: 35 °C air temperature; stay indoors from 12 noon to 3 pm, drink water and ORS, call 108 for anyone who collapses in the heat. |
| 34 | Central 34 · D.V Gundappa Ward | Emergency | Emergency for 23 April: 35 °C air temperature; stay indoors from 12 noon to 3 pm, drink water and ORS, call 108 for anyone who collapses in the heat. |
| 39 | Central 39 · Venkat Reddy Nagara | Emergency | Emergency for 23 April: 35 °C air temperature; stay indoors from 12 noon to 3 pm, drink water and ORS, call 108 for anyone who collapses in the heat. |
| 45 | Central 45 · K.R Market | Emergency | Emergency for 23 April: 35 °C air temperature; stay indoors from 12 noon to 3 pm, drink water and ORS, call 108 for anyone who collapses in the heat. |
| 46 | Central 46 · Cheluvadi Palya | Emergency | Emergency for 23 April: 35 °C air temperature; stay indoors from 12 noon to 3 pm, drink water and ORS, call 108 for anyone who collapses in the heat. |
| 48 | Central 48 · Azad Nagar | Emergency | Emergency for 23 April: 35 °C air temperature; stay indoors from 12 noon to 3 pm, drink water and ORS, call 108 for anyone who collapses in the heat. |
| 49 | Central 49 · Kasturbha Nagar | Emergency | Emergency for 23 April: 35 °C air temperature; stay indoors from 12 noon to 3 pm, drink water and ORS, call 108 for anyone who collapses in the heat. |
369 messages in all: 258 Heat alert, 111 Emergency.
The same idea, live
The US weather service runs this every day: its HeatRisk map colours the whole country green to magenta for the next 7 days by comparing the forecast with local records, and heat.gov tells people what to do.Try it
- Click 2016 and 2019 in the calendar.
- Move the gauge one degree up:
higher = warning.levels(era5.loc["1991":], lines=(34, 35, 36, 37)) # change the lines here
_hot = lambda lv: (lv["level"] >= 2).groupby(lv.index.year).sum()
pd.DataFrame({"33/34/35/36": _hot(levels), "34/35/36/37": _hot(higher)}).loc[2010:].rename_axis("hot or worse days")
| 33/34/35/36 | 34/35/36/37 | |
|---|---|---|
| hot or worse days | ||
| 2010 | 20 | 4 |
| 2011 | 0 | 0 |
| 2012 | 18 | 1 |
| 2013 | 23 | 2 |
| 2014 | 35 | 18 |
| 2015 | 11 | 0 |
| 2016 | 34 | 23 |
| 2017 | 29 | 1 |
| 2018 | 3 | 0 |
| 2019 | 22 | 2 |
| 2020 | 7 | 1 |
| 2021 | 2 | 1 |
| 2022 | 3 | 1 |
| 2023 | 8 | 0 |
| 2024 | 37 | 26 |
| 2025 | 1 | 0 |
| 2026 | 17 | 2 |
Next steps: set the gauge from hospital records, add humidity, warm nights and hot spells, and street sensors. Thank you!