From d3db7057a58c54e2aadc22fe113f25e041fa3872 Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Thu, 10 Jul 2025 23:06:15 -0400 Subject: [PATCH] add landfall map to all storms --- dashboard.Rmd | 247 ++++++++++++++++++++++++++++++-------------------- queries.R | 15 +++ 2 files changed, 165 insertions(+), 97 deletions(-) diff --git a/dashboard.Rmd b/dashboard.Rmd index 1e3ecb6..d1101a6 100644 --- a/dashboard.Rmd +++ b/dashboard.Rmd @@ -104,6 +104,11 @@ loss_storms <- get_all_loss_storms() latest_normalized_losses <- get_latest_aggregate_losses() +all_storm_tracks <- get_all_hurdat_tracks() + +all_storm_landfalls <- all_storm_tracks %>% + filter(record_identifier == "L") + storm_selection <- reactiveValues( storm_year = NULL, storm_name = NULL, @@ -621,103 +626,7 @@ fillCol( Storm Fatalities {data-navmenu="Storm Details"} === -Fatalities {data-navmenu="Fatalities"} -=== -Column {data-width=500} ---- - -### {data-height=500} -```{r} -fatality_years <- seq(1900, 2010, by = 10) -direct_deaths <- c(6000, 275, 0, 408, 26, 654, 466, 213, 104, 228, 1136, 321) -indirect_deaths <- c(0, 0, 0, 0, 0, 1, 8, 15, 40, 54, 1171, 368) - -yearly_fatalities <- data.frame(fatality_years, direct_deaths, indirect_deaths) %>% - mutate( - fatality_years = as.Date(paste0(fatality_years, "-01-01")) - ) - -yearly_fatalities_ts <- yearly_fatalities %>% - select(-fatality_years) %>% - xts(order.by = yearly_fatalities$fatality_years) - -output$decade_fatalities <- renderDygraph( - dygraph(yearly_fatalities_ts, main = "Fatalities By Decade") %>% - dySeries("direct_deaths", label = "Direct Deaths") %>% - dySeries("indirect_deaths", label = "Indirect Deaths") %>% - dyRangeSelector() -) - -dygraphOutput("decade_fatalities") -``` - -### {data-height=500} -```{r} -surge_yearly <- c(0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 410, 107) -surf_yearly <- c(0, 0, 0, 0, 0, 0, 0, 14, 2, 12, 12, 17) -rough_seas_yearly <- c(0, 0, 0, 0, 16, 0, 2, 0, 24, 17, 0, 14) -rip_current_yearly <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 14, 3) -freshwater_floods_yearly <- c(0, 0, 0, 0, 0, 200, 12, 151, 0, 117, 50, 284) -wind_yearly <- c(0, 0, 0, 0, 0, 0, 0, 8, 14, 23, 11, 82) -tree_fall_yearly <- c(0, 0, 0, 0, 1, 0, 0, 1, 0, 9, 24, 56) -tornado_yearly <- c(0, 0, 0, 0, 1, 12, 43, 7, 0, 7, 11, 7) -traffic_yearly <- c(0, 0, 0, 0, 0, 0, 0, 4, 0, 3, 2, 1) -traffic_accident_yearly <- c(0, 0, 0, 0, 0, 0, 5, 0, 0, 8, 26, 11) -electrocution_yearly <- c(0, 0, 0, 0, 0, 0, 2, 0, 0, 5, 2, 7) -other_yearly <- c(0, 0, 0, 0, 5, 0, 5, 11, 15, 13, 37, 7) - -yearly_fatalities_type <- data.frame(fatality_years, surge_yearly, surf_yearly, rough_seas_yearly, rip_current_yearly, freshwater_floods_yearly, wind_yearly, tree_fall_yearly, tornado_yearly, traffic_yearly, traffic_accident_yearly, electrocution_yearly, other_yearly) %>% - mutate( - fatality_years = as.Date(paste0(fatality_years, "-01-01")) - ) - -yearly_fatalities_type_ts <- yearly_fatalities_type %>% - select(-fatality_years) %>% - xts(order.by = yearly_fatalities_type$fatality_years) - -output$decade_fatalities_type <- renderDygraph( - dygraph(yearly_fatalities_type_ts, main = "Fatality Types By Decade") %>% - dySeries("surge_yearly", label = "Surge") %>% - dySeries("surf_yearly", label = "Surf") %>% - dySeries("rough_seas_yearly", label = "Rough Seas") %>% - dySeries("rip_current_yearly", label = "Rip Current") %>% - dySeries("freshwater_floods_yearly", label = "Freshwater Floods") %>% - dySeries("wind_yearly", label = "Wind") %>% - dySeries("tree_fall_yearly", label = "Tree Fall") %>% - dySeries("tornado_yearly", label = "Tornado") %>% - dySeries("traffic_yearly", label = "Traffic") %>% - dySeries("traffic_accident_yearly", label = "Traffic Accident") %>% - dySeries("electrocution_yearly", label = "Electrocution") %>% - dySeries("other_yearly", label = "Other") %>% - dyRangeSelector() -) - -dygraphOutput("decade_fatalities_type") -``` - -Column {data-width=500} ---- - -### {data-height=500} -```{r} -fatality_type <- c("Surge", "Surf", "Rough Seas", "Rip Current", "Floods", "Wind", "Tree Fall", "Tornado", "Traffic", "Traffic Accident", "Electrocution", "Other") -fatality_totals <- c(520, 56, 77, 23, 826, 131, 91, 88, 10, 45, 16, 56) - -aggregate_fatality_types <- data.frame(fatality_type, fatality_totals) - -output$aggregate_fatalities <- renderBillboarder( - billboarder() %>% - bb_piechart(aggregate_fatality_types) - #%>% bb_legend(position = "right") -) - -billboarderOutput("aggregate_fatalities") -``` - -### {data-height=500} -```{r} -``` Normalization Calculator {data-navmenu="Compute"} @@ -826,8 +735,13 @@ fillCol( Data Export {data-navmenu="Compute"} === -All Storms Table +Tracked Storms {data-navmenu="All Storms"} === + +Column {data-width=650} +--- + +### {} ```{r} #DT with storm, hurdatid, base damage, mmh, mmp, maybe multipliers?, sparkline? @@ -856,5 +770,144 @@ DTOutput("normalized_storms_full_table") ``` +Column {data-width=350} +--- + +### {.no-padding} +```{r} +output$all_storms_map <- renderLeaflet({ + leaflet() %>% + addProviderTiles("CartoDB.Positron", option = providerTileOptions(minZoom = 2, maxZoom = 18)) %>% + # %>% setView(lng = -89.8, lat = 29.6, zoom = 8) + #addPolylines( + #data = all_storm_tracks, + #lng = ~lon, + #lat = ~lat, + #weight = .5, + #color = "blue" + #) %>% + addCircleMarkers( + data = all_storm_landfalls, + lng = ~lon, + lat = ~lat, + radius = 5, + weight = 0, + color = "red", + fillColor = "red", + fillOpacity = 0.8 + ) %>% + addCircles( + data = all_storm_landfalls, + lng = ~lon, + lat = ~lat, + radius = ~rmw_meters, + weight = 2, + color = "red", + fillColor = "red", + fillOpacity = 0.3 + ) +}) + +leafletOutput("all_storms_map") +``` + +Fatalities {data-navmenu="All Storms"} +=== + +Column {data-width=500} +--- + +### {data-height=500} +```{r} +fatality_years <- seq(1900, 2010, by = 10) +direct_deaths <- c(6000, 275, 0, 408, 26, 654, 466, 213, 104, 228, 1136, 321) +indirect_deaths <- c(0, 0, 0, 0, 0, 1, 8, 15, 40, 54, 1171, 368) + +yearly_fatalities <- data.frame(fatality_years, direct_deaths, indirect_deaths) %>% + mutate( + fatality_years = as.Date(paste0(fatality_years, "-01-01")) + ) + +yearly_fatalities_ts <- yearly_fatalities %>% + select(-fatality_years) %>% + xts(order.by = yearly_fatalities$fatality_years) + +output$decade_fatalities <- renderDygraph( + dygraph(yearly_fatalities_ts, main = "Fatalities By Decade") %>% + dySeries("direct_deaths", label = "Direct Deaths") %>% + dySeries("indirect_deaths", label = "Indirect Deaths") %>% + dyRangeSelector() +) + +dygraphOutput("decade_fatalities") +``` + +### {data-height=500} +```{r} +surge_yearly <- c(0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 410, 107) +surf_yearly <- c(0, 0, 0, 0, 0, 0, 0, 14, 2, 12, 12, 17) +rough_seas_yearly <- c(0, 0, 0, 0, 16, 0, 2, 0, 24, 17, 0, 14) +rip_current_yearly <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 14, 3) +freshwater_floods_yearly <- c(0, 0, 0, 0, 0, 200, 12, 151, 0, 117, 50, 284) +wind_yearly <- c(0, 0, 0, 0, 0, 0, 0, 8, 14, 23, 11, 82) +tree_fall_yearly <- c(0, 0, 0, 0, 1, 0, 0, 1, 0, 9, 24, 56) +tornado_yearly <- c(0, 0, 0, 0, 1, 12, 43, 7, 0, 7, 11, 7) +traffic_yearly <- c(0, 0, 0, 0, 0, 0, 0, 4, 0, 3, 2, 1) +traffic_accident_yearly <- c(0, 0, 0, 0, 0, 0, 5, 0, 0, 8, 26, 11) +electrocution_yearly <- c(0, 0, 0, 0, 0, 0, 2, 0, 0, 5, 2, 7) +other_yearly <- c(0, 0, 0, 0, 5, 0, 5, 11, 15, 13, 37, 7) + +yearly_fatalities_type <- data.frame(fatality_years, surge_yearly, surf_yearly, rough_seas_yearly, rip_current_yearly, freshwater_floods_yearly, wind_yearly, tree_fall_yearly, tornado_yearly, traffic_yearly, traffic_accident_yearly, electrocution_yearly, other_yearly) %>% + mutate( + fatality_years = as.Date(paste0(fatality_years, "-01-01")) + ) + +yearly_fatalities_type_ts <- yearly_fatalities_type %>% + select(-fatality_years) %>% + xts(order.by = yearly_fatalities_type$fatality_years) + +output$decade_fatalities_type <- renderDygraph( + dygraph(yearly_fatalities_type_ts, main = "Fatality Types By Decade") %>% + dySeries("surge_yearly", label = "Surge") %>% + dySeries("surf_yearly", label = "Surf") %>% + dySeries("rough_seas_yearly", label = "Rough Seas") %>% + dySeries("rip_current_yearly", label = "Rip Current") %>% + dySeries("freshwater_floods_yearly", label = "Freshwater Floods") %>% + dySeries("wind_yearly", label = "Wind") %>% + dySeries("tree_fall_yearly", label = "Tree Fall") %>% + dySeries("tornado_yearly", label = "Tornado") %>% + dySeries("traffic_yearly", label = "Traffic") %>% + dySeries("traffic_accident_yearly", label = "Traffic Accident") %>% + dySeries("electrocution_yearly", label = "Electrocution") %>% + dySeries("other_yearly", label = "Other") %>% + dyRangeSelector() +) + +dygraphOutput("decade_fatalities_type") +``` + +Column {data-width=500} +--- + +### {data-height=500} +```{r} +fatality_type <- c("Surge", "Surf", "Rough Seas", "Rip Current", "Floods", "Wind", "Tree Fall", "Tornado", "Traffic", "Traffic Accident", "Electrocution", "Other") +fatality_totals <- c(520, 56, 77, 23, 826, 131, 91, 88, 10, 45, 16, 56) + +aggregate_fatality_types <- data.frame(fatality_type, fatality_totals) + +output$aggregate_fatalities <- renderBillboarder( + billboarder() %>% + bb_piechart(aggregate_fatality_types) + #%>% bb_legend(position = "right") +) + +billboarderOutput("aggregate_fatalities") +``` + +### {data-height=500} +```{r} +``` + About === diff --git a/queries.R b/queries.R index d2ce274..474ea0e 100644 --- a/queries.R +++ b/queries.R @@ -50,6 +50,12 @@ view.all_loss_storms <- tbl(con, "all_loss_storms") view.all_loss_landfalls <- tbl(con, "all_loss_landfalls") view.yearly_normalized_losses <- tbl(con, "yearly_normalized_losses") view.simplified_county_geom <- tbl(con, "simplified_county_geom") +view.all_loss_storms_tracks <- tbl(con, "all_loss_storms_tracks") + +#qry <- econ.storm_base_loss %>% +# left_join(view.hurdat_track, by = c("storm_basin", "storm_year", "storm_name")) + +#show_query(qry) # test storm #katrina <- list( @@ -175,6 +181,15 @@ get_hurdat_landfalls <- function(storm) { return(result) } +# returns all storm tracks from HURDAT +get_all_hurdat_tracks <- function() { + query <- view.all_loss_storms_tracks + + result <- query %>% collect() + + return(result) +} + # returns storm track from HURDAT get_hurdat_track <- function(storm) { query <- view.hurdat_track %>%