Skip to content

Air quality from CAMS: NO2, CO, ozone, SO2, particles and the US AQI (model "air") - #17

Merged
guernica0131 merged 1 commit into
mainfrom
air-quality
Nov 27, 2026
Merged

guernica0131 merged 1 commit into
mainfrom
air-quality

Conversation

@guernica0131

@guernica0131 guernica0131 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

The expert asked for NO2, CO and an AQI. This adds a model air from CAMS, the Copernicus Atmosphere Monitoring Service's global forecast (ECMWF's IFS with chemistry, about 40 km), read from the Atmosphere Data Store (ADS).

What it serves (/v2/air/...), hourly to 120 h, from two runs a day, on CAMS's own 0.4° grid:

  • no2, co, o3, so2: the gases at the model's lowest level (about 10 m up), in µg/m³. They are converted from mass mixing ratios using the air's density, taken from that level's temperature and pressure; the pressure uses the files' own level coefficients.
  • pm25, pm10: the same ids and meaning as GEFS-Aerosols', so the two models can be compared.
  • aqi: the US EPA Air Quality Index, computed at ingest (forecast/aqi.py) following EPA-403/B-26-003 (May 2026):
    • Table 6 breakpoints, truncation, and Equation 1.
    • Averaging windows: PM over 24 h, ozone and CO over 8 h (ozone's 1-hour value counts too when its index is higher), NO2 and SO2 hourly (SO2 over 304 ppb uses its 24-hour mean).
    • The tests check it against the document's worked examples. One of those examples prints 148, but its own equation gives 147.49, so the test expects 147 and notes the slip.
    • In a forecast's first day, the averages start at its first hour, because the run has no earlier hours.
  • Daily summaries: aqi_max, no2_mean, co_mean, o3_max, pm25_mean, pm10_mean.
  • Palettes:
    • The AQI uses EPA's colours, graded like the existing PM2.5 palette.
    • Each gas has its own hue, and clean air is see-through.

Getting a run. The ADS queues requests, which can take anywhere from under a minute to an hour. The ingest is built so the queue never holds up the other models:

  • It asks for a run on one poll (prepare raises the new RunPending), and the other models go on.
  • A later poll downloads the run (all eight fields, about 800 MB), reads it, and deletes the file.
  • The request id is saved in data/forecast/air/.ads, so a restart carries on with the same request.

The ECMWF data stores' current notice for automated clients asks for one request at a time and warns against resubmitting invalid requests. So:

  • There is one request per run, checked against the dataset's constraints first.
  • A failed request is asked again after 1 h, then after 2 h; after three failures, the run is left for the next one.
  • A download that breaks off is tried again on the next poll.

Accounts and licence.

  • The model is served by default only when CDSAPI_KEY is set. Production's .env doesn't have it yet.
  • The CAMS data are under CC BY 4.0. The credit reads "Contains modified Copernicus Atmosphere Monitoring Service information ", with the DOI and ECMWF's disclaimer.

Checked.

  • 169 tests pass (13 new), and ruff passes.
  • A real 2-hour global CAMS file was decoded and published locally:
    • The surface fields arrive as GRIB1 while the gases are GRIB2; the message scanner handles both.
    • Sample values: Delhi AQI 172–179, Beijing 303–313, Dili 35, Bodélé dust in Chad 1851 (PM10 1820 µg/m³; EPA's last segment carries on past 500).
    • Windy seas read "moderate" from sea salt, because EPA's "good" PM2.5 now stops at 9 µg/m³. The AQI description says so.

A stored run is about 0.7 GB, and two are kept.

…(model "air")

The Copernicus Atmosphere Monitoring Service's global forecast, from the Atmosphere Data Store:
two runs a day, hourly to 120 h, stored on its own 0.4° grid. The gases at the lowest model level
are turned into µg/m³ with the air's density there; the US EPA's Air Quality Index is worked out
at ingest hour by hour with EPA's breakpoints and averaging windows (forecast/aqi.py, checked
against the technical document's worked examples).

The ADS queues requests, so the ingest asks for a run on one poll (prepare raises RunPending)
and downloads it on a later one, without holding up the other models. One request at a time,
checked against the dataset's constraints first; a failed one is asked again only after a wait,
as the ADS asks of automated clients. Served by default only when CDSAPI_KEY is set.
@guernica0131
guernica0131 merged commit b203a12 into main Nov 27, 2026
9 checks passed
@guernica0131
guernica0131 deleted the air-quality branch November 27, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant