Open zrubinstein opened 7 years ago
mac <- etl("macleish") %>% etl_update()
whately <- mac %>% tbl("whately") %>% collect(n = Inf) %>% select(when, temperature)
orchard <- mac %>% tbl("orchard") %>% collect(n = Inf) %>% select(when, temperature)
whately <- whately %>% separate(col = when, into = c("when", "time"), sep = "T", remove = TRUE)
weather1 <-inner_join(whately, orchard, by="when")
weather1<-weather1 %>% separate(col = when, into = c("when", "time"), sep = "T", remove = TRUE) weather1<-weather1 %>% rename(whately=temperature.x, orchard = temperature.y) %>%
weather1<-weather1 %>%
filter(time=="00:00:00Z"| time=="04:00:00Z" | time== "08:00:00Z" | time=="12:00:00Z" | time== "16:00:00Z" | time== "20:00:00Z")
weather1<-mutate(weather1, temp=(orchard+whately)/2)
whately <- mac %>%
tbl("whately") %>%
collect(n = Inf) %>%
select(when, temperature)
orchard <- mac %>%
tbl("orchard") %>%
collect(n = Inf) %>%
select(when, temperature)
weather <- inner_join(whately, orchard, by="when") %>%
separate(col = when, into = c("when", "time"), sep = "T", remove = TRUE) %>%
rename(whately=temperature.x, orchard = temperature.y)
weather <- weather %>%
mutate(temp = (orchard+whately)/2) %>%
select(when, time, temp)
weather_day <- weather %>%
filter(time== "08:00:00Z" | time=="12:00:00Z" | time== "16:00:00Z" | time== "20:00:00Z") %>%
group_by(when) %>%
summarize(avg_day_temp = mean(temp))
weather_night <- weather %>%
filter(time=="00:00:00Z"| time=="04:00:00Z" | time== "16:00:00Z" | time== "20:00:00Z") %>%
group_by(when) %>%
summarize(avg_night_temp = mean(temp))
weather_all <- inner_join(weather_day, weather_night, by="when")
'##Denote Day Temp and Night Temp weather_day <- weather %>% filter(time== "08:00:00Z" | time=="12:00:00Z" | time== "16:00:00Z" | time== "20:00:00Z") %>% group_by(when) %>% summarize(avg_day_temp = mean(temp))
weather_night <- weather %>% filter(time=="00:00:00Z"| time=="04:00:00Z" | time== "16:00:00Z" | time== "20:00:00Z") %>% group_by(when) %>% summarize(avg_night_temp = mean(temp))
weather_all <- inner_join(weather_day, weather_night, by="when") weather_all<-mutate(weather_all, when=as.Date(when))
melted_day<-select(weather_all, avg_day_temp, when) melted_day<-melt(melted_day, id.vars=c("when"), variable.name="ToD", value.name="temperature")
melted_night<-select(weather_all, avg_night_temp, when) melted_night<-melt(melted_night, id.vars=c("when"), variable.name="ToD", value.name="temperature")
full<-rbind(melted_day, melted_night) full<-arrange(full, when)'
need to include library(reshape2) to melt
Spacial Data of Maple Forest -
bechtel <- data.frame(lat = 42.449167, lon = -72.679389)
forest_pal <- colorFactor("Greens", macleish_layers[["forests"]]$Sheet1__Na == 9)
leaflet() %>%
addTiles(group = "OpenStreetMap") %>% addProviderTiles("Esri.WorldTopoMap", group = "Topography") %>% addProviderTiles("Esri.WorldImagery", group = "Satellite") %>% addProviderTiles("Stamen.TonerLite", group = "Toner Lite") %>%
addPolygons(data = macleish_layers[["boundary"]], weight = 1, fillOpacity = 0.01, group = "Boundaries") %>%
addPolygons(data = macleish_layers[["forests"]], color = ~forest_pal(Sheet1Na == 9), weight = 0.1, fillOpacity = 0.2, popup = ~ Sheet1Na == 9, group = "Natural") %>%
addLayersControl( baseGroups = c("OpenStreetMap", "Topography", "Satellite", "Toner Lite"), overlayGroups = c("Boundaries", "Natural"), options = layersControlOptions(collapsed = FALSE) ) %>% setView(lat = bechtel$lat, lng = bechtel$lon, zoom = 15) m
summary(macleish_layers[["forests"]])
temp_plot <- ggplot(data = full) +
geom_point(aes(x = when, y = temperature, color = ToD), alpha = 0.5) +
geom_line(aes(x = when, y = 0))
temp_plot
full2<- inner_join(full, maple_sap)
full3<-full2 %>% separate(col = when, into = c("year", "month", "day"), sep = "-", remove = TRUE) yr2015<-filter(full3, year=="2015")
Problem Statement: We are examining potential start and end dates for sugaring season. Temperatures must be above freezing during the day and below freezing at night, in order for sap to run. By combining weather data with maple_sap data, the follow graphics illustrate our findings about the sugaring season.
full3<-full2 %>% separate(col = when, into = c("year", "month", "day"), sep = "-", remove = TRUE) full4<- full3 %>%
yr2015<-filter(full3, year=="2015") yr2016<-filter(full3, year=="2016") yr2017<-filter(full3, year=="2017")
##Visualization
```{r}
temp_plot <- ggplot(data = full) +
geom_point(aes(x = when, y = temperature, color = ToD), alpha = 0.5) +
geom_line(aes(x = when, y = 0))
temp_plot
ggplot(data=yr2015) + geom_point(aes(x=day, y=sap))
ggplot(data=yr2016) + geom_point(aes(x=day, y=sap))
ggplot(data=yr2017) + geom_point(aes(x=day, y=sap))
In New England, farmers are generally out in the woods from late February through early April tapping maple trees for their sap. It takes up to 40 gallons of sap from a tree to make just one gallon of syrup (Source 1). In 2016, Massachusetts had 315,000 taps with a yield per tap of 0.244 gallons and produced 77,000 gallons of syrup.
Source 1: http://www.discovernewengland.org/things-do/new-englands-maple-sugaring-season Source 2: https://www.nass.usda.gov/Statistics_by_State/New_England_includes/Publications/Current_News_Release/2016/Maple.pdf
Actionable Recommendation: Our suggestion is that Smith taps the maple trees between and in order to obtain the maximum yields.
Visualizations:
temp_plot <- ggplot(data = full) +
geom_point(aes(x = when, y = temperature, color = ToD), alpha = 0.5) +
geom_line(aes(x = when, y = 0))
temp_plot
## October to April
oct15_apr16 <-full %>%
filter(grepl("(2015-(10|11|12))|(2016-(01|02|03|04))",when))
oct15_apr16_plot <-ggplot(data = oct15_apr16) +
geom_point(aes(x = when, y = temperature, color = ToD), alpha = 0.5) +
geom_line(aes(x = when, y = 0))
oct15_apr16_plot
## Februrary to April
feb_apr <-full %>%
filter(grepl("(2016-(02|03|04))",when))
feb_apr_plot <-ggplot(data = feb_apr) +
geom_point(aes(x = when, y = temperature, color = ToD), alpha = 0.5) +
geom_line(aes(x = when, y = 0))
feb_apr_plot
## Combine month and day columns in full3 df
full3_date <- full3 %>%
mutate(month_day = paste(month, day, sep = '-')) %>%
select(year, month_day, ToD, temperature, sap)
(to be added to the map)
in the future: it would be extremely beneficial to have, within the "forest" Macleish package, marked trees that are being tapped. Then within our map we could annotate where each tree is being tapped and look more into temperatures at those specific points and project future tapping locations.
bechtel <- data.frame(lat = 42.449167, lon = -72.679389)
forest_pal <- colorFactor("Greens", macleish_layers[["forests"]]$Sheet1__Na == 9)
leaflet() %>%
## Base groups
addTiles(group = "OpenStreetMap") %>%
addProviderTiles("Esri.WorldTopoMap", group = "Topography") %>%
addProviderTiles("Esri.WorldImagery", group = "Satellite") %>%
addProviderTiles("Stamen.TonerLite", group = "Toner Lite") %>%
## Boundaries of Property
addPolygons(data = macleish_layers[["boundary"]], weight = 1, fillOpacity = 0.01, group = "Boundaries") %>%
## Natural elements, filtering for Sugar Maple Forest
addPolygons(data = macleish_layers[["forests"]],
color = ~forest_pal(Sheet1__Na == 9), weight = 0.1,
fillOpacity = 0.2,
popup = ~ Sheet1__Na == 9, group = "Natural") %>%
## Layers control
addLayersControl(
baseGroups = c("OpenStreetMap", "Topography", "Satellite", "Toner Lite"),
overlayGroups = c("Boundaries", "Natural"),
options = layersControlOptions(collapsed = FALSE)
) %>%
setView(lat = bechtel$lat, lng = bechtel$lon, zoom = 15)
m
##Including data frame that we pulled data from ("forests" within MacLeish spatial data)
summary(macleish_layers[["forests"]])
##in the futurue: it would be extremely beneficial to have, within the "forest" Macleish package, marked trees that are being tapped. Then within our map we could annotate where each tree is being tapped and look more into temperatures at those specific points and project future tapping locations.
maple_sap <- maple_sap %>% select(when, sap) %>% filter(!is.na(sap))