diff --git a/nimble/model12/verbose_plotting.R b/nimble/model12/verbose_plotting.R new file mode 100644 index 0000000000000000000000000000000000000000..a95f64dde8636b7e93633e62439703d8febff096 --- /dev/null +++ b/nimble/model12/verbose_plotting.R @@ -0,0 +1,146 @@ +## rm(list=ls()) +library(sf) +library(tmap) +library(tmaptools) +library(dplyr) + +## Set the working directory to the directory storing the simulation output (Rdata) files +setwd("/home/david/asf-challenge/nimble/model12/MCMCall1000/simsCases_Verbose") + +## Choose simulation files for a given SCENARIO +SCENARIO <- 3 # could also be 2 (and eventually 3, 4, 5, 6, 7 or 8) +simFiles = sort(dir()[grep(paste0("scenario",SCENARIO), dir())]) +simFiles = simFiles[grep("Rdata", simFiles)] +length(simFiles) ## Should be 10000 + +## Set two constants +tStop = 230 +nSim = length(simFiles) + +## Plot trajectories of 3 hidden states and 3 observed states (detected cases) +nSim4plot = 10 +tRange = -30:tStop +ALPHA = 0.2 +par(mfrow=n2mfrow(6)) +## Exposed +plot(tRange, tRange, typ="n", ylab="Exposed", xlab="Day", ylim=c(0,2200)) +abline(h=0) +for (sim in 1:nSim4plot) { # sim=1 + if (sim %% round(nSim4plot/10) == 1) print(sim) + load(simFiles[sample(nSim, 1)]) # Choose one file at random & load it + lines(tVec, rowSums(E), col=rgb(0,0,0,ALPHA)) +} +## Infectious +plot(tRange, tRange, typ="n", ylab="Infectious", xlab="Day", ylim=c(0,1800)) +abline(h=0) +for (sim in 1:nSim4plot) { # sim=1 + if (sim %% round(nSim4plot/10) == 1) print(sim) + load(simFiles[sample(nSim, 1)]) # Choose one file at random & load it + lines(tVec, rowSums(I), col=rgb(0,0,0,ALPHA)) +} +## Carcass +plot(tRange, tRange, typ="n", ylab="Carcass", xlab="Day", ylim=c(0,10000)) +abline(h=0) +for (sim in 1:nSim4plot) { # sim=1 + if (sim %% round(nSim4plot/10) == 1) print(sim) + load(simFiles[sample(nSim, 1)]) # Choose one file at random & load it + lines(tVec, rowSums(C), col=rgb(0,0,0,ALPHA)) +} +## Hunted & tested +ve +plot(tRange, tRange, typ="n", ylab="Hunted & Tested +ve", xlab="Day", ylim=c(0,200)) +abline(h=0) +for (sim in 1:nSim4plot) { # sim=1 + if (sim %% round(nSim4plot/10) == 1) print(sim) + load(simFiles[sample(nSim, 1)]) # Choose one file at random & load it + lines(tVec, rowSums(HP), col=rgb(0,0,0,ALPHA)) +} +## Active search +plot(tRange, tRange, typ="n", ylab="Active search", xlab="Day", ylim=c(0,50)) +abline(h=0) +for (sim in 1:nSim4plot) { # sim=1 + if (sim %% round(nSim4plot/10) == 1) print(sim) + load(simFiles[sample(nSim, 1)]) # Choose one file at random & load it + lines(tVec, rowSums(AS), col=rgb(0,0,0,ALPHA)) +} +## Passive search +plot(tRange, tRange, typ="n", ylab="Passive search", xlab="Day", ylim=c(0,25)) +abline(h=0) +for (sim in 1:nSim4plot) { # sim=1 + if (sim %% round(nSim4plot/10) == 1) print(sim) + load(simFiles[sample(nSim, 1)]) # Choose one file at random & load it + lines(tVec, rowSums(PS), col=rgb(0,0,0,ALPHA)) +} + + +############# +## Mapping ## +############# +#drake::loadd(hexAll, hexSub_at_D110, fence, huntZone, admin) +#save(hexAll, hexSub_at_D110, fence, huntZone, admin, file="objectsForMapping.Rdata") +load("objectsForMapping.Rdata") + +## Choose one file at random & load it +load(simFiles[sample(nSim, 1)]) +## Select simulated data from one given day +DAY = 80 +ZOOM = TRUE +hexAll$E = E[which(tVec==DAY),] +hexAll$I = I[which(tVec==DAY),] +hexAll$C = C[which(tVec==DAY),] +hexAll$HP = HP[which(tVec==DAY),] +hexAll$AS = AS[which(tVec==DAY),] +hexAll$PS = PS[which(tVec==DAY),] +## Define map extent +if (ZOOM==TRUE) { + mapBase = tm_shape(hexSub_at_D110) + tm_polygons(col = "pForest", lwd=0.2, border.col="grey", palette=get_brewer_pal("Greens", n = 10, plot=FALSE)) +} else { + mapBase = tm_shape(hexAll) + tm_polygons(col = "pForest", lwd=0.2, border.col="grey", palette=get_brewer_pal("Greens", n = 10, plot=FALSE)) +} +## Define finishing overlays +mapOverays = + tm_shape(admin) + tm_borders(lwd=2) + + tm_shape(fence) + tm_borders(col="darkviolet", lwd=2) + + tm_shape(huntZone) + tm_borders(col="red", lwd=2) +## Map of exposed +mapE = mapBase +if(any(hexAll$E>0)) { + mapE = mapE + tm_shape(hexAll %>% filter(hexAll$E > 0)) + tm_polygons(col="E", border.alpha=1) +} +mapE = mapE + mapOverays +## Map of infectious +mapI = mapBase +if(any(hexAll$I>0)) { + mapI = mapI + + tm_shape(hexAll %>% filter(hexAll$I > 0)) + tm_polygons(col="I", border.alpha=1) +} +mapI = mapI + mapOverays +## Map of Carcasses +mapC = mapBase +if(any(hexAll$C>0)) { + mapC = mapC + + tm_shape(hexAll %>% filter(hexAll$C > 0)) + tm_polygons(col="C", border.alpha=1) +} +mapC = mapC + mapOverays +## Map of Hunted & tested +ve +mapHP = mapBase +if(any(hexAll$HP>0)) { + mapHP = mapHP + + tm_shape(hexAll %>% filter(hexAll$HP > 0)) + tm_polygons(col="HP", border.alpha=1) +} +mapHP = mapHP + mapOverays +## Map of Active search +mapAS = mapBase +if(any(hexAll$AS>0)) { + mapAS = mapAS + + tm_shape(hexAll %>% filter(hexAll$AS > 0)) + tm_polygons(col="AS", border.alpha=1) +} +mapAS = mapAS + mapOverays +## Map of Passive search +mapPS = mapBase +if(any(hexAll$PS>0)) { + mapPS = mapPS + + tm_shape(hexAll %>% filter(hexAll$PS > 0)) + tm_polygons(col="PS", border.alpha=1) +} +mapPS = mapPS + mapOverays +## Plot all maps +tmap_arrange(mapE, mapI, mapC, mapHP, mapAS, mapPS) diff --git a/nimble/model12/verbose_simWildBoarFromMCMC12.R b/nimble/model12/verbose_simWildBoarFromMCMC12.R index 720452c833e2a3f1a514542d77a782b5fd7005c0..a925d6cddba0c7df93a7553768c65501871fb451 100644 --- a/nimble/model12/verbose_simWildBoarFromMCMC12.R +++ b/nimble/model12/verbose_simWildBoarFromMCMC12.R @@ -1,7 +1,7 @@ # source(here::here("nimble/model12/verbose_simWildBoarFromMCMC12.R")) # rm(list=ls()) -SCENARIO <- 1 # 4 +SCENARIO <- 2 # 4 # This script jumps through MCMC output and generates weighted means & stdevs of the simulations @@ -166,7 +166,7 @@ cSimFromMCMC <- compileNimble(rSimFromMCMC) ##%%%%%%%%%%%%%%%%%%%%% ## Run simulations #### ##%%%%%%%%%%%%%%%%%%%%% -nSim = 1000 ## 10000 # 5000 +nSim = 10000 ## 10000 # 5000 tFence = 60 flagFence = c(1, 0) ## if 0 -> set omegaFence to 0 flagHuntZone = c(1, 0) ## if 0 -> set log_tauHArmy to -Inf (if it can handle it)