openair
package. Files are imported from a remote server
operated by AEA that provides air quality data files as R data objects.thedata <- importAURN(site = "my1", year = 2009, pollutant =
"all", hc = FALSE)
site =
c("my1", "nott")
--- to import Marylebone Road and Nottingham for
example.year = 1990:2000
. To import several
specfic years use year = c(1990, 1995, 2000)
for example.pollutant = c("nox", "no2")
.hc = TRUE
will ensure hydrocarbon data are
imported. The default is however not to as most users will not be
interested in using hydrocarbon data and the resulting data importAURN
function is currently released as a
test version. NOTE - Information is required on the site codes for
easy use.importAURN
function has been written to make it
easy to import data from the UK AURN. AEA have provided .RData files (R
workspaces) of all individual sites and years for the AURN. These files
are updated on a daily basis. This approach requires a link to the
Internet to work.
There are several advantages over the web portal approach where .csv
files are downloaded. First, it is quick to select a range of sites,
pollutants and periods (see examples below). Second, storing the data as
.RData objects is very efficient as they are about four times smaller
than .csv files --- which means the data downloads quickly and saves
bandwidth. Third, the function completely avoids any need for data
manipulation or setting time formats, time zones etc. Finally, it is
easy to import many years of data beyond the current limit of about
64,000 lines. The final point makes it possible to download several long
time series in one go. The function also has the advantage that the
proper site name is imported and used in openair
functions.
The site codes and pollutant names can be upper or lower case. The
function will issue a warning when data less than six months old is
downloaded, which may not be ratified.
The data are imported by stacking sites on top of one another and will
have field names site
, code
(the site code) and
pollutant
. Sometimes it is useful to have columns of site
data. This can be done using the reshape
function --- see
examples below.
All units are expressed in mass terms for gaseous species (ug/m3 for NO,
NO2, NOx, SO2 and hydrocarbons; and mg/m3 for CO).
While the function is being developed, the following site codes should
help with selection.
## import all pollutants from Marylebone Rd from 1990:2009
mary <- importAURN(site = "my1", year = 2000:2009)
## import nox, no2, o3 from Marylebone Road and Nottingham Centre for 2000
thedata <- importAURN(site = c("my1", "nott"), year = 2000,
pollutant = c("nox", "no2", "o3"))
## import over 20 years of Mace Head O3 data!
o3 <- importAURN(site = "mh", year = 1987:2009)
## import hydrocarbon (and other) data from Marylebone Road
mary <- importAURN(site = "my1", year =1998, hc = TRUE)
## reshape the data so that each column represents a pollutant/site
thedata <- importAURN(site = c("nott", "kc1"), year = 2008,
pollutant = "o3")
thedata <- reshape(thedata, idvar = "date", timevar = "code", direction
= "wide")
## thedata now has columns o3.MY1 and o3.KC1
## can also get rid of columns, in this case site:
thedata <- reshape(thedata, idvar = "date", timevar = "code", direction
= "wide", drop = "site")
## now can export as a csv file:
write.csv(thedata, file = "~/temp/thedata.csv")
Run the code above in your browser using DataLab