-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.Rmd
More file actions
175 lines (140 loc) · 4.88 KB
/
Copy pathindex.Rmd
File metadata and controls
175 lines (140 loc) · 4.88 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
---
title: "Annual Data Validation"
author: "Air Quality Section | Environmental Monitoring and Analysis Branch"
date: "`r format(Sys.time(), '%B %d, %Y')`"
params:
prepped_data: !r stringr::str_c("./prepped-data/",dir('./prepped-data')[15],collapse="")
year: 2025
site: bookdown::bookdown_site
output:
bookdown::gitbook:
config:
toc:
collapse: section
---
```{r setup,echo=FALSE,warning=FALSE,message=FALSE}
# for testing (comment out when compiling books)
# params <- list(prepped_data = stringr::str_c("./prepped-data/",dir('./prepped-data')[15],collapse=""),
# year = 2024)
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("./stat-summary-fcns/pm25-stats-fcn.R")
source("./stat-summary-fcns/pm10-stats-fcn.R")
source("./stat-summary-fcns/no2-stats-fcn.R")
source("./stat-summary-fcns/no-stats-fcn.R")
source("./stat-summary-fcns/so2-stats-fcn.R")
source("./stat-summary-fcns/o3-stats-fcn.R")
source("./stat-summary-fcns/h2s-stats-fcn.R")
source("./stat-summary-fcns/trs-stats-fcn.R")
source("./stat-summary-fcns/co-stats-fcn.R")
source("plotly-fcn.R")
source("empty-plot.R")
```
```{r import-data}
#use the line below for automated report generation
data<-readr::read_rds(params$prepped_data)
station<-unique(data$STATION_NAME)
#LOOK FOR DUPLICATES
# duplicates<-data %>%
# dplyr::group_by(DATE_PST, STATION_NAME, PARAMETER) %>%
# dplyr::summarise(n = dplyr::n(), .groups = "drop") %>%
# dplyr::filter(n > 1L) %>%
# dplyr::left_join(.,
# data,
# by=c("DATE_PST","STATION_NAME","PARAMETER"))
#
# utils::View(duplicates)
#LOOK FOR DUPLICATES
# duplicates<-data %>%
# dplyr::group_by(DATE_PST, STATION_NAME, PARAMETER) %>%
# dplyr::summarise(n = dplyr::n(), .groups = "drop") %>%
# dplyr::filter(n > 1L) %>%
# dplyr::left_join(.,
# data,
# by=c("DATE_PST","STATION_NAME","PARAMETER"))
#
# utils::View(duplicates)
#use the line below for testing - comment it out and pick a station with the parameter(s) of interest
# data<-readRDS("./preppedData/Kelowna.rds")
prev_yrs_wind<-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(x=_)
# add units because it is used below and in the plots
# look at all the unique parameters
# data |> dplyr::distinct(PARAMETER)
data %<>%
dplyr::mutate(UNIT=dplyr::case_when(
PARAMETER %in% c("CO",
"NO",
"NO2",
"NOx",
"O3",
"SO2",
"H2S",
"TRS") ~ "ppb",
PARAMETER %in% c("PM10",
"PM25") ~ "ug/m3",
PARAMETER == "HUMIDITY" ~ "%",
PARAMETER == "TEMP_MEAN" ~ "deg. C",
PARAMETER == "WDIR_VECT" ~ "deg.",
PARAMETER == "WSPD_SCLR" ~ "m/s"
))
```
```{r daily-data}
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 hourly-and-daily}
# combine hourly and day data sets in one tidy tibble
all_data<-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`**.