-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather.Rmd
271 lines (231 loc) · 8.62 KB
/
weather.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
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
---
title: "MPG Ranch Weather"
output:
flexdashboard::flex_dashboard:
theme: spacelab
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(plotly)
library(lubridate)
library(readr)
library(DT)
library(leaflet)
library(colorspace)
```
```{r load_data, include = FALSE}
weather_df <- read_csv('https://storage.googleapis.com/mpg-data-warehouse/weather_summaries/mpg_ranch_daily/weather_daily_cache.csv')
stations_df <- read_csv('https://storage.googleapis.com/mpg-data-warehouse/weather/MPG/station_meta/weather_station_location.csv')
pal <- sequential_hcl(palette = "Batlow", n = 6)
station_cols <- scale_color_manual(
name = "Stations:",
values = c("Baldy Draw" = pal[1],
"Baldy Summit" = pal[2],
"Indian Ridge" = pal[3],
"Orchard House" = pal[4],
"Sanfoin Bench" = pal[5],
"South Baldy Ridge" = pal[6])
)
station_fills <- scale_fill_manual(
name = "Stations",
values = c("Baldy Draw" = pal[1],
"Baldy Summit" = pal[2],
"Indian Ridge" = pal[3],
"Orchard House" = pal[4],
"Sanfoin Bench" = pal[5],
"South Baldy Ridge" = pal[6])
)
theme_text_col = "gray35"
theme_weather =
theme_bw() +
theme(
axis.title.y = element_text(size = 12, color = theme_text_col, margin = unit(c(t = 0, r = 4, b = 0, l = 0 ), "mm")),
axis.text.x = element_text(size = 10, color = theme_text_col, margin = unit(c(t = 4, r = 0, b = 0, l = 0 ), "mm")),
axis.text.y = element_text(size = 10, color = theme_text_col, margin = unit(c(t = 0, r = 3, b = 0, l = 0 ), "mm")),
axis.ticks.length = unit(-1.5, "mm"),
strip.text = element_text(size = 12, color = "gray15"),
strip.background = element_rect(fill = "lightsteelblue2"),
plot.caption = element_text(size = 10, color = theme_text_col),
legend.text = element_text(size = 12, color = theme_text_col),
legend.title = element_text(size = 12, color = theme_text_col),
legend.position = "top",
panel.grid.minor = element_blank()
)
```
Sidebar {.sidebar data-width=250}
=====================================
```{r}
dateRangeInput("date_range",
label = "Date range:",
start = "2013-01-01",
end = Sys.Date() - 1,
max = Sys.Date() - 1,
min = "2013-01-01")
selectInput("station",
"Select station:",
choices = c("Baldy Draw", "Baldy Summit", "Indian Ridge",
"Orchard House", "Sanfoin Bench", "South Baldy Ridge"),
selected = c("Baldy Summit", "Orchard House"),
multiple = TRUE)
sliderInput("day_slider",
label = "Day Range by Year:",
min = 1,
max = 366,
value = c(1,366),
step = 1)
show_weather_df <- reactive({
weather_df %>%
select(-X1) %>%
filter(date_day >= min(input$date_range) &
date_day <= max(input$date_range)) %>%
filter(station %in% if(is.null(input$station)) {'Orchard House'} else {input$station}) %>%
mutate(doy = yday(date_day)) %>%
filter(doy >= min(input$day_slider) &
doy <= max(input$day_slider))
})
show_stations_df <- reactive({
stations_df %>%
filter(station %in% input$station)
})
# Create placeholder for the download Button
uiOutput("downloadUI")
# Create the actual download Button
output$downloadUI <- renderUI({
downloadButton("downBtn", "Download *.csv", style = "width:100%;")
})
# Add download handling
output$downBtn <- downloadHandler(
filename = function() {
paste('mpg_weather-', min(input$date_range), '_', max(input$date_range), '.csv', sep='')
},
content = function(file) {
write.csv(show_weather_df(), file, row.names = FALSE)
}
)
```
Plots
=====================================
Column {.tabset data-width=750}
-----------------
### Temperature
```{r}
renderPlot({
show_weather_df() %>%
select(date_day, station, temp_F_mean) %>%
arrange(date_day) %>%
mutate(
year = year(date_day),
doy = yday(date_day),
axis_date = as.Date(paste0("2000-",format(date_day, "%j")), "%Y-%j")
) %>%
ggplot(aes(x=axis_date, y=temp_F_mean)) +
geom_line(aes(colour = station), size = 0.8) +
facet_grid(vars(year), as.table = FALSE) +
labs(x = "", y = expression(Average~Temperature~"("*degree*F*")")) +
scale_x_date(labels = function(x) format(x, "%b-%d")) +
station_cols +
theme_weather
})
```
### Precipitation
```{r}
renderPlot({
show_weather_df() %>%
arrange(date_day) %>%
mutate(
year = year(date_day),
doy = yday(date_day),
axis_date = as.Date(paste0("2000-",format(date_day, "%j")), "%Y-%j")
) %>%
group_by(year, station) %>%
mutate(precip_in = cumsum(precip_in_sum)) %>%
ungroup() %>%
ggplot(aes(x = axis_date, y = precip_in, group = station)) +
geom_step(aes(color = station), size = 0.8) +
facet_grid(vars(year), as.table = FALSE) +
labs(x = "", y = "Cumulative Rainfall (in)", caption = "Note: the weather stations do not measure snow-water-equivalent. Values shown here depict rainfall, with trivial contributions from snow.") +
scale_x_date(labels = function(x) format(x, "%b-%d")) +
station_cols +
theme_weather
})
```
### Wind Speed
```{r}
renderPlot({
show_weather_df() %>%
select(date_day, station, wspd_mph_mean) %>%
arrange(date_day) %>%
mutate(
year = year(date_day),
doy = yday(date_day),
axis_date = as.Date(paste0("2000-",format(date_day, "%j")), "%Y-%j")
) %>%
ggplot(aes(x=axis_date, y=wspd_mph_mean)) +
geom_line(aes(colour = station), size = 0.8) +
facet_grid(vars(year), as.table = FALSE) +
labs(x = "", y = "Average Wind Speed (mph)") +
scale_x_date(labels = function(x) format(x, "%b-%d")) +
station_cols +
theme_weather
})
```
### Wind Direction
```{r}
ordinal_directions <- c('N', 'E', 'S', 'W', 'N')
renderPlot({
show_weather_df() %>%
select(date_day, station, wdir_deg_prevail) %>%
arrange(date_day) %>%
mutate(
year = year(date_day),
doy = yday(date_day),
axis_date = as.Date(paste0("2000-",format(date_day, "%j")), "%Y-%j")
) %>%
ggplot(aes(x=axis_date, y=wdir_deg_prevail, group = station)) +
geom_point(aes(fill = station), shape = 21, color = "black", stroke = 0.4, alpha = 0.7, size = 1.6) +
facet_grid(vars(year), as.table = FALSE) +
labs(x = "", y = "Prevailing Wind Direction") +
scale_x_date(labels = function(x) format(x, "%b-%d")) +
scale_y_continuous(labels = ordinal_directions, breaks = (0:4) * 90, limits = c(0, 360)) +
station_fills +
theme_weather
})
```
Table
=====================================
```{r}
renderDataTable({
datatable(
show_weather_df() %>% select(-doy),
rownames = FALSE,
options = list(scrollY = '400px', scrollX = TRUE)
)
})
```
Map
=====================================
```{r}
leaflet() %>%
# addTiles() %>%
setView(-114.001, 46.70, zoom = 13) %>%
addWMSTiles("https://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}",
layers = "OpenTopoMap") %>%
addMarkers(lat = stations_df$lat, lng = stations_df$long,
popup = paste0(popup = paste0(
"<strong>Station: </strong>", stations_df$station, "<br>",
"<strong>Elevation: </strong>", stations_df$elevation, " ft")),
label = stations_df$station)
```
About
=====================================
#### Intention
MPG Ranch has tools which display weather data, but none of them allow general users to download data for their own use. In this application, users may filter, view, and *download* weather data from MPG Ranch weather stations.
#### Description
The data are collected from six weather stations, ranging from 3218 to 5994 ft in elevation. The stations record weather variables every 30 minutes. These observations are then loaded into the MPG Ranch Data Warehouse and compiled into daily values. Data included here begin on January 1, 2013, and new data are appended daily.
Leap years have 366 days. Users should account for this when processing downloaded data.
Known missing data are displayed [here](https://datastudio.google.com/reporting/c55060be-c84b-4547-8556-5107f9a51813){target="_blank"}.
Thank you Nick and Gus for setting up and maintaining the weather stations.
#### Feedback
We appreciate suggestions. Please contact Beau and Erik with any feedback. If you would like to report bugs or issues, or would like to be involved with development, join us on [GitHub](https://github.com/samsoe/mpg_shiny/issues){target="_blank"}.