knitr::opts_chunk$set(echo = FALSE)

library(dplyr)
library(DT)
library(flexdashboard)
library(googlesheets)
library(ggplot2)
library(plotly)
library(shiny)
library(viridis)

load("app_data.RData")
source("helper_fxns.R")
#source("exposure.R")
#source("fatality.R")

prior <- curve(dgamma(x, shape = 11.81641,  
                      rate = 9.765625),
               from = 0.5,
               to = 3)

priorb <- curve(dgamma(x, shape = 1.52522,
                       rate = 0.4781255),
                from = 0,
                to = 10)

collision <- curve(dbeta(x, shape1 = 1.638029, shape2 = 290.0193), 
                   from = 0, 
                   to = 0.04)

collisionb <- curve(dbeta(x, shape1 = 2.573610, shape2 = 366.3502),
                    from = 0,
                    to = 0.04)

act <- mean(Bay16$FLIGHT_MIN)/mean(Bay16$EFFORT)

scale <- glm(data = Bay16, (COLLISIONS/(FLIGHT_MIN/EFFORT))/0.002895415 ~ RISK_HA + I(RISK_HA^2))

tab <- select(Bay16, 
                    SITE, TURBINES, 
                    EFFORT, FLIGHT_MIN)

dt <- DT::datatable(tab,
                    fillContainer = TRUE,
                    selection = list(mode = 'single', 
                                     target = 'row'),
                    colnames = c("Site", "Turbines", "Survey Effort (hr*km3)",
                                 "Eagle Obs (min)"),
                  options = list(rownames = FALSE,
                                 pageLength = nrow(tab),
                                 dom = 'tip'
                                 )
                )%>%
  formatRound("EFFORT", 2)

Inputs {.sidebar}

Enter the proposed project specs:

column(6,
       numericInput('n', 'Number of Turbines',
            value = 100,
            min = 0, 
            max = 1000,
            width = '100%'),
       numericInput('t', 'Hours of Operation',
             value = 10,
             min = 8, 
             max = 14,
             width = '100%')
)
column(6,
       numericInput('h', 'Turbine Height (m)',
             value = 200,
             min = 100,
             max = 300,
             width = '100%'),
       numericInput('r', 'Rotor Radius (m)',
             value = 30,
             min = 20,
             max = 100,
             width = '100%')
)
#numericInput('size',
#            "Project Area (ha)",
#            value = round(mean(Bay16$RISK_HA), 0),
#            min = 0,
#            max = 500,
#            step = 1
#            )

Area surveyed for eagles. FWS requres at least one cylindrical plot of 800m radius (201 ha) by 200m height.

sliderInput("area",
            "Survey Area (ha)",
            min = 0,
            max = 2010,
            value = 201,
            step = 201)

Time spent surveying. FWS requires at least 12 hrs per year, for two years.

sliderInput("hrs",
            "Survey Hours",
            min = 0,
            max = 240,
            value = 24,
            step = 12)

Enter the amount of time eagles were observed flying within survey cylinders.

numericInput("min",
            "Flight Time (min)",
            value = 7,
            min = 0)



#cur_min <- reactive({Bay16$FLIGHT_MIN[Bay16$SITE == input$sites]})
cur_min <- reactive({input$min})
#cur_effort <- reactive({Bay16$EFFORT[Bay16$SITE == input$sites]})
cur_effort <- reactive({input$hrs * (input$area * 0.01) * 0.2})
#cur_scale <- reactive({Bay16$SCALE[Bay16$SITE == input$sites]})
cur_scale <- reactive({(input$t*365) * input$n * input$h/1000 * ((input$r/1000)^2) * pi})
#cur_scale <- reactive({-362.57580 + (input$size*33.38994) + ((input$size^2)*-0.03774)})
a <- reactive({11.81641 + cur_min()})
b <- reactive({9.7656250 + cur_effort()})
ab <- reactive({1.52522 + cur_min()})
bb <- reactive({0.4781255 + cur_min()})
actionButton("update", "Update Distributions")

r hr()

actionButton("calculate", "Calculate Fatalities")

r hr()

helpText("Note: Calcuating predicted fatality distributions takes time.  Please allow several seconds for the graph to load.")

Golden Eagles

Column {data-width = 500}

Prior Probabilities of Eagle Collision Rates

