-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path10-wind.Rmd
More file actions
421 lines (294 loc) · 10.4 KB
/
Copy path10-wind.Rmd
File metadata and controls
421 lines (294 loc) · 10.4 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# Wind {.tabset}
```{r wind_options}
knitr::opts_chunk$set(cache = FALSE)
```
## Time Series
Something to look for: ws/wd lock due to rime on the anemometer or vane, data coming online after long periods (multiple hours) of being offline only to have the first hour read high, then all subsequent hours much lower.
### Wind Speed
```{r wspd_sclr-hourly}
wspd_sclr_plots<-if(
(data %>%
dplyr::filter(PARAMETER %in% toupper("wspd_sclr") & !is.na(RAW_VALUE)) %>%
nrow(.))==0
) {htmltools::tags$p("There is no data for this parameter.")} else {
plotly_fcn(data,
all_data,
parameter=toupper("wspd_sclr"))
}
htmltools::tagList(wspd_sclr_plots)
```
### Wind Direction
```{r wdir_vect-hourly}
wdir_vect_plots<-if(
(data %>%
dplyr::filter(PARAMETER %in% toupper("wdir_vect")& !is.na(RAW_VALUE)) %>%
nrow(.))==0
) {htmltools::tags$p("There is no data for this parameter.")} else {
plotly_fcn(data,
all_data,
parameter=toupper("wdir_vect"))
}
htmltools::tagList(wdir_vect_plots)
```
## Histograms
### Wind Speed (Scalar)
```{r ws-histogram}
suppressWarnings(
htmltools::tagList(
purrr::map(data |>
dplyr::pull(STATION_NAME) |>
unique(x=_),
function(station)
{
plot_data<-data |>
dplyr::filter(STATION_NAME %in% station &
PARAMETER %in% toupper("wspd_sclr"))
if(nrow(plot_data)!=plot_data |>
dplyr::summarise(nas=sum(is.na(RAW_VALUE))) |>
dplyr::pull(nas)){
p <- ggplot2::ggplot(data = plot_data,
ggplot2::aes(x = RAW_VALUE,
fill = INSTRUMENT,
color = INSTRUMENT)) +
ggplot2::geom_histogram(alpha = 0.25,
binwidth = 1) +
ggplot2::labs(
title = paste("Histogram:",
station),
y = "Count",
x = "Hourly Wind Speed (m/s)"
) +
ggplot2::theme_bw() +
ggplot2::theme(legend.position = "none",
legend.title = ggplot2::element_blank()) +
ggplot2::scale_fill_brewer(palette = "Set1") +
ggplot2::facet_wrap(~ INSTRUMENT, scales = "free")
plotly::ggplotly(p)
} else{htmltools::tags$p("There is no data for this parameter.")}#end if and else
} #end plot function
)# end map
) #end tagList
) #end suppressWarnings
```
### Wind Direction (Vector)
```{r wd-histogram}
suppressWarnings(
htmltools::tagList(
purrr::map(data |>
dplyr::pull(STATION_NAME) |>
unique(x=_),
function(station)
{
plot_data<-data |>
dplyr::filter(STATION_NAME %in% station &
PARAMETER %in% toupper("wdir_vect"))
if(nrow(plot_data)!=plot_data |>
dplyr::summarise(nas=sum(is.na(RAW_VALUE))) |>
dplyr::pull(nas)){
p <- ggplot2::ggplot(data = plot_data,
ggplot2::aes(x = RAW_VALUE,
fill = INSTRUMENT,
color = INSTRUMENT)) +
ggplot2::geom_histogram(alpha = 0.25,
binwidth = 1) +
ggplot2::labs(
title = paste("Histogram:",
station),
y = "Count",
x = "Hourly Wind Direction (degrees)"
) +
ggplot2::theme_bw() +
ggplot2::theme(legend.position = "none",
legend.title = ggplot2::element_blank()) +
ggplot2::scale_fill_brewer(palette = "Set1") +
ggplot2::facet_wrap(~ INSTRUMENT, scales = "free")
plotly::ggplotly(p)
} else{htmltools::tags$p("There is no data for this parameter.")}#end if and else
} #end plot function
)# end map
) #end tagList
) #end suppressWarnings
```
## Wind Roses
Wind roses for `r params$year` and 5 previous years (when available).
Things to look for when validating wind data:
+ Annual windrose
+ Windrose from previous years
+ Percent calm winds for the past 5-8 years
+ Do we have any pictures of the station?
+ Does the windrose make sense to you relative to the local topography?
+ RH - does RH get to 100% or does it max out at 97%? Has this changed recently?
+ Can I see any obvious breakpoints in a strip chart where something changes/
```{r wind-cache}
knitr::opts_chunk$set(cache = FALSE)
```
```{r wind-data-prep-qaqc}
# select wind data, get it in openair format
wind_data <- # contains X previous years as per _01.import-data.html
dplyr::bind_rows(
data |> # data from import-data chunk in index.Rmd
dplyr::filter(PARAMETER %in% c("WSPD_SCLR", "WDIR_VECT")),
prev_yrs_wind
)
```
```{r duplicates,eval=FALSE,include=FALSE}
# # # # # FIND DUPLICATES
duplicates<-wind_data |>
dplyr::group_by(DATE_PST, STATION_NAME, PARAMETER) |>
dplyr::summarise(n = dplyr::n(), .groups = "drop") |>
dplyr::filter(n > 1L) |>
dplyr::left_join(x=_,
wind_data,
by=c("DATE_PST","STATION_NAME","PARAMETER"))
utils::View(duplicates)
# save duplicates as csv
write.csv(duplicates,"duplicates.csv")
# # # EXPLORATORY DATA ANALYSIS # # #
#look at the first 6 rows of each set of duplicates (by PARAMETER)
duplicates |>
dplyr::group_by(PARAMETER) |>
dplyr::slice(1:6) |> utils::View()
# are any groups all NA's? makes it easy to remove
duplicates |>
# dplyr::filter(PARAMETER=="WSPD_SCLR") |>
dplyr::group_by(PARAMETER,INSTRUMENT) |>
dplyr::summarise(`# NA's`=sum(is.na(RAW_VALUE)),
`# Obs`=sum(!is.na(RAW_VALUE)),
`# Hours`=dplyr::n())
# when did the duplicates start and end?
duplicates |>
dplyr::group_by(STATION_NAME,PARAMETER,INSTRUMENT) |>
dplyr::summarise(start=min(DATE_PST),
end=max(DATE_PST))
# to look at the whole data set (sorted by PARAMETER and DATE_PST)
duplicates |>
dplyr::arrange(PARAMETER,DATE_PST) |> utils::View()
duplicates |>
dplyr::filter(PARAMETER=="WDIR_VECT") |> utils::View()
# odd rows - shoudl be all NA's
dplyr::slice(seq(1,nrow(.),2)) |> utils::View()
# preview wind_data
wind_data |>
dplyr::filter(INSTRUMENT=="UNSPECIFIED" &
lubridate::year(DATE_PST)==2021) |> utils::View()
# # # END DUPLICATES
```
```{r wind-data-openair}
if( all(nrow(wind_data)!=0, # at least one row of data
any(unique(wind_data$PARAMETER) %in% "WSPD_SCLR"),
any(unique(wind_data$PARAMETER) %in% "WDIR_VECT")
)
){
wind_data <- wind_data |>
dplyr::select(date = DATE_PST,
STATION_NAME,
# INSTRUMENT,
PARAMETER,
RAW_VALUE) |>
tidyr::pivot_wider(data=_,
names_from = PARAMETER,
values_from = RAW_VALUE) |>
dplyr::rename(ws = WSPD_SCLR,
wd = WDIR_VECT) |>
dplyr::mutate(ws = ifelse(is.na(wd), NA_real_, ws),
wd = ifelse(is.na(ws), NA_real_, wd))
}
# openair::summaryPlot(wind_data)
```
```{r wind-rose, fig.show='hide'}
if(all(
# at least a row of data
nrow(wind_data) != 0,
# some data in the year being validated
length(unique(lubridate::year(wind_data$date)) %in% params$year)!=0,
# a column called ws
any(names(wind_data) %in% "ws"),
# a column called wd
any(names(wind_data) %in% "wd")
)
) {
station<-unique(wind_data$STATION_NAME)
plot_list<-lapply(unique(lubridate::year(wind_data$date)) |> sort(x=_),
# plot_list<-purrr::walk(unique(lubridate::year(wind_data$date)) |> sort(x=_),
function(year){
# TESTING
# year<-2024
#
# wind_dataBackup<-wind_data
#
# wind_data<-wind_dataBackup
# END TESTING
wind_data %<>%
dplyr::filter(lubridate::year(date) %in% year)
#number of calm hours
ncalm <- wind_data |>
dplyr::filter(ws < 0.5) |>
dplyr::summarise(calms = n())
#total number of valid ws hours
ntotal <- wind_data |>
dplyr::filter(!is.na(ws)) |>
dplyr::summarise(total = n())
#percentage calm (ws<0.5 m/s)
pcalm <- round(100 * ncalm / ntotal,
digits = 2)
#filter out calm wind_data
roseData <- wind_data |>
dplyr::filter(ws >= 0.5)
if(nrow(wind_data)==sum(is.na(wind_data$ws)) | nrow(roseData)==0){
#make an empty plot when there is no data for a year
ggplot2::ggplot(data=tibble::tibble(
y=NA_real_,
x=NA_real_),
ggplot2::aes(x=x,y=y
))+
ggplot2::annotate("text",x=0,y=0,label="There is no valid paired wind data for this year.")+
ggplot2::labs(x="",
y="",
title=year)+
ggplot2::theme_bw()+
ggplot2::theme(axis.text.x = ggplot2::element_blank(),
axis.ticks.x = ggplot2::element_blank(),
axis.text.y = ggplot2::element_blank(),
axis.ticks.y = ggplot2::element_blank()) +
ggplot2::coord_polar()
} else {
#windRose
p<-windRose(
roseData,
annotate = FALSE,
breaks = c(0.5, 1.5, 3.3, 5.5, 7.9, 10.7, 13.8, 17.1),
#Beaufort scale with 0.5 as lowest cut point.
sub = paste("Calms (=<0.5m/s)=", pcalm, "%"),
key.position = "right",
main = stringr::str_c(year),
angle = 360 / 16,
#16 spokes
cols = "jet",
paddle = FALSE
)
p$plot
} # end else
} #end function(station)
) # map
} else{
plot_list<-htmltools::tags$p("This station either doesn't measure wind, has no wind data for the year being validated, or it is missing one of WSPD_SCLR or WDIR_VECT")
}
```
```{r wind-rose-fig-dims}
#define width and height of wind rose figures based on length of plot_list
fig_height<-dplyr::case_when(
length(plot_list) %in% 1:2 ~ 4,
length(plot_list) %in% 3:4 ~ 8,
length(plot_list) %in% 5:6 ~ 12,
length(plot_list) %in% 7:8 ~ 16
)
```
```{r wind-rose-output,fig.height=fig_height}
if(is.null(plot_list$name)){
gridExtra::grid.arrange(grobs=plot_list,
ncol=dplyr::if_else(length(plot_list)==1,1,2),
top=unique(wind_data$STATION_NAME))
}else{
plot_list
}
```