The study
Clean Air Schools put low-cost air-quality sensors into NSW schools, indoors and outdoors. The study was scoped for 100 schools and more than 400 sensors from two vendors: 270+ Clarity monitors for particulates (PM2.5, with PM1, PM10, NO2, temperature and humidity on the same rows) and 130+ Efento sensors for CO2. Most analysis ran on the core cohort: 59 schools, 136 Clarity monitors reporting between 2021 and 2025, and their indoor Efento CO2 sensors.
I was the only engineer on the data side, on a research budget: get the readings in, keep them honest, make them fast to query.
What the raw data looked like
Two vendors, two clocks. Clarity serves data as reports: you request one, poll until it's ready, then download a wide CSV. Efento serves readings per network location, at most 34 days per request, across 17 locations. Cadence differed as well. The Clarity rows land roughly every 17 minutes per monitor, and the Efento CO2 sensors mixed 5-, 15- and 30-minute periods. I aligned everything to 15-minute windows for quality checks, so completeness could be counted as readings received against readings expected.
Vendor flags. Every Clarity value carries a status. Across the 10.1 million PM2.5 rows in our export, 34% were calibrated-ready, 41% calibration-missing and 25% calibration-unknown. For two rows in three, the vendor's calibrated number was either absent or couldn't be vouched for.
Hardware churn. Monitors were swapped between sites, and the deployment sheet tracked swaps as extra columns (Monitor, Monitor2, Monitor3). Data subscriptions lapsed quietly: 11 cohort monitors stopped delivering through the API when theirs expired between late 2023 and late 2024. Some sensors' PM2.5 jumped to 3,000+ µg/m³ and had to be cut from that date. Two schools' CO2 data was recorded in the wrong timezone.
Drift. Low-cost CO2 sensors drift as they age, and low-cost PM2.5 readings need correcting for humidity before they mean much.
Ingestion: idempotent upserts into Postgres
The Clarity path is an HTTP Cloud Function. A POST names a window (a trailing 7 days by default, or an explicit start and end) and optionally a report ID to reuse, a thread count and a chunk size. It reads credentials from Secret Manager, requests a report at the vendor's finest resolution, polls every 10 seconds, then writes monitors and measurements into Cloud SQL Postgres in parallel chunks through a pooled connector.
Every load is an idempotent upsert keyed on (datasource_id, time). That one key made everything else cheap: overlapping windows are harmless, a failed run is fixed by running the same window again, and a reading the vendor reprocessed later lands on the same row instead of duplicating it. Backfills became a loop: a driver script walked August 2022 to December 2023 in three-month windows, with 15 threads and 2,000-row chunks per call, spaced about 25 minutes apart. For bulk loads there was a second path that staged the report CSV in a GCS bucket and loaded it with Postgres COPY.
Schema: keep every version of the number
The measurements table has one row per sensor and timestamp, with the sensor's location, and three columns for each metric (PM1, PM2.5 and PM10 mass and number concentration, NO2, internal temperature, humidity): raw, status and value.
I kept all three because calibration was an open research question. The vendor's value was one answer among several, the status said how far to trust it, and raw was the only thing every method could start from.
Quality checks ran in SQL. A LAG(time) OVER (PARTITION BY source_id ORDER BY time) query flags any sensor with a gap longer than a day, and per-sensor non-null counts for each variable show which metrics a unit actually reports.
The analysis set: rebuilt around install dates
For the main analysis I built a static, analysis-ready PM2.5 dataset. I pulled one all-sensor Clarity export covering April 2021 to April 2025, streamed it in 1-million-row chunks, and kept the cohort's 136 monitors: 10,172,273 rows by 76 columns, of which 17 held any data.
Then I made the monitor history machine-readable: the wide swap sheet became 156 rows, one per deployment, each with a site, indoor/outdoor flag, and install and removal dates. Those dates were in Sydney local time, so they were localised and converted to UTC before filtering the UTC readings. Readings outside every deployment window were dropped: in the PM pass, 8,264,018 rows became 6,643,951, about one in five gone. The calibration models then ran over the resulting 8,191,162-row PM2.5 set in chunks.
Calibration and drift, in a package
The CAS Python package (about 4,200 lines, documented with MkDocs and pdoc) is how the team's researchers got at all of this. One interface reads Clarity from Postgres, another pulls Efento from its API, and a cohort interface fetches both in parallel threads and outer-joins them on school, indoor/outdoor and time after converting each to Sydney time.
Calibration lives there too, and it was research as much as engineering. Low-cost sensor calibration has no settled answer, so I read up on what works for each pollutant, came up with several candidate methods, fitted them against reference data, applied them across the network and compared the results. For PM2.5 that meant per-monitor linear models (five variants, assigned per monitor) and a bushfire model, keeping the higher of the two, plus regional and global models that use dew point and PM-times-humidity terms. Because the raw column is always there, comparing calibration methods for a pollutant is a function call, not a re-ingest.
For CO2 I wrote a drift correction. Each week's baseline comes from Monday 00:00–05:00, when the building is empty, and the offset is taken against 420 ppm outdoor air. Offsets are smoothed across neighbouring weeks and interpolated where a week has no quiet-hour data.
From 90-second pulls to Parquet
By late 2024 researchers used a notebook interface (ipywidgets and Plotly) that re-queried Postgres on every filter change. I timed it in December 2024: one school took 3.5–12 seconds, five schools 19–43 seconds, ten schools 37–87 seconds. Fine for a script, unusable for an interface.
The fix was a columnar copy shaped like the questions. The analysis set's 1.5 GB CSV (about 9 million rows) became a 120 MB Parquet file: Snappy compression, categorical types for the ID columns, and only the columns the analysis used. Then I rewrote it as a Hive-partitioned dataset, school=/I_O=/year=, because every view in the interface starts by choosing a school, indoor or outdoor, and a time range. That gave 343 partitions across 59 schools and 2021–2025, about 76,000 rows per slice.
Reads open one partition and only the columns asked for, with an LRU cache on partition loads and resamples. I prototyped Dask too, but at 76,000 rows a slice plain pandas was enough. A daily export kept the same layout current in a GCS bucket, so researchers could download the subset they needed instead of querying the production database. Pulls that had taken up to 90 seconds became near-instant reads.
Serving it
The package backs a notebook interface (all-school and single-school views, raw, hourly and daily resampling, indoor/outdoor, and the 25 µg/m³ daily PM2.5 standard on every plot). I also built a geospatial PM2.5 heatmap in React and SVG, and in 2023 automated fleet health checks: fortnightly vendor-status sweeps, battery checks, and emailed reports sorting monitors into healthy, offline, needs follow-up and may need replacing.
I presented this work as an invited speaker on the Big Data stream at AIRAH 2024.