modalDialog(
  title = h2("Bayesian Eagle Mortality Prediction"),
  p("The ", tags$a(href = "https://www.fws.gov/", "U.S. Fish and Wildlife Service")," uses a Bayesian model to estimate the number of bald and golden eagles likely to be killed by proposed wind projects.
This approach combines surveys of eagle activity at proposed sites with prior information about eagle collision and activity rates across existing wind farms to estimate the likely number of fatalities."),
br(),
p("This dashboard allows you to explore how priors interact with survey data to produce predicted eagle fatalities at a set of wind energy sites. Eagle fatalities are predicted using four pieces of information obtained prior to construction:"),
tags$ol(
  tags$li("Project Specs: the number and size of turbines."),
  tags$li("Survey Area: the size of the area surveyed for eagles."),
  tags$li("Survey Hours: time spent conducting eagle surveys."),
  tags$li("Flight Time: the total time eagles were observed flying within survey areas")
),
p("The tabs at the top of the page allow you to switch between golden and bald eagle estimates."),
  easyClose = TRUE
  )

renderPlotly({
  plot_ly()%>%
  add_trace(x = ~collision$x, y = ~collision$y, type = "scatter", mode = "lines",
            fill = "tozeroy", name = "Prior", line = list(color = "grey"),
            text = ~paste("Prior probability of Collision Rate = ",
                          round(collision$x, 3),
                          "<br> is ",
                          round(collision$y, 3),
                          sep = ""),
            hoverinfo = "text")%>%
      layout(#title = "Prior Collision Rates",
             xaxis = list(title = "Collision Rate (per Exposure)",
                          range = 0, 0.01),
             yaxis = list(title = "Probability Density"))
})

#ggplot(Bay16, aes(x = EFFORT, y = OBS_MIN))+
#  geom_point()
#renderPlotly({
#ggplotly()
#})

Eagle Activity (Click 'Update Distributions')

observeEvent(input$update, {
  act <- isolate({cur_min()/cur_effort()})
  obs <- isolate({density(rgamma(10000, 
                                 shape = a(), 
                                 rate = b()
                                 )
                          )
    })

output$exposure <- renderPlotly({ 
    plot_ly()%>%
      add_trace(x = ~c(act, act), y = ~c(0,max(c(prior$y,obs$y))),
                type = "scatter", mode = "lines",
                name = "Observed", line = list(color = vir_col(3)[2]),
                text = ~paste("Observed Activity<br>at site = ",
                              round(act,2),
                              sep = ""),
                hoverinfo = "text")%>%
      add_trace(x = prior$x, y = prior$y,
                type = "scatter", mode = "lines", fill = "tozeroy",
                name = "Prior", line = list(color = vir_col(3)[1]),
                text = ~paste("Prior Activity<br>estimate = ",
                              round(prior$x, 2),
                              sep = ""),
                hoverinfo = "text")%>%
      add_trace(x = ~obs$x, y = ~obs$y,
                type = "scatter", mode = "lines", fill = "tozeroy",
                name = "Combined", line = list(color = vir_col(3)[3]),
                text = ~paste("Combined Activity<br>estimate = ",
                              round(obs$x, 2),
                              sep = ""),
                hoverinfo = "text")%>%
      layout(#title = "Eagle Exposure",
             xaxis = list(title = "Eagle Activity (min/km<sup>3</sup>*hr)",
                          range = c(0,10)),
             yaxis = list(title = "Probability Density"),
             legend = list(x = 0.7,
                           y = 1))
   })

})

plotlyOutput("exposure")

Activity is the number of minutes eagles are observed flying within survey areas, per hour.

Predicted Fatalities (Click 'Predict Fatalities')

observeEvent(input$calculate,{
  #if(input$sites != ""){
    out <- isolate({simFatal(iters = 10000, BMin = cur_min(), SmpHrKm = cur_effort(),
                             aPriExp=11.81641, bPriExp=9.7656250,
                             aPriCPr=1.638029, bPriCPr=290.0193)})
    fatality <- isolate({density(out$fatality*cur_scale())})
    q80 <- isolate({quantile(out$fatality*cur_scale(), 0.8)})

    out2 <- isolate({simFatal(iters = 10000, BMin = cur_min(), SmpHrKm = cur_effort(),
                             aPriExp = 0, bPriExp = 0,
                             aPriCPr = 1.638029, bPriCPr = 290.0193)})
    fatality2 <- isolate({density(out2$fatality*cur_scale())})
    q82 <- isolate({quantile(out2$fatality*cur_scale(), c(0.8))})

output$fatality <- renderPlotly({
        plot_ly()%>%
          add_trace(x = ~fatality$x, y = ~fatality$y, type = "scatter", mode = "lines",
                    fill = "tozeroy",
                    name = "Incl. Prior Exposure", line = list(color = vir_col(3)[3]),
                    text = ~paste("Predicted fatalities<br>incorporating prior = ",
                                  round(fatality$x, 2),
                                  sep = ""),
                    hoverinfo = "text")%>%
          add_trace(x = ~c(q80, q80), y = ~ c(0, max(fatality$y)),
                    mode = 'lines', type = 'scatter',
                    line = list(color = vir_col(3)[3]),
                    name = "80th Percentile")%>%
          add_trace(x = ~fatality2$x, y = ~fatality2$y, type = "scatter", 
                    mode = "lines",
                    fill = "tozeroy",
                    line = list(color = vir_col(3)[2]), 
                    name = "Using Site Survey Only",
                    text = ~paste("Predicted fatalities<br>from site survey = ",
                                  round(fatality2$x, 2),
                                  sep = ""),
                    hoverinfo = "text")%>%
          add_trace(x = ~c(q82, q82), y = ~ c(0, max(fatality2$y)),
                    mode = 'lines', type = 'scatter',
                    line = list(color = vir_col(3)[2]),
                    name = "80th Percentile")%>%
          layout(##title = "Predicted Annual Eagle Fatalities",
                 xaxis = list(title = "Fatalities per Year"),
                 yaxis = list(title = "Probability Density"),
                 legend = list(x = 0.7,
                               y = 1))
    })
output$text <-renderText({
    paste("For the proposed project observing ", input$min, "minutes of eagle flight time during ", input$hrs, " survey hours covering ", input$area, "(ha), the predicted take requiring mitigation is ", round(q80, 1), " golden eagles using the update priors.")
    })
  #}
})
plotlyOutput('fatality')

Column {data-width=500}

FWS Survey Data {data-height=700}

DT::renderDataTable({dt})

Results {data-height=300}

span(textOutput('text'), style='color:blue; font-size:18px')

Data taken from Appendix S1 in Bay et al. (2016). The Journal of Wildlife Management 80(6): 1000-1010.

Bald Eagles

Column {data-width = 500}

Prior Probabilities of Eagle Collision Rates

renderPlotly({
  plot_ly()%>%
  add_trace(x = ~collisionb$x, y = ~collisionb$y, type = "scatter", mode = "lines",
            fill = "tozeroy", name = "Prior", line = list(color = "grey"),
            text = ~paste("Prior probability of Collision Rate = ",
                          round(collisionb$x, 3),
                          "<br> is ",
                          round(collisionb$y, 3),
                          sep = ""),
            hoverinfo = "text")%>%
      layout(#title = "Prior Collision Rates",
             xaxis = list(title = "Collision Rate (per Exposure)",
                          range = 0, 0.01),
             yaxis = list(title = "Probability Density"))
})

#ggplot(Bay16, aes(x = EFFORT, y = OBS_MIN))+
#  geom_point()
#renderPlotly({
#ggplotly()
#})

Eagle Activity (Click 'Update Distributions')

observeEvent(input$update, {
  act <- isolate({cur_min()/cur_effort()})
  obs <- isolate({density(rgamma(10000, 
                                 shape = ab(), 
                                 rate = bb()
                                 )
                          )
    })

output$exposureb <- renderPlotly({ 
    plot_ly()%>%
      add_trace(x = ~c(act, act), y = ~c(0,max(c(priorb$y,obs$y))),
                type = "scatter", mode = "lines",
                name = "Observed", line = list(color = vir_col(3)[2]),
                text = ~paste("Observed Activity<br>at site = ",
                              round(act,2),
                              sep = ""),
                hoverinfo = "text")%>%
      add_trace(x = priorb$x, y = priorb$y,
                type = "scatter", mode = "lines", fill = "tozeroy",
                name = "Prior", line = list(color = vir_col(3)[1]),
                text = ~paste("Prior Activity<br>estimate = ",
                              round(priorb$x, 2),
                              sep = ""),
                hoverinfo = "text")%>%
      add_trace(x = ~obs$x, y = ~obs$y,
                type = "scatter", mode = "lines", fill = "tozeroy",
                name = "Combined", line = list(color = vir_col(3)[3]),
                text = ~paste("Combined Activity<br>estimate = ",
                              round(obs$x, 2),
                              sep = ""),
                hoverinfo = "text")%>%
      layout(#title = "Eagle Exposure",
             xaxis = list(title = "Eagle Activity (min/km<sup>3</sup>*hr)",
                          range = c(0,10)),
             yaxis = list(title = "Probability Density"),
             legend = list(x = 0.7,
                           y = 1))
   })

})

plotlyOutput("exposureb")

Activity is the number of minutes eagles are observed flying within survey areas, per hour.

Predicted Fatalities (Click 'Predict Fatalities')

observeEvent(input$calculate,{
  #if(input$sites != ""){
    outb <- isolate({simFatal(iters = 10000, BMin = cur_min(), SmpHrKm = cur_effort(),
                             aPriExp=1.52522, bPriExp=0.4781255,
                             aPriCPr=2.573610, bPriCPr=366.3502)})
    fatalityb <- isolate({density(outb$fatality*cur_scale())})
    q80b <- isolate({quantile(outb$fatality*cur_scale(), 0.8)})

    out2b <- isolate({simFatal(iters = 10000, BMin = cur_min(), SmpHrKm = cur_effort(),
                             aPriExp = 0, bPriExp = 0,
                             aPriCPr = 2.573610, bPriCPr = 366.3502)})
    fatality2b <- isolate({density(out2b$fatality*cur_scale())})
    q82b <- isolate({quantile(out2b$fatality*cur_scale(), c(0.8))})

output$fatalityb <- renderPlotly({
        plot_ly()%>%
          add_trace(x = ~fatalityb$x, y = ~fatalityb$y, type = "scatter", mode = "lines",
                    fill = "tozeroy",
                    name = "Incl. Prior Exposure", line = list(color = vir_col(3)[3]),
                    text = ~paste("Predicted fatalities<br>incorporating prior = ",
                                  round(fatalityb$x, 2),
                                  sep = ""),
                    hoverinfo = "text")%>%
          add_trace(x = ~c(q80b, q80b), y = ~ c(0, max(fatalityb$y)),
                    mode = 'lines', type = 'scatter',
                    line = list(color = vir_col(3)[3]),
                    name = "80th Percentile")%>%
          add_trace(x = ~fatality2b$x, y = ~fatality2b$y, type = "scatter", 
                    mode = "lines",
                    fill = "tozeroy",
                    line = list(color = vir_col(3)[2]), 
                    name = "Using Site Survey Only",
                    text = ~paste("Predicted fatalities<br>from site survey = ",
                                  round(fatality2b$x, 2),
                                  sep = ""),
                    hoverinfo = "text")%>%
          add_trace(x = ~c(q82b, q82b), y = ~ c(0, max(fatality2b$y)),
                    mode = 'lines', type = 'scatter',
                    line = list(color = vir_col(3)[2]),
                    name = "80th Percentile")%>%
          layout(##title = "Predicted Annual Eagle Fatalities",
                 xaxis = list(title = "Fatalities per Year"),
                 yaxis = list(title = "Probability Density"),
                 legend = list(x = 0.7,
                               y = 1))
    })
output$textb <-renderText({
    paste("For the proposed project observing ", input$min, "minutes of bald eagle flight time during ", input$hrs, " survey hours covering ", input$area, "(ha), the predicted take requiring mitigation is ", round(q80b, 1), " bald eagles using the update priors.")
    })
  #}
})
plotlyOutput('fatalityb')

Column {data-width=500}

FWS Survey Data {data-height=700}

DT::renderDataTable({dt})

Results {data-height=300}

span(textOutput('textb'), style='color:blue; font-size:18px')

Data taken from Appendix S1 in Bay et al. (2016). The Journal of Wildlife Management 80(6): 1000-1010.



mjevans26/eaglesFWS documentation built on Dec. 29, 2021, 1:35 a.m.