rdefra: Interact with the UK AIR Pollution Database from DEFRA

Claudia Vitolo

2020-04-05

Introduction

The package rdefra allows to retrieve air pollution data from the Air Information Resource (UK-AIR, https://uk-air.defra.gov.uk/) of the Department for Environment, Food and Rural Affairs (DEFRA) in the United Kingdom. UK-AIR does not provide a public API for programmatic access to data, therefore this package scrapes the HTML pages to get relevant information.

This package follows a logic similar to other packages such as waterData and rnrfa: sites are first identified through a catalogue, data are imported via the station identification number, then visualised and/or used in analyses. The information related to the monitoring stations is accessible through the function ukair_catalogue(). Some station may have missing coordinates, which can be recovered using the function ukair_get_coordinates(). Lastly, time series data related to different pollutants can be obtained using the function ukair_get_hourly_data().

The package is designed to collect data efficiently. It allows to download multiple years of data for a single station with one line of code and, if used with the parallel package, allows the acquisition of data from hundreds of sites in only few minutes.

Installation

Get the released version from CRAN:

Or the development version from GitHub using the package remotes:

Load the rdefra package:

Functions

The package logic assumes that users access the UK-AIR database in two steps:

  1. Browse the catalogue of available stations and selects some stations of interest.
  2. Retrieves data for the selected stations.

Get stations catalogue

The list of monitoring stations can be downloaded using the function ukair_catalogue() with no input parameters, as in the example below.

There are currently 6608 stations in UK-AIR. The same function, can be used to filter the catalogue using the following input parameters:

  • site_name IDs of specific site (UK.AIR.ID). By default this is left blank to get info on all the available sites.
  • pollutant This is an integer between 1 and 10. Default is 9999, which means all the pollutants.
  • group_id This is the identification number of a group of stations. Default is 9999 which means all available networks.
  • closed This is set to TRUE to include closed stations, FALSE otherwise.
  • country_id This is the identification number of the country, it can be an integer between 1 and 6. Default is 9999, which means all the countries.
  • region_id This is the identification number of the region. 1 = Aberdeen City, etc. (for the full list see https://uk-air.defra.gov.uk/). Default is 9999, which means all the local authorities.

The example above shows how to retrieve the 108 stations in England in which ozone is measured.

Get missing coordinates

Locating a station is extremely important to be able to carry out any spatial analysis. If coordinates are missing, for some stations in the catalogue, it might be possible to retrieve Easting and Northing (coordinates in the British National Grid) from DEFRA’s web pages, transform them to latitude and longitude and populate the missing coordinates as shown below.

Check hourly data availability

Pollution data started to be collected in 1972 and consists of hourly concentration of various species (in micrograms/m3), such as ozone (O3), particulate matters (PM2.5 and PM10), nitrogen dioxide (NO2), sulphur dioxide (SO2), and so on.

The ID under which these data are available differs from the UK.AIR.ID. The catalogue does not contain this additional station ID (called SiteID hereafter) but DEFRA’s web pages contain references to both the UK.AIR.ID and the SiteID. The function below uses as input the UK.AIR.ID and outputs the SiteID, if available.

Please note this function takes several minutes to run.

Cached catalogue

For convenience, a cached version of the catalogue (last updated in December 2019) is included in the package and can be loaded using the following command:

The cached catalogue contains all the available siteIDs and coordinates and can be used offline as lookup table to find out the correspondence between the UK.AIR.ID and SiteID, as well as to investigate station characteristics.

Get hourly data

Once the SiteID is known, time series for a given station can be retrieved in one line of code:

Hourly ozone data from London Marylebone Road monitoring station in 2015

Hourly ozone data from London Marylebone Road monitoring station in 2015

The above figure shows the highest concentrations happen in late spring and at the beginning of summer. In order to check whether this happens every year, we can download multiple years of data and then compare them.

The code below explores the distribution of ozone by month. The resulting box plots show that the highest concentrations usually occurr during April/May and that these vary year-by-year.

Applications

Analyse the spatial distribution of the monitoring stations

Below are two plots showing the spatial distribution of the monitoring stations. These are concentrated largely in urban areas and mostly estimate the background level of concentration of pollutants.

Spatial distribution of the monitoring stations across zones.

Spatial distribution of the monitoring stations across zones.

Spatial distribution of the monitoring stations across environment types.

Spatial distribution of the monitoring stations across environment types.