-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
407 changed files
with
115,093 additions
and
57,580 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
# | ||
# Mortalité éoliennes [2] | ||
# Partie Server | ||
# | ||
|
||
library(shiny) | ||
|
||
# Define server logic required to draw a histogram | ||
shinyServer(function(input, output) { | ||
|
||
##------------------------## | ||
# la fonction suivante se déclenche avec un clic sur le bouton GO, | ||
# effectue 1000 simulations et | ||
# renvoie un dataframe de 5 variables x 1000 valeurs | ||
##------------------------## | ||
simul <- eventReactive(input$go, { | ||
|
||
# nombre de visites sur le terrain | ||
Nvisites<-input$Nvisites | ||
# intervale de temps entre les visites | ||
l<-input$l | ||
# nombre de cadavres posés pour le test de persistence | ||
Nind<-input$Nind | ||
# taux de détection des cadavres | ||
d<-input$d # detection | ||
# nombre de cadavres posés pour le test de détection | ||
size<-input$size | ||
# taux de persistence quotidien des cadavres | ||
p<-input$p # persistence quotidienne | ||
# nombre de mortalités attendues par an | ||
Natt<-input$Natt | ||
# nombre de simulations | ||
Nboot<-input$Nboot | ||
|
||
##------------------------## | ||
# script de simulations | ||
##------------------------## | ||
Njour<-Nvisites*l+100 | ||
Ncad<-Natt/365 # nombre de cadavres moyen par jour | ||
|
||
d_estim<-rep(0,Nboot) | ||
Mortboot<-rep(0,Nboot) | ||
t<-rep(0,Nboot) | ||
ptemp<-rep(0,Nboot) | ||
p_estim<-rep(0,Nboot) | ||
Huso<-rep(0,Nboot) | ||
Winkelmann<-rep(0,Nboot) | ||
Erickson<-rep(0,Nboot) | ||
Jones<-rep(0,Nboot) | ||
Mort_true_interval<-rep(0,Nboot) | ||
|
||
## debut des bootstrap | ||
withProgress(message = 'Bootstrap progression : ', value=0, { | ||
|
||
for (boot in 1:Nboot) { | ||
################################### | ||
# simulation - nombre de cadavres détectés | ||
################################### | ||
Mort_an<-rpois(Njour,Ncad) | ||
Ntotmort<-sum(Mort_an) | ||
histM<-matrix(0,ncol=Njour,nrow=Ntotmort) | ||
first<-rep(0,Ntotmort) | ||
last<-rep(0,Ntotmort) | ||
done<-0 | ||
|
||
for (j in 1:(Njour-1)) { | ||
Nnew<-Mort_an[j] | ||
if(Nnew>0) { | ||
histM[(done+1):(done+Nnew),j]<-1 | ||
first[(done+1):(done+Nnew)]<-j | ||
done<-done+Nnew | ||
} | ||
if (done>0) { | ||
for (i in 1:done) { | ||
if (histM[i,j]>0) { | ||
histM[i,(j+1)]<-rbinom(1,histM[i,j],p) | ||
if (histM[i,(j+1)]==0){ | ||
last[i]<-j | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
init<-5 | ||
Sample_visites<-seq(init,(init+(l*(Nvisites-1))),length.out=Nvisites) | ||
Mort_visites<-histM[,Sample_visites] | ||
histdetect<-matrix(0,nrow=Ntotmort,ncol=Nvisites) | ||
for (i in 1:Ntotmort) { | ||
for (j in 1:Nvisites) { | ||
if (Mort_visites[i,j]>0){ | ||
histdetect[i,j]<-rbinom(1,Mort_visites[i,j],d) | ||
} | ||
} | ||
} | ||
|
||
Mort_detect<-sum(rowSums(histdetect)>0) | ||
Mortboot[boot]<-Mort_detect | ||
Mort_true_interval[boot]<-sum(Mort_an[init:(init+(l*(Nvisites-1)))]) | ||
|
||
################################### | ||
## simulation estimation detect | ||
################################### | ||
Ndetect<-sum(rbinom(size,1,d)) | ||
d_estim[boot]<-Ndetect/size | ||
|
||
################################### | ||
# simulation estimation persistence | ||
################################### | ||
|
||
|
||
NjourP<-100 | ||
hist<-matrix(0,nrow=Nind,ncol=NjourP) | ||
last<-rep(1,Nind) | ||
hist[,1]<-1 | ||
for (i in 1:Nind) { | ||
for (j in 2:NjourP) { | ||
hist[i,j]<-rbinom(1,hist[i,(j-1)],p) | ||
if (hist[i,j]==1) { | ||
last[i]<-j | ||
} | ||
} | ||
} | ||
last<-last-1 | ||
p_estim[boot]<-sum(last>l)/Nind | ||
t[boot]<-mean(last) # durée de vie moyenne d'un cadavre | ||
|
||
|
||
### calculs Huso | ||
if ((-log(0.01)*t[boot])>=l){ | ||
e_hat<-1 | ||
} | ||
if ((-log(0.01)*t[boot])<l){ | ||
e_hat<-((-log(0.01)*t[boot])/l) | ||
} | ||
ptemp[boot]<-t[boot]*(1-exp(-(l/t[boot])))/l | ||
Huso[boot]<-Mortboot[boot]/(d_estim[boot]*ptemp[boot]*e_hat) | ||
Winkelmann[boot]<-Mortboot[boot]/(p_estim[boot]*d_estim[boot]) | ||
Erickson[boot]<-l*Mortboot[boot]/(t[boot]*d_estim[boot]) | ||
Jones[boot]<-Mortboot[boot]/(d_estim[boot]*exp(-0.5*(l/t[boot]))*e_hat) | ||
|
||
# barre de progression Shiny (recalculee tous les 10 iterations) | ||
if (boot%%10 == 0) | ||
setProgress(boot/Nboot) | ||
} | ||
setProgress(1) | ||
}) | ||
# fin des bootstrap | ||
##------------------------## | ||
|
||
# valeur retour | ||
data.frame(Huso, Erickson, Winkelmann, Jones, Mort_true_interval) | ||
}) | ||
|
||
##------------------------## | ||
# rendu HTML résultats | ||
output$quantiles <- renderTable({ | ||
df <- simul() | ||
l <- nrow(df) | ||
#nomcol <- c("Méthode" ,"Médiane", "IC 2.5", "IC 97.5", "IC 10", "IC 90","Proportion simulations sans Mortalité") | ||
col1 <- c("Erickson", "Huso", "Winkelmann", "Jones") | ||
col23456 <- rbind( | ||
quantile(df$Erickson[df$Erickson<10000], probs=c(0.5,0.025,0.975, 0.1,0.9),na.rm = T), | ||
quantile(df$Huso[df$Huso<10000], probs=c(0.5,0.025,0.975, 0.1,0.9),na.rm = T), | ||
quantile(df$Winkelmann[df$Winkelmann<10000], probs=c(0.5,0.025,0.975, 0.1,0.9),na.rm = T), | ||
quantile(df$Jones[df$Jones<10000], probs=c(0.5,0.025,0.975, 0.1,0.9),na.rm = T) | ||
) | ||
col7 <- c( | ||
sum(df$Erickson==0,na.rm=T)/(l-sum(is.na(df$Erickson))), | ||
sum(df$Huso==0,na.rm=T)/(l-sum(is.na(df$Huso))), | ||
sum(df$Winkelmann==0,na.rm=T)/(l-sum(is.na(df$Winkelmann))), | ||
sum(df$Jones==0,na.rm=T)/(l-sum(is.na(df$Jones))) | ||
) | ||
result <- data.frame(col1,col23456,col7) | ||
colnames(result) <- c("Méthode" ,"Médiane", "IC 2.5", "IC 97.5", "IC 10", "IC 90","Proportion simulations sans Mortalité") | ||
result | ||
}) | ||
|
||
##------------------------## | ||
# rendu des graphiques | ||
output$graphHuso <- renderPlot({ | ||
df <- simul() | ||
hist(df$Huso, xlab="Estimation de la mortalité", ylab="fréquence sur les simulations", main="Formule de Huso") | ||
}) | ||
|
||
output$graphErickson <- renderPlot({ | ||
df <- simul() | ||
hist(df$Erickson, xlab="Estimation de la mortalité", ylab="fréquence sur les simulations", main="Formule de Erickson") | ||
}) | ||
|
||
output$graphWinkelmann <- renderPlot({ | ||
df <- simul() | ||
hist(df$Winkelmann, xlab="Estimation de la mortalité", ylab="fréquence sur les simulations", main="Formule de Winkelmann") | ||
}) | ||
|
||
output$graphJones <- renderPlot({ | ||
df <- simul() | ||
hist(df$Jones, xlab="Estimation de la mortalité", ylab="fréquence sur les simulations", main="Formule de Jones") | ||
}) | ||
|
||
output$graphMortalite <- renderPlot({ | ||
df <- simul() | ||
hist(df$Mort_true_interval, xlab="Nombre réeel de mortalités", ylab="fréquence sur les simulations", main="Mortalité réelle") | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# | ||
# Mortalité éoliennes [2] | ||
# Partie UI | ||
# | ||
|
||
library(shiny) | ||
|
||
# Define UI for application | ||
shinyUI(fixedPage( | ||
|
||
|
||
# Application title | ||
fluidRow( | ||
column(width=3,img(src="cefe_160px.png", style="margin: 1rem auto;")), | ||
column(width=9,h1("Préparer un protocole de suivi de mortalité")) | ||
), | ||
|
||
wellPanel( | ||
fluidRow( | ||
column(width=6, | ||
numericInput('Nvisites', label='Nombre de visites sur le terrain = ', value=10, step=1), | ||
numericInput('l', label='Intervalle de temps entre les visites = ', value=4, step=1), | ||
numericInput('Natt', label='Nombre de mortalités attendues par an = ', value=80, step=5), | ||
numericInput('Nboot', label='Nombre de simulations = ', value=1000, step=100) | ||
), | ||
column(width=6, | ||
numericInput('Nind', label='Nombre de cadavres posés pour le test de persistance = ', value=15, step=1), | ||
numericInput('p', label='Taux de persistance quotidien des cadavres = ', value=0.75, step=0.05), | ||
numericInput('size', label='Nombre de cadavres posés pour le test de détection = ', value=15, step=1), | ||
numericInput('d', label='Taux de détection des cadavres = ', value=0.75, step=0.05) | ||
) | ||
), | ||
fluidRow( | ||
column(width=6, | ||
actionButton(inputId = "go", label = "SIMULER") | ||
), | ||
column(width=6, | ||
h4("A propos de cette page"), | ||
p(HTML("•"), a(href="manuel_shiny.pdf", "Manuel d'utilisation")), | ||
p(HTML("•"), a(href="estimations_de_mortalites.pdf", "Présentation sur l'estimation des mortalités")) | ||
) | ||
) | ||
), | ||
fluidRow( | ||
column(width=11, | ||
h4("Estimations et leurs intervalles de confiance"), | ||
tableOutput("quantiles") | ||
) | ||
), | ||
fluidRow( | ||
column(width=6, | ||
plotOutput("graphErickson"), | ||
plotOutput("graphHuso") | ||
), | ||
column(width=6, | ||
plotOutput("graphWinkelmann"), | ||
plotOutput("graphJones"), | ||
plotOutput("graphMortalite") | ||
) | ||
) | ||
)) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM rocker/shiny:latest | ||
|
||
# Installing packages needed for check traffic on the container and kill if none | ||
RUN echo "force-unsafe-io" > /etc/dpkg/dpkg.cfg.d/02apt-speedup && \ | ||
echo "Acquire::http {No-Cache=True;};" > /etc/apt/apt.conf.d/no-cache && \ | ||
apt-get -qq update && apt-get install --no-install-recommends -y net-tools procps | ||
|
||
# Bash script to check traffic | ||
COPY CEFE /srv/shiny-server/sample-apps/CEFE | ||
ADD ./monitor_traffic.sh /monitor_traffic.sh | ||
COPY shiny-server.sh /usr/bin/shiny-server.sh | ||
CMD ["/usr/bin/shiny-server.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# shiny-GIE-test | ||
Based on the work of https://github.com/65MO/Galaxy-E/tree/master/GIE/shiny-GIE-master | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
while true; do | ||
sleep 60 | ||
|
||
if [ `netstat -t | grep -v CLOSE_WAIT | grep ':3838' | wc -l` -lt 3 ] | ||
then | ||
pkill shiny-server | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh | ||
|
||
# Make sure the directory for individual app logs exists | ||
mkdir -p /var/log/shiny-server | ||
chown shiny.shiny /var/log/shiny-server | ||
|
||
chmod +x /monitor_traffic.sh | ||
exec /monitor_traffic.sh & | ||
|
||
exec shiny-server 2>&1 |
Binary file not shown.
Oops, something went wrong.