daily_aqi: Retrieve the air quality data.

Description Usage Arguments Value Note Examples

View source: R/prep_aqi.R

Description

Retrieve the air quality data.

Usage

1
2
3
4
5
6
7
8
daily_aqi(
  aqs_api_email,
  aqs_api_key,
  fips_list,
  metric_list = c(81102, 88101, 42101, 44201, 42602),
  year_min = 2015,
  year_max = 2015
)

Arguments

aqs_api_email

AQS API email

aqs_api_key

AQS API key

fips_list

A vector of FIPS codes per county. One can use the output from the get_counties function as follows: fips_list=pull(counties, 'fips')

metric_list

list of codes that represent different air quality metrics 81101 - PM10, 88101 - PM2.5, 42101 - CO, 42602 - NO2, 44201 - Ozone.

year_min

earliest year to pull the air quality data for, starts January 1st.

year_max

latest year to pull the air quality data for, ends December 31st.

Value

A dataframe of daily AQI data, including the metrics specified.

Note

The function uses the AQS API to fetch the data from the API endpoints. Use the following service to register as a user: A verification email will be sent to the email account specified. To register using the email address create and request this link (Replace myemail@example.com in the example with your email address.): (https://aqs.epa.gov/data/api/signup?email=myemail@example.com) You then need to set the email and the key in the .Renviron file as follows, i.e. aqs_api_email=myemail@example.com aqs_api_key=testkey1234

AQS AQI has request limits and ToS: (https://aqs.epa.gov/aqsweb/documents/data_api.html#terms). The function intentionally adds a 10 second delay between each call (per year, per county) but pay attention to the limits as the account may be disabled. It is also recommended to process no more than five years at a time, as the API request occasionally times out and data may be lost.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Not run: 
aqs_api_email = Sys.getenv("aqs_api_email")
aqs_api_key = Sys.getenv("aqs_api_key")

state_codes <- get_state_code(aqs_api_email = aqs_api_email,
                              aqs_api_key = aqs_api_key,
                              state_names = c('California'))
counties <- get_counties(aqs_api_email = aqs_api_email,
                         aqs_api_key = aqs_api_key,
                         state_codes = state_codes)
aqi <- daily_aqi(aqs_api_email = aqs_api_email,
                 aqs_api_key = aqs_api_key,
                 fips_list = counties$fips,
                 year_min = 2015,
                 year_max = 2015)

## End(Not run)

wildviz documentation built on Aug. 23, 2021, 9:06 a.m.