-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWunderground_Weather_Data.Rmd
167 lines (148 loc) · 5.4 KB
/
Wunderground_Weather_Data.Rmd
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
---
title: "Weather Underground Data Analysis and Wind Roses"
author: "Lourdes Vera"
date: "2/15/2021"
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
#Load the packages you installed
library(tidyverse)
library(datetime)
library(rvest)
library(vctrs)
```
```{r}
df <- read.csv("DF_All.csv")
```
#Format date and time
```{r}
#format the date and time
df$Date <- as.date(df$date)
df$Time2 <- format(strptime(df$Time, "%I:%M %p"), format = "%H:%M:%S")
```
```{r}
#concatenate date and time
df$Datetime <- paste0(df$Date, " ", df$Time2)
```
```{r}
df$Datetime <- as.POSIXct(df$Datetime, format="%Y-%m-%d%H:%M", tz = "America/Chicago")
```
```{r}
df$Datetime <- round(df$Datetime, "hours")
```
#Format Weather Data
```{r}
#temperature
df$Temperature <- str_sub(df$Temperature, start=1, end=4)
df$Temperature <- as.numeric(df$Temperature)
#humidity
df$Humidity <- str_sub(df$Humidity, start=1, end=2)
df$Humidity <- as.numeric(df$Humidity)
#windspeed
df$ws <- str_sub(df$Speed, end=-5)
df$ws <- str_trim(df$ws)
df$ws <- as.numeric(df$ws)
```
#Keep complete data
```{r}
df$Datetime <- as.POSIXct(df$Datetime , format="%Y-%m-%d%H:%M")
```
#
```{r}
#Wind direction
df$WindNumber <- NA
df[which(df$Wind == "East"),c("WindNumber")] <- 90
df[which(df$Wind == "West"),c("WindNumber")] <- 270
df[which(df$Wind == "WNW"),c("WindNumber")] <- 292.5
df[which(df$Wind == "NW"),c("WindNumber")] <- 315
df[which(df$Wind == "North"),c("WindNumber")] <- 0
df[which(df$Wind == "NE"),c("WindNumber")] <- 45
df[which(df$Wind == "ENE"),c("WindNumber")] <- 67.5
df[which(df$Wind == "South"),c("WindNumber")] <- 180
df[which(df$Wind == "SE"),c("WindNumber")] <- 135
df[which(df$Wind == "SSE"),c("WindNumber")] <- 157.5
df[which(df$Wind == "SSW"),c("WindNumber")] <- 202.5
df[which(df$Wind == "ESE"),c("WindNumber")] <- 112.5
df[which(df$Wind == "WSW"),c("WindNumber")] <- 247.5
df[which(df$Wind == "NNE"),c("WindNumber")] <- 22.5
df[which(df$Wind == "NNW"),c("WindNumber")] <- 337.5
df[which(df$Wind == "SW"),c("WindNumber")] <- 225
#make wind direction numeric
df$wd <- as.numeric(df$WindNumber)
```
```{r}
dfwinddatetime <- df %>% group_by(Datetime) %>%
summarise(mean = mean(wd, na.rm = TRUE), ws = mean(ws, na.rm = TRUE))
```
```{r}
#Wind direction
dfwinddatetime$Wind <- "NA"
dfwinddatetime[which(dfwinddatetime$mean >= 0 & dfwinddatetime$mean < 22.5| dfwinddatetime$mean >= 337.5 & dfwinddatetime$mean <= 360),c("Wind")] <- "North"
dfwinddatetime[which(dfwinddatetime$mean >= 22.5 & dfwinddatetime$mean < 67.5),c("Wind")] <- "Northeast"
dfwinddatetime[which(dfwinddatetime$mean >= 67.5 & dfwinddatetime$mean < 112.5),c("Wind")] <- "East"
dfwinddatetime[which(dfwinddatetime$mean >= 112.5 & dfwinddatetime$mean < 157.5),c("Wind")] <- "Southeast"
dfwinddatetime[which(dfwinddatetime$mean >= 157.5 & dfwinddatetime$mean < 202.5),c("Wind")] <- "South"
dfwinddatetime[which(dfwinddatetime$mean >= 202.5 & dfwinddatetime$mean < 247.5),c("Wind")] <- "Southwest"
dfwinddatetime[which(dfwinddatetime$mean >= 247.5 & dfwinddatetime$mean < 292.5),c("Wind")] <- "West"
dfwinddatetime[which(dfwinddatetime$mean >= 292.5 & dfwinddatetime$mean < 337.5),c("Wind")] <- "Northwest"
```
```{r}
write.csv(dfwinddatetime, "dfwinddatetime_VOC.csv")
```
#format dates and times again
```{r}
dfwinddatetime$Datetime <- as.POSIXct(dfwinddatetime$Datetime , format="%Y-%m-%d%H:%M")
```
```{r}
library(openair)
```
```{r}
df <- dfwinddatetime
df<- df[complete.cases(df),]
df$Datetime <- as.POSIXct(df$Datetime)
```
#SEPARATE ROUNDS
```{r}
#round2
round2 <- df[df$Datetime>="2020-02-23 10:22:00" & df$Datetime<="2020-03-01 15:18:00",]
#round 3
round3 <- df[df$Datetime>="2020-04-05 12:00:00" & df$Datetime<="2020-04-12 16:35:00",]
#round 4
round4 <- df[df$Datetime>="2020-04-25 09:56:00" & df$Datetime<="2020-05-02 08:32:59",]
```
#Weather Round 1
```{r}
windRose(round2, ws = "ws", wd = "mean", ws2 = NA, wd2 = NA,
ws.int = 3, angle = 30, type = "default", bias.corr = TRUE, cols
= "default", grid.line = NULL, width = 1, seg = NULL, auto.text
= TRUE, breaks = 6, offset = 10, normalise = FALSE, max.freq =
NULL, paddle = TRUE, key.header = NULL, key.footer = "mph",
key.position = "bottom", key = TRUE, dig.lab = 5, statistic =
"prop.count", pollutant = NULL, annotate = TRUE, angle.scale =
315, border = NA)
```
#Weather Round 2
```{r}
windRose(round3, ws = "ws", wd = "mean", ws2 = NA, wd2 = NA,
ws.int = 3, angle = 30, type = "default", bias.corr = TRUE, cols
= "default", grid.line = NULL, width = 1, seg = NULL, auto.text
= TRUE, breaks = 6, offset = 10, normalise = FALSE, max.freq =
NULL, paddle = TRUE, key.header = NULL, key.footer = "mph",
key.position = "bottom", key = TRUE, dig.lab = 5, statistic =
"prop.count", pollutant = NULL, annotate = TRUE, angle.scale =
315, border = NA)
```
#Weather Round 3
```{r}
windRose(round4, ws = "ws", wd = "mean", ws2 = NA, wd2 = NA,
ws.int = 3, angle = 30, type = "default", bias.corr = TRUE, cols
= "default", grid.line = NULL, width = 1, seg = NULL, auto.text
= TRUE, breaks = 6, offset = 10, normalise = FALSE, max.freq =
NULL, paddle = TRUE, key.header = NULL, key.footer = "mph",
key.position = "bottom", key = TRUE, dig.lab = 5, statistic =
"prop.count", pollutant = NULL, annotate = TRUE, angle.scale =
315, border = NA)
```