-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwind_analysis.Rmd
More file actions
163 lines (115 loc) · 3.72 KB
/
wind_analysis.Rmd
File metadata and controls
163 lines (115 loc) · 3.72 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
---
title: "wind_analysis"
author: "Steven Cognac"
date: "11/28/2021"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(dataRetrieval)
library(tidyverse)
library(here)
library(patchwork)
library(readr)
library(feasts)
#library(smooth)
#library(slider)
library(lubridate)
library(tibbletime)
library(tsibble)
```
Data downloaded from the NOAA National Centers for Environmental Information (NCEI) Climate Data Online search tool for Local Climatological Data (LCD) - (https://www.ncdc.noaa.gov/cdo-web/datatools/lcd)
https://www.ncei.noaa.gov/metadata/geoportal/rest/metadata/item/gov.noaa.ncdc:C00684/html
10-year Date Range
Start: 2011-10-01
End: 2021-09-30
Stations
- VACAVILLE NUT TREE AIRPORT ASOS, CA US (Station No: WBAN:93241)
- SACRAMENTO AIRPORT ASOS, CA US (Station No: WBAN:23232)
- CONCORD BUCHANAN FIELD, CA US (WBAN:23254)
sacramento airport metadata - https://www.ncdc.noaa.gov/cdo-web/datasets/GHCND/stations/GHCND:USW00023232/detail
# Read in Data
```{r}
wind_vaca_raw <- read_csv(here("data", "2805190_vacaville.csv")) %>%
select(2,56:58) %>%
filter(DATE > "2014-12-31 23:59:00")
wind_sac_raw <- read_csv(here("data", "2805192_sacramento.csv")) %>%
select(2,56:58) %>%
filter(DATE > "2014-12-31 23:59:00")
wind_concord_raw <- read_csv(here("data", "2805195_concord.csv")) %>%
select(2,56:58) %>%
filter(DATE > "2014-12-31 23:59:00")
```
```{r}
# vacaville nut tree airport
wind_vaca <- wind_vaca_raw %>%
mutate(station = "vacaville",
DATE = lubridate::floor_date(DATE, "hours")) %>%
group_by(DATE, station) %>%
summarise(HourlyWindSpeed)
wind_vaca <- wind_vaca[!duplicated(wind_vaca$DATE), ]
# sacramento airport
wind_sac <- wind_sac_raw %>%
mutate(station = "sacramento",
DATE = lubridate::floor_date(DATE, "hours")) %>%
group_by(DATE, station) %>%
summarise(HourlyWindSpeed)
wind_sac <- wind_sac[!duplicated(wind_sac$DATE), ]
# concord airport
wind_concord <- wind_concord_raw %>%
mutate(station = "concord",
DATE = lubridate::floor_date(DATE, "hours")) %>%
group_by(DATE, station) %>%
summarise(HourlyWindSpeed)
wind_concord <- wind_concord[!duplicated(wind_concord$DATE), ]
# combine dataframes
wind <- rbind(wind_vaca, wind_sac, wind_concord)
rm(wind_concord_raw, wind_concord, wind_sac_raw,wind_sac, wind_vaca_raw, wind_vaca)
```
```{r}
wind
class(wind)
lapply(wind, class)
```
## Calcualte average hourly wind speed for three stations
```{r}
wind_all <- wind %>%
group_by(DATE) %>%
summarize(HourlyWindSpeed = mean(HourlyWindSpeed)) %>%
mutate(station = "vaca_sac_concord")
# combine datasets
wind_join <- rbind(wind, wind_all)
wind_tsbl <- wind_join %>% as_tsibble(key = station)
```
https://blog.earo.me/2018/02/06/tsibble-or-tibbletime/
```{r}
# time period options: as.Date(.), yearweek(.), yearmonth(.), yearquarter(.), lubridate::floor_date(., "4 hour")
# interval = lubridate::floor_date(., "4 hours")
wind_avg <- wind_tsbl %>%
group_by_key() %>%
# every 2 hours
index_by(time = ~yearweek(.)) %>%
summarise(wind_speed = mean(HourlyWindSpeed, na.rm = TRUE)) %>%
na.omit()
wind_avg
```
```{r}
wind_avg %>%
filter(station == "vaca_sac_concord") %>%
ggplot(aes(x = time, y = wind_speed)) +
geom_line(color = "firebrick2", alpha = 0.5) +
geom_smooth() +
labs(title = "Average Hourly Wind Speed",
subtitle = "Cache Slough Complex, Solano County, California",
x = "Date",
y = "Wind Speed (mph)",
caption = "Source: NOAA NCEI. Station WBAN No. 93241, 23232, & 23254")
```
```{r}
decomp <- wind_avg %>%
filter(station == "vaca_sac_concord") %>%
model(classical_decomposition(wind_speed, type = "additive")) %>%
components() %>%
autoplot()
decomp
```