forked from bcgov/aq-level2-validation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.Rmd
More file actions
120 lines (100 loc) · 3.46 KB
/
Copy pathindex.Rmd
File metadata and controls
120 lines (100 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
title: "Annual Data Validation"
author: "Air Quality Section | Regional Operations Branch"
date: "`r format(Sys.time(), '%B %d, %Y')`"
params:
preppedData: !r stringr::str_c("./preppedData/",dir('./preppedData')[72],collapse="")
year: 2022
site: bookdown::bookdown_site
output:
bookdown::gitbook:
config:
toc:
collapse: section
---
```{r setup,echo=FALSE,warning=FALSE,message=FALSE}
# To do's for next year:
# - add range slider to plotly so it's easy to pan along axes:
#(https://plotly.com/r/range-slider/)
# - round aqs stats to match ecms
# - add difference row to sas summary
knitr::opts_chunk$set(warning = FALSE,
message = FALSE,
echo = FALSE)
library(tidyverse)
library(openair)
library(Hmisc)
library(xts)
library(plotly)
library(RCurl)
library(DT)
library(feather)
library(magrittr)
library(readxl)
library(gdata)
# functions to calculate SAS stats from hourly data
source("./statSummaryFcns/pm25StatsFcn.R")
source("./statSummaryFcns/pm10StatsFcn.R")
source("./statSummaryFcns/no2StatsFcn.R")
source("./statSummaryFcns/noStatsFcn.R")
source("./statSummaryFcns/so2StatsFcn.R")
source("./statSummaryFcns/o3StatsFcn.R")
source("./statSummaryFcns/h2sStatsFcn.R")
source("./statSummaryFcns/trsStatsFcn.R")
source("./statSummaryFcns/coStatsFcn.R")
source("plotlyFcn.R")
source("emptyPlot.R")
```
```{r importData}
#use the line below for automated report generation
data<-readRDS(params$preppedData)
#use the line below for testing - comment it out and pick a station with the parameter(s) of interest
# data<-readRDS("./preppedData/Cranbrook Muriel Baxter.rds")
prevYrWind<-data %>%
dplyr::filter(lubridate::year(DATE_PST)!=params$year &
PARAMETER %in% c("WSPD_SCLR","WDIR_VECT"))
data %<>%
dplyr::filter(lubridate::year(DATE_PST)==params$year) %>%
dplyr::group_by(PARAMETER,INSTRUMENT) %>%
dplyr::filter(!all(is.na(RAW_VALUE))) %>% dplyr::ungroup(.)
```
```{r dailyData}
day<-data %>%
# rename to date for openair
dplyr::rename(date=DATE_PST) %>%
dplyr::group_by(STATION_NAME,PARAMETER,INSTRUMENT) %>%
dplyr::group_modify(~ openair::timeAverage(.x,
pollutant="RAW_VALUE",
avg.time = "day",
data.thresh = 75)
) %>%
ungroup %>%
dplyr::rename(DATE_PST=date)
`24hr`<-data %>%
# rename to date for openair
dplyr::rename(date=DATE_PST) %>%
dplyr::group_by(STATION_NAME,PARAMETER,INSTRUMENT) %>%
dplyr::group_modify(~ openair::rollingMean(.x,
pollutant="RAW_VALUE",
width = 24,
align = "right",
data.thresh = 75,
new.name = "RAW_VALUE")
) %>%
ungroup %>%
dplyr::rename(DATE_PST=date)
```
```{r hourlyAndDaily}
# combine hourly and day data sets in one tidy tibble
allData<-data %>%
dplyr::select(names(day)) %>%
dplyr::mutate(TIME_AVG = "Hourly") %>%
dplyr::bind_rows(.,
day %>%
dplyr::mutate(TIME_AVG = "Daily")) %>%
dplyr::bind_rows(.,
`24hr` %>%
dplyr::mutate(TIME_AVG = "24-HR Running Ave"))
```
# Preamble {-}
**This report is for `r data %>% dplyr::pull(STATION_NAME) %>% unique %>% sort`**.