-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail_current.Rmd
238 lines (186 loc) · 7.73 KB
/
email_current.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
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
---
title: "Daily report of previous 10 days of data for the Madill site from Oklahoma Mesonet"
author: "Mike Proctor"
date: "`r format(Sys.Date(), '%B %d, %Y')`"
email: "[email protected]"
output:
html_document:
toc: true
toc_float: true
fig_caption: yes
theme: cerulean
code_folding: hide
df_print: paged
---
```{r Libraries, echo=TRUE, message=FALSE, warning=FALSE}
library(tidyverse)
library(lubridate)
library(magrittr)
library(rprojroot)
library("tidylog", warn.conflicts = FALSE)
library(blastula)
library(okmesonet)
library(plotly)
```
---
output: blastula::blastula_email
---
```{r Get data, echo=TRUE, message=FALSE, warning=FALSE}
yesterday <- duration("10 days") ## Set a period of one day
today <- duration("1 day") ## One day for daily pressure
bgin <- now()-yesterday ## Bgin is one day prior to right now
madill <- okmts(begintime=bgin, ## Retrieve specific fields
endtime=now(),
station = "MADI",
missingNA = TRUE,
localtime = TRUE,
variables = c("RELH",
"TAIR",
"WSPD",
"WDIR",
"WMAX",
"PRES",
"RAIN",
"TS05"
))
madill <- mutate(madill, TEMP = TAIR * 1.8 + 32, PPT = RAIN/25.4, SOIL_5cm = (TS05 * 1.8 + 32))## Convert to fahrenheit and inches
```
## Temperature
```{r Temperature, echo=TRUE, message=FALSE, warning=FALSE}
## ======================== Plot TEMP values============================
## Get min values
min.temp <- madill %>% mutate(day = format(TIME, "%d")) %>%
group_by(day) %>%
top_n(-1, TEMP)
temp.floor <- min.temp %>% distinct(TEMP, .keep_all = TRUE)
## Get maxvalues
max.temp <- madill %>% mutate(day = format(TIME, "%d")) %>%
group_by(day) %>%
top_n(1, TEMP)
temp.ceiling <- max.temp %>% distinct(TEMP, .keep_all = TRUE)
Temp_vals <-
ggplot(madill, aes(TIME, TEMP)) +
geom_line(color = "red", size = 0.5)+
scale_x_datetime(date_breaks = "1 day", date_labels = "%b %d") +
geom_text(data = temp.floor, aes(label = round(TEMP,0)), hjust = 1.5, color = "red") +
geom_text(data = temp.ceiling, aes(label = round(TEMP,0)), hjust = 1.5, color = "red") +
ggtitle(paste0("Temp values for past 10 days \nMadill - ", now()))
ggsave("plots/temp_vals.pdf", width = 10, height = 8)
print(Temp_vals)
```
## Preciptation
```{r Precipitation, echo=TRUE, message=FALSE, warning=FALSE}
## ======================== Plot PPT values============================
## Get max PPT values
ppt.rain <- madill %>% mutate(day = format(TIME, "%d")) %>%
group_by(day) %>%
top_n(1, PPT)
ppt.ceiling <- ppt.rain %>% distinct(PPT, .keep_all = TRUE)
ppt.label <- ppt.ceiling %>% filter(PPT > 0) ## Plot only works when it rains
PPT_vals <-
ggplot(ppt.rain, aes(TIME, PPT)) +
geom_line(color = "blue", size = 1.5)+
scale_x_datetime(date_breaks = "1 day", date_labels = "%b %d") +
geom_point(data = ppt.ceiling, aes(TIME, PPT)) +
# geom_text(data = ppt.label, aes(TIME, PPT,
# label = round(PPT,2),
# hjust = 1.2,
# vjust = -0.8),color = "blue") +
ggtitle(paste0("Precipitation for past 10 days \nMadill - ", now()))
ggsave("plots/ppt_vals.pdf", width = 10, height = 8)
print(PPT_vals)
```
## Humidity
```{r Relative Humidity, echo=TRUE, message=FALSE, warning=FALSE}
## Get min RH values
min.rh <- madill %>% mutate(day = format(TIME, "%d")) %>%
group_by(day) %>%
top_n(-1, RELH)
rh.floor <- min.rh %>% distinct(RELH, .keep_all = TRUE)
## Get max RH values
max.rh <- madill %>% mutate(day = format(TIME, "%d")) %>%
group_by(day) %>%
top_n(1, RELH)
rh.ceiling <- max.rh %>% distinct(RELH, .keep_all = TRUE)
RH_vals <-
ggplot(madill, aes(TIME, RELH)) +
geom_line(color = "green", size = 1) +
scale_x_datetime(date_breaks = "1 day", date_labels = "%b %d") +
geom_text(data = rh.floor, aes(label = round(RELH,0)), hjust = 1.5, color = "blue") +
geom_text(data = rh.ceiling, aes(label = round(RELH,0)), hjust = 1.5, color = "black") +
ggtitle(paste0("RH values for past 10 days \nMadill - ", now()))
ggsave("plots/rh_vals.pdf", width = 10, height = 8)
print(RH_vals)
```
## Pressure
```{r Barometric Pressure, echo=TRUE, message=FALSE, warning=FALSE}
## Current Barometric Pressure - last 24 hrs
one.day <- madill %>% filter(TIME >= (now() - today))
ggplot(one.day, aes(TIME, PRES)) +
geom_line(color = "black", size = 0.5) +
ggtitle(paste0("24hr Barometric Pressure"), max(one.day$TIME))
ggplot(madill, aes(TIME, PRES)) +
geom_line(color = "black", size = 1.2) +
ggtitle(paste0("Barometric Pressure for past 10 days \nMadill - ", now()))
minmaxPressure <- madill %>% select(TIME, PRES) %>%
group_by(day(TIME))
```
```{r Pressure value, echo=TRUE, message=FALSE, warning=FALSE, paged.print=TRUE}
pressureTail <- tail(minmaxPressure, 50)
#print(pressureTail)
pressureTail
```
## Soil Temperature
```{r Soil Temps, echo=TRUE, message=FALSE, warning=FALSE}
## Soil temps
soilPlot <- ggplot(madill, aes(TIME, SOIL_5cm)) +
geom_point(color = "red", size = 1.5)+
ggtitle(paste0("2\" Soil temps for past 10 days \nMadill - ", now()))
ggplotly(soilPlot)
```
## Wind Velocity
```{r Wind, echo=TRUE, message=FALSE, warning=FALSE}
## Get max WIND values
max.wspd <- madill %>% mutate(day = format(TIME, "%d")) %>%
group_by(day) %>%
top_n(1, WMAX)
wmax.ceiling <- max.wspd %>% distinct(WSPD, .keep_all = TRUE)
ggplot(madill, aes(TIME, WSPD)) +
geom_line(color = "blue4", size = 0.8) +
geom_line(aes(y = WMAX), color = "magenta3", size = 0.5) +
scale_x_datetime(date_breaks = "1 day", date_labels = "%b %d") +
geom_point(data = wmax.ceiling, aes(TIME, WMAX)) +
geom_text(data = wmax.ceiling, aes(TIME, WMAX,
label = WMAX,
hjust = 1.2,
vjust = -0.8),color = "blue") +
ggtitle(paste0("Wind values for past 10 days \nMadill - ", now()))
```
## Wind Direction and Counts
```{r Wind direction, echo=TRUE, message=FALSE, warning=FALSE}
## Breaks and labels for plots
brks <- c(0, 45, 90, 135, 180, 225, 270, 315, 360)
lbls <- c("N", "NE", "E", "SE", "S", "SW", "W", "NW")
## Extract month and day for facet_wrap
madill <- mutate(madill, re.day = paste0(month(TIME), "-", day(TIME)))
## Create df specifically for wind data
wind <- madill %>% ## Set up bins, rotate coord system, and summarise
filter(is.na(WDIR) == FALSE, is.na(WSPD) == FALSE) %>%
mutate(WDIR2 = (WDIR + 360/8/2) %% 360) %>%
mutate(dir.bin = cut(WDIR2, breaks = brks, labels = lbls)) %>%
group_by(dir.bin, re.day) %>% ## Group on re.day for facet_wrap
summarise(dir.count = n(), med.spd = median(WSPD), avg = mean(WSPD))
## Histogram of wind data
wind.bar <- ggplot(wind, aes(dir.bin, dir.count, fill = avg)) +
geom_histogram(stat = "identity") +
scale_fill_distiller(palette = "Reds")
wind.bar
## Wind.rose of wind data
wind.rose <- ggplot(wind, aes(dir.bin, dir.count, fill = avg)) +
geom_histogram(stat = "identity") +
scale_fill_distiller(palette = "Reds") +
coord_polar(start = -(22.5 * pi/180)) +
theme(axis.title.x = element_blank(), axis.title.y = element_blank()) +
facet_wrap(~ re.day, nrow = 2)
wind.rose
```