knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  tidy = TRUE,
  eval = FALSE
)
library(AirVizR)
library(magrittr)
# library(readxl)
# library(lubridate)

Importing local Federal Reference Monitor (FRM) data

The following example demonstrates how to wrangle local FRM data. It is based on the data format of the Oregon Department of Environmental Quality (DEQ) "Portland SE Lafayette" station, which you can download from their "single station report" tool. Other FRM data can be imported in a similar manner, but might require customization.


Inputs

Many functions rely on the same inputs, therefore default to the same defined objects in the environment. It is highly recommended to specify inputs upfront in their own chunk to simplify functionality. Environment cleans are present in this document to showcase where and when these objects can be disgarded.

# File path to the file of interest
input_frm_path <- "data-raw/frm_july.xlsx"

## Optional grouping settings (which will NOT impact raw data output, but can be useful when graphing!)

## DATE GROUPING
# Run date grouping? If set to "FALSE", the date inputs below will not matter (but will still appear in the environment)
run_date_grouping <- TRUE
# If TRUE, specify the groupings below as respective items in their lists
# (i.e. the first item in each list is one "group", the second item in each list is another "group", etc.)
# Date grouping categories:
input_date_tags <- c("Before", "Independence Day", "After")
# Start dates (in a list, "YYYY-MM-DD")
input_date_starts <- c("2020-07-01", "2020-07-04", "2020-07-05")
# End dates (in a list, "YYYY-MM-DD")
input_date_ends <- c("2020-07-03", "2020-07-04", "2020-07-07")

## HOUR GROUPING
# Run hour grouping? If set to "FALSE", the hour inputs below will not matter (but will still appear in the environment)
run_hour_grouping <- TRUE
# If TRUE, specify the groupings below as respective items in their lists
# (i.e. the first item in each list is one "group", the second item in each list is another "group", etc.)
# Hour grouping categories:
input_hour_tags <- c("Morning", "Afternoon", "Evening", "Night")
# Start hours (in a list, using full hours in 24 hour format)
input_hour_starts <- c(5, 12, 17, 21)
# End hours will be automatically generated; no need to add "end" hours

Loading Data

# The following is location data for the DEQ FRM in Portland
frm_raw_meta <- data.frame(
  label = "DEQ SE Lafayette",
  location = factor("FRM"), # The device is outside but this will label it separately
  latitude = 45.496641,
  longitude = -122.602877,
  site_id = "41-051-0080",
  timezone = "America/Los_Angeles", # Use OlsonNames() to see valid inputs.
  flag_highValue = FALSE # Being an FRM, it is not expected to be reporting poorly
)

raw_frm <- read_frm()

Wrangling Data

frm_meta <- wrangle_meta(frm_raw_meta)
frm_full <- wrangle_frm(raw_frm, frm_meta)

frm_hourly <- group_stad(frm_full, by_day = TRUE, by_hour = TRUE)
frm_daily <- group_stad(frm_full, by_day = TRUE, by_hour = FALSE)
frm_diurnal <- group_stad(frm_full, by_day = FALSE, by_hour = TRUE)

if (run_date_grouping == TRUE){
  frm_full <- apply_date_tags(frm_full)
  frm_daily <- apply_date_tags(frm_daily)
  frm_hourly <- apply_date_tags(frm_hourly)
}
if (run_hour_grouping == TRUE) {
  frm_full <- apply_hour_tags(frm_full)
  frm_hourly <- apply_hour_tags(frm_hourly)
  frm_diurnal <- apply_hour_tags(frm_diurnal)
}
# OPTIONAL
# Cleaning the global environment
remove(run_date_grouping, run_hour_grouping)
remove(list = c(ls(pattern = "input_(hour|date|frm)_")))
# It is recommended to keep raw_meta and raw_data since it takes the longest to load,
# as well as the input start & end dates (since the diurnal set does not contain date information)

Next steps

Now we're ready to visualize! See the visualize-data vignette for instructions.
You may wish to first combine the data sets with other STADs, which you can learn about in the combine-data vignette.



gmcginnis/AirVizR documentation built on Dec. 20, 2021, 11:49 a.m.