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 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 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")
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:
importAURN
and family functions.timeAverage
and selectByDate
to
make it easier to manipulate atmospheric composition data.windRose
and
pollutionRose
.openair
type
option
available in most functions.type
option to easily
evaluate models by season, hour of the day etc. These include key
model statistics, Taylor Diagram, Conditional Quantile plots.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
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")
type
optionOne 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:
hemisphere
option that can be either "northern"
(default) or "southern"longitude
and latitude
wd
) is available type = "wd"
will split
the data up into 8 sectors: N, NE, E, SE, S, SW, W, NW.type = "season"
will just split the data into four
seasons regardless of the year.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.
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" )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.