knitr::opts_chunk$set(
  collapse = TRUE,
  warning = FALSE,
  fig.retina = 2,
  message = FALSE,
  eval = FALSE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

openair: open source tools for air quality data analysis

R-CMD-check CRAN
status

openair is an R package developed for the purpose of analysing air quality data --- or more generally atmospheric composition data. The package is extensively used in academia, the public and private sectors. The project was initially funded by the UK Natural Environment Research Council (NERC), with additional funds from Defra.

The most up to date information on openair can be found in the package itself and at the book website (https://bookdown.org/david_carslaw/openair/).

Installation

Installation can be done in the normal way:

install.packages("openair")

The development version can be installed from GitHub. Installation of openair from GitHub is easy using the pak package. Note, because openair contains C++ code a compiler is also needed. For Windows - for example, Rtools is needed.

# install.packages("pak")
pak::pak("davidcarslaw/openair")

Description

openair has developed over several years to help analyse air quality data.

This package continues to develop and input from other developers would be welcome. A summary of some of the features are:

Brief examples

Import data from the UK Automatic Urban and Rural Network

It is easy to import hourly data from 100s of sites and to import several sites at one time and several years of data.

library(openair)
kc1 <- importAURN(site = "kc1", year = 2020)
kc1

Utility functions

Using the selectByDate function it is easy to select quite complex time-based periods. For example, to select weekday (Monday to Friday) data from June to September for 2012 and for the hours 7am to 7pm inclusive:

sub <- selectByDate(kc1,
  day = "weekday",
  year = 2020,
  month = 6:9,
  hour = 7:19
)
sub

Similarly it is easy to time-average data in many flexible ways. For example, 2-week means can be calculated as

sub2 <- timeAverage(kc1, avg.time = "2 week")

The type option

One of the key aspects of openair is the use of the type option, which is available for almost all openair functions. The type option partitions data by different categories of variable. There are many built-in options that type can take based on splitting your data by different date values. A summary of in-built values of type are:

If a categorical variable is present in a data frame e.g. site then that variables can be used directly e.g. type = "site".

type can also be a numeric variable. In this case the numeric variable is split up into 4 quantiles i.e. four partitions containing equal numbers of points. Note the user can supply the option n.levels to indicate how many quantiles to use.

Example directional analysis

openair can plot basic wind roses very easily provided the variables ws (wind speed) and wd (wind direction) are available.

windRose(mydata)

However, the real flexibility comes from being able to use the type option.

``r type option.", fig.alt="Polar bar charts showing the proportion of wind coming from 12 compass directions. There are 8 charts, each representing a year of data from 1998 to 2005. While there is a small amount of variation, the dominant wind direction for each year is from the south west."} windRose(mydata, type = "year", layout = c(4, 2) )

There are many flavours of bivariate polar plots, as described
[here](https://bookdown.org/david_carslaw/openair/sections/directional-analysis/polar-plots.html) that
are useful for understanding air pollution sources.

```r
polarPlot(mydata,
  pollutant = "so2",
  statistic = "cpf",
  percentile = 90,
  cols = "YlGnBu"
)


davidcarslaw/openair documentation built on April 23, 2024, 4:08 p.m.