-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-uniformD.R
62 lines (51 loc) · 1.62 KB
/
example-uniformD.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
### Simple example generating an optimal SCR design
### (uniform animal density)
library(dplyr)
library(tidyr)
library(ggplot2)
library(sf)
library(stringr)
library(secr)
library(secrdesign)
#library(oSCR)
library(raster)
library(kofnGA)
source("oSCR/e2dist.R")
source("oSCR/scrdesignGAenrm.R")
source("oSCR/scrdesignOFenrm.R")
# input file contains data frames with mask locations, and all potential camera locations
load("data/TostExample.RData")
# design parameters
ndesigns <- 1
nT <- 30
# assumptions about animal density and movement
lambda0 <- 1
dens_per_100km2 <- 2 # mean animal density per 100km2, SLs are ~1
D <- dens_per_100km2 / 10000
sigma <- 3000
dt <- "count"
mask <- read.mask(data = bigmask_df)
plot(mask)
plot(read.mask(data = alltraps_df), col = 'blue', add = TRUE, axes =T)
# traps = subset of mask points that are potential camera locations
alltraps <- alltraps_df[,1:2] %>% as.matrix()
# generate optimal design
mnr <- scrdesignGAenrm(statespace = mask,
alltraps = alltraps,
ntraps = nT,
lambda0 = lambda0,
sigma = sigma,
D = D,
occasions = 1,
detector = "count",
ngen = 20,
popsize = 500,
seed = 700)
# extract camera locations
mnr_traps <- as.data.frame(mnr$optimaltraps)
# plot
mnr_traps %>%
ggplot(aes(x = x, y = y)) +
geom_tile(data = mask_df, fill = "gray80", colour = "black") +
geom_point(size = 1, colour = "red") +
scale_fill_viridis_c() + coord_equal()