Air quality
Overview
OpenAQ is a non-profit that collects publicly available air quality measurements from around the world into one uniform format. It focuses on the main pollutants: PM2.5, PM10, SO2, NO2, CO, O3 and black carbon, plus relative humidity and temperature. Values are reported in physical units (e.g. µg/m³, ppm), not as an air quality index.
The data are organised in a hierarchy: locations (a monitoring site) have sensors (one per pollutant), and sensors have measurements. A typical workflow is to find locations in an area, list their sensors, then download measurements for the sensors you want. This makes it a good data set for practising working with APIs, joining tables and handling time series.
Getting the data
R package (API)
Register for a free account at https://explore.openaq.org/register, then copy your API key from the account page into .Renviron as OPENAQ_API_KEY=yourkey (e.g. using usethis::edit_r_environ()), and restart R.
# install.packages("openaq")
library(openaq)
# Monitoring locations measuring PM2.5 (parameters_id = 2) around Melbourne
melb <- list_locations(
bbox = c(xmin = 144.5, ymin = -38.2, xmax = 145.5, ymax = -37.5),
parameters_id = 2
)
# Sensors at one location, then a month of hourly PM2.5 for one sensor
sensors <- list_location_sensors(melb$id[1])
pm25 <- list_sensor_measurements(
sensors_id = sensors$id[sensors$parameters_id == 2],
data = "hours",
datetime_from = as.POSIXct("2026-11-01", tz = "UTC"),
datetime_to = as.POSIXct("2026-12-01", tz = "UTC"),
limit = 1000
)Use list_parameters() to look up other parameters_id values. The free tier allows 60 requests per minute and 2,000 per hour, and each request returns at most limit rows, so use page to fetch longer series.
OpenAQ archive (no key)
Daily CSV files for each location are available from a public AWS bucket, with paths of the form records/csv.gz/locationid=<id>/year=<yyyy>/month=<mm>/location-<id>-<yyyymmdd>.csv.gz. Find location IDs on the OpenAQ Explorer map.
library(readr)
url <- "https://openaq-data-archive.s3.amazonaws.com/records/csv.gz/locationid=2178/year=2022/month=05/location-2178-20220503.csv.gz"
day <- read_csv(url)Data dictionary
list_locations(): one row per monitoring location
| variable | class | description |
|---|---|---|
id |
integer | OpenAQ location ID. |
name |
character | Location name (may be empty). |
is_mobile |
logical | Whether the monitor moves (e.g. mounted on a vehicle). |
is_monitor |
logical | TRUE for reference-grade regulatory monitors, FALSE for low-cost air sensors. |
timezone |
factor | Time zone of the location, e.g. Australia/Melbourne. |
countries_id, country_name, country_iso |
numeric, character, factor | Country ID, name and ISO 3166 code. |
latitude, longitude |
numeric | Location coordinates (WGS84). |
datetime_first, datetime_last |
POSIXct | First and most recent measurement (UTC). |
owner_name |
factor | Organisation that owns the monitor. |
providers_id, provider_name |
numeric, character | Organisation that supplies the data to OpenAQ. |
list_location_sensors(): one row per sensor (pollutant) at a location
| variable | class | description |
|---|---|---|
id |
numeric | Sensor ID, used in list_sensor_measurements(). |
name |
character | Pollutant and units, e.g. pm25 µg/m³. |
parameters_id |
numeric | Parameter ID (e.g. 2 for PM2.5). |
datetime_first_utc, datetime_first_local, datetime_last_utc, datetime_last_local |
POSIXct | First and last measurement times, in UTC and local time. |
min, max, avg |
numeric | Summary of all values recorded by the sensor. |
expected_count, observed_count, percent_complete, percent_coverage |
numeric | How many measurements were expected and received over the sensor’s lifetime. |
expected_interval, observed_interval |
factor | Expected and observed time covered. |
latest_value, latest_datetime, latest_latitude, latest_longitude |
numeric, POSIXct | Most recent measurement and where it was taken. |
list_sensor_measurements(): one row per time period
| variable | class | description |
|---|---|---|
value |
numeric | Measured value (for data = "hours" or longer, the average over the period). |
parameter_id, parameter_name, parameter_units |
numeric, character, character | Pollutant ID, name (e.g. pm25) and units (e.g. µg/m³). |
period_label, period_interval |
factor | Aggregation period, e.g. 1hour. |
datetime_from, datetime_to |
POSIXct | Start and end of the period, in local clock time but labelled as UTC (see below). |
latitude, longitude |
numeric | Coordinates of the measurement. |
min, q02, q25, median, q75, q98, max, avg, sd |
numeric | Summary of the raw values within the period (NA for raw measurements). |
expected_count, observed_count, percent_complete, percent_coverage |
numeric | Number of raw values expected and received within the period; use these to judge whether an hourly or daily value is reliable. |
expected_interval, observed_interval |
factor | Expected and observed time covered within the period. |
Archive CSV files: one row per measurement
| variable | class | description |
|---|---|---|
location_id |
numeric | OpenAQ location ID. |
sensors_id |
numeric | Sensor ID. |
location |
character | Location name and ID, e.g. Del Norte-2178. |
datetime |
POSIXct | Stored in the file as local time with UTC offset (e.g. 2022-05-03T01:00:00-06:00); read_csv() converts it to the correct UTC time. |
lat, lon |
numeric | Coordinates. |
parameter |
character | Pollutant, e.g. pm25, pm10, o3. |
units |
character | Units, e.g. µg/m³, ppm. |
value |
numeric | Measured value. |
Teaching ideas
- Working with APIs: go from locations to sensors to measurements, handling pagination and rate limits, and joining the tables by ID.
- Time series: daily and weekly patterns in NO2 (traffic) versus ozone (sunlight), or seasonal patterns in PM2.5 (wood heaters in winter).
- Events: look for bushfire smoke (e.g. summer 2019–20), industrial fires (e.g. the Derrimut chemical factory fire in July 2024), dust storms, or Guy Fawkes / New Year’s Eve fireworks in the PM2.5 record.
- Spatial: map the monitors in a city and compare sites near major roads with those in parks or suburbs.
- Measurement quality: compare a low-cost sensor (
is_monitor = FALSE) with a nearby reference monitor, and use the coverage variables to decide which hourly values to keep. - Policy: compare daily PM2.5 with the national standard (the Ambient Air Quality NEPM) and count exceedance days.
Things to watch out for
- Time zones:
list_sensor_measurements()returnsdatetime_fromanddatetime_toin the location’s local clock time, but the R values are labelledUTC(checked in openaq 1.1.0). Uselubridate::force_tz(datetime_from, "Australia/Melbourne")to fix the time zone, rather than converting it withwith_tz(). The archive CSVs are fine:read_csv()gives correct UTC times, whichwith_tz()converts to local time. - Coverage: check which Australian locations are available before setting an assignment. OpenAQ only has data from providers it has found or been given, and stations can start, stop or move.
- Sensor types: low-cost sensors are less accurate than regulatory monitors and can drift; filter with
monitor = TRUEif you only want reference-grade data. - Units differ by pollutant (µg/m³ for particles, ppm for gases); don’t put them on the same axis without thinking.
- Gaps and negative values: instruments go offline and some report small negative values near zero.
- API keys: each student needs their own key; keep it out of code that’s shared or submitted.
Used in
- Monash Business Analytics students, described in OpenAQ’s blog post How OpenAQ is empowering student learning. Students chose their own questions; for example, one looked at how the July 2024 Derrimut chemical factory fire affected Melbourne’s air quality. They downloaded the data with airpurifyr, a NUMBATs package built at a hackathon. airpurifyr has since been replaced by OpenAQ’s own openaq package, so use the code in Getting the data instead.
References
- OpenAQ API documentation: https://docs.openaq.org
- Biggs, R. and Parker, C. openaq: Access Air Quality Data from the OpenAQ API. R package. https://openaq.github.io/openaq-r/
- OpenAQ terms of use: https://docs.openaq.org/about/terms