Blog

GreenTech: how a real-time air quality site for Tashkent is built

5 min read

GreenTech: how a real-time air quality site for Tashkent is built

GreenTech is a site that shows air quality for Tashkent's districts, Uzbekistan's cities and Central Asia. It maps PM2.5, PM10, NO₂, O₃, SO₂ and CO, gives a 72-hour forecast, and warns you when the air becomes harmful. It uses one index everywhere: the US EPA AQI (a 0–500 scale, with the 2024 PM2.5 breakpoints). Below is how it works, and where I got things wrong along the way.

Where the data comes from

The main source is the Copernicus CAMS model via Open-Meteo. It's a model estimate with a spatial resolution of about 40 km, so neighbouring districts get almost the same values.

To see what's really happening, I added ground stations: Uzhydromet, embassy monitors and citizen sensors via WAQI. If a working station is within 2 km of a district, its value is used. Otherwise the site takes an average of the stations within 25 km, where closer stations count for more than distant ones (IDW, a distance-weighted average).

Faulty sensors, and one station that lifted half the city

Ground stations don't always tell the truth. I started with the obvious checks:

  • the same value for 12 hours straight: a "stuck" sensor;
  • a 48-hour median that's too low: the sensor isn't working;
  • in most of the last 6 hours, the station differs from the model by more than 5×: something's off.

That last check had to use AQI rather than PM2.5. In regional centres the model underestimates PM2.5 by 5–9×, so by PM2.5 real stations looked broken.

The most telling case came on November 20. The Uchtepa station read 71 µg/m³ while the rest of Tashkent's stations read 8 to 30. Through IDW it pushed Chilanzar and Sergeli up to AQI 130+, even though their air was clearly cleaner. That's where the "local hotspot" rule came from: a station several times higher or lower than its neighbours is only used for a place within 2 km, and stays out of the average for neighbouring districts.

Something similar happened in Khujand: one sensor showed AQI 363 while the model said about 55. There the station isn't switched off entirely; only that hour is dropped.

All such stations are listed on the "Station status" page with the reason.

So how far off is the model overall? From November 19 to December 2 (7,606 paired hours), the model averaged 24.4 µg/m³ of PM2.5 while the stations averaged 50.9. CAMS underestimates pollution by about half, with a correlation of only 0.41. Regional centres are worse still: in Samarkand the station averaged 71.6 and the model 16.8; in Gulistan, 92.1 against 21.5.

Forecast

A separate ML model (HistGradientBoostingRegressor) is trained for each location. Features: hour of day, day of week, temperature, humidity, wind, and PM2.5 from previous days. The final forecast is the average of CAMS and ML (an ensemble).

Every forecast is archived and, when its time comes, compared with the actual value. The "Forecast accuracy" page shows MAE and RMSE for the ensemble, ML and a naive "same as yesterday at this hour" forecast side by side.

That page caught me out. For one place it said ML was "more accurate by −26%". The minus meant the naive forecast had beaten my model, and the wording hid it. I fixed the wording, and now the ensemble uses the naive forecast instead of ML wherever it wins.

The numbers as of December 2 (archive since November 18, 131,792 forecast hours, PM2.5 error in µg/m³): the ensemble's MAE is 6.17, ML's 8.78 and the naive forecast's 10.53. But in training, on the last 72 hours, ML beats the naive forecast in only 18 of 36 places, with a median gain of about 3%. So the ensemble isn't decoration: ML on its own would often be no better than "same as yesterday".

On the same page I noticed CAMS looked almost error-free at short lead times. It turned out it was being compared against CAMS data itself. CAMS is now left out of the accuracy ranking.

Alerts

  • Web Push: a notification reaches the browser even when the site is closed. It uses VAPID, the standard a server uses to sign push notifications.
  • Telegram bot: shows the current situation on request, sends a daily summary every morning and a weekly recap on Mondays. In the health profile you can choose "sensitive" or "active", and the bot then warns you at a lower AQI.

A single location sends at most one alert every 6 hours.

The first version of the bot, by the way, didn't answer at all. The timeout parameter was passed to getUpdates twice, and Telegram never returned a single message.

Tech stack

LayerWhat
FrontendNext.js, TypeScript, Leaflet, Recharts, PWA, uz/ru/en
BackendPython, FastAPI, SQLAlchemy, APScheduler, scikit-learn
DatabasePostgreSQL
ServerOracle Cloud VM + Cloudflare Tunnel, auto-deploy via GitHub Actions

The dark map used to come from CARTO, until one day an API key requirement showed up where the map should have been. Now it's plain OpenStreetMap tiles darkened with a CSS filter.

What I learned

The most useful thing wasn't making the model more complex but honestly comparing it with a simple "same as yesterday" forecast and with real stations. As an outside check, the site also stores IQAir's Tashkent AQI every hour. Over 293 hours (November 20 to December 2), the site's value was off from IQAir by 21 AQI points on average, and the raw CAMS model by 48. That page is what showed me where ML loses, where CAMS was being compared with itself, and how one station in Uchtepa skewed the picture for neighbouring districts. Without the forecast archive I wouldn't have seen any of it.