Dateien nach "/" hochladen
This commit is contained in:
@@ -0,0 +1,362 @@
|
||||
|
||||
|
||||
CFG <- list(
|
||||
crs = 32632, # Beispiel: UTM 32N; an Projektgebiet anpassen
|
||||
years = 1,
|
||||
survey_days = 90,
|
||||
fixes_per_day = 1440/5, # 30-min Schritte; fuer feinere Detektion erhoehen
|
||||
n_replicates = 100, # fuer finale Analyse eher 500-1000
|
||||
alpha = 0.05,
|
||||
target_power = 0.80,
|
||||
# Kameradesign: "random" = vorgegebene Anzahl zufaelliger Standorte;
|
||||
# "grid" = zufaellig verschobenes/gedrehtes Raster.
|
||||
camera_design_mode = "grid",
|
||||
camera_numbers = c(20, 30, 40),
|
||||
allocations_focus = c(0.50, 0.75, 0.90),#c(0.35, 0.50, 0.65, 0.80),anteil zufaelliger standorte auf fokus
|
||||
min_camera_spacing_m = 300,
|
||||
# Bei Grid-Design bestimmt der Rasterabstand direkt die Kamerazahl.
|
||||
# Mehrere Werte koennen in der Poweranalyse verglichen werden.
|
||||
grid_spacings_m = c(300, 500, 700),
|
||||
grid_random_rotation = TRUE,
|
||||
grid_clip_to = "buffer", # "outer", "focus" oder "buffer"
|
||||
focus_radius_m = 1000,
|
||||
buffer_width_m = 1500,
|
||||
landscape_margin_m = 1800,
|
||||
detection_radius_m = 20,
|
||||
p_detect_5m = 0.95,
|
||||
p_detect_18m = 0.05,
|
||||
independence_minutes = 11,
|
||||
# relative Aenderung der Nutzung der Fokusflaeche von Jahr 1 bis Jahr 5:
|
||||
focus_use_multiplier_end = 0.5,#c(0.80, 0.70, 0.50, 0.40),
|
||||
# Gesamtpopulation konstant (=0) oder jaehrliche proportionale Aenderung:
|
||||
annual_population_change = 0, #c(0.00, -0.03, -0.05),
|
||||
# gleiche Kamerastandorte ueber die Jahre erhoehen Vergleichbarkeit:
|
||||
permanent_cameras = TRUE
|
||||
)
|
||||
|
||||
|
||||
SPECIES <- list(
|
||||
Rehwild = list(
|
||||
n_animals = 20,
|
||||
home_range_ha = 70,
|
||||
step_scale_m = 38,
|
||||
n_attraction_points = 4,
|
||||
attraction_strength = 0.10,
|
||||
resting_probability = 0.25,
|
||||
speed_km_day = 1.00,
|
||||
group_size_mean = 1.3
|
||||
),
|
||||
Rotwild = list(
|
||||
n_animals = 40,
|
||||
home_range_ha = 300,
|
||||
step_scale_m = 105,
|
||||
n_attraction_points = 3,
|
||||
attraction_strength = 0.055,
|
||||
resting_probability = 0.30,
|
||||
speed_km_day = 3.0,
|
||||
group_size_mean = 3.5
|
||||
),
|
||||
Gamswild = list(
|
||||
n_animals = 50,
|
||||
home_range_ha = 150,
|
||||
step_scale_m = 70,
|
||||
n_attraction_points = 5,
|
||||
attraction_strength = 0.075,
|
||||
resting_probability = 0.10,
|
||||
speed_km_day = 1.5,
|
||||
group_size_mean = 4.2
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
species_names <- c("Rehwild", "Rotwild", "Gamswild")
|
||||
|
||||
|
||||
AREA <- make_study_area()
|
||||
|
||||
|
||||
|
||||
|
||||
# One Simulation ----------------------------------------------------------
|
||||
|
||||
run <- 1
|
||||
|
||||
# tracks
|
||||
|
||||
tracks_roe <- simulate_tracks(
|
||||
species = "Rehwild",
|
||||
year = 1,
|
||||
pars = SPECIES$Rehwild,
|
||||
area = AREA,
|
||||
cfg = CFG
|
||||
)
|
||||
|
||||
tracks_red <- simulate_tracks(
|
||||
species = "Rotwild",
|
||||
year = 1,
|
||||
pars = SPECIES$Rotwild,
|
||||
area = AREA,
|
||||
cfg = CFG
|
||||
)
|
||||
|
||||
|
||||
tracks_cham <- simulate_tracks(
|
||||
species = "Gamswild",
|
||||
year = 1,
|
||||
pars = SPECIES$Gamswild,
|
||||
area = AREA,
|
||||
cfg = CFG
|
||||
)
|
||||
|
||||
|
||||
# grid sampling design --------------------- ##
|
||||
|
||||
|
||||
cfg_grid <- CFG
|
||||
cfg_grid$camera_design_mode <- "grid"
|
||||
cfg_grid$grid_random_rotation <- TRUE
|
||||
|
||||
grids <- list()
|
||||
n <- 1
|
||||
|
||||
for(gsm in CFG$grid_spacings_m){
|
||||
|
||||
# make grid
|
||||
cams_grid <- make_camera_design(
|
||||
area = AREA,
|
||||
cfg = cfg_grid,
|
||||
grid_spacing_m = gsm
|
||||
)
|
||||
|
||||
# get detections
|
||||
detections_roe_grid <- simulate_detections(
|
||||
tracks = tracks_roe,
|
||||
cameras = cams_grid,
|
||||
cfg = cfg_grid
|
||||
)
|
||||
|
||||
detections_red_grid <- simulate_detections(
|
||||
tracks = tracks_red,
|
||||
cameras = cams_grid,
|
||||
cfg = cfg_grid
|
||||
)
|
||||
|
||||
detections_cham_grid <- simulate_detections(
|
||||
tracks = tracks_cham,
|
||||
cameras = cams_grid,
|
||||
cfg = cfg_grid
|
||||
)
|
||||
|
||||
# summarise detections
|
||||
|
||||
camera_counts_roe_grid <- summarise_camera_counts(
|
||||
det = detections_roe_grid,
|
||||
cameras = cams_grid,
|
||||
year = 1,
|
||||
species = "Rehwild",
|
||||
cfg = cfg_grid
|
||||
)
|
||||
|
||||
camera_counts_red_grid <- summarise_camera_counts(
|
||||
det = detections_red_grid,
|
||||
cameras = cams_grid,
|
||||
year = 1,
|
||||
species = "Rotwild",
|
||||
cfg = cfg_grid
|
||||
)
|
||||
|
||||
camera_counts_cham_grid <- summarise_camera_counts(
|
||||
det = detections_cham_grid,
|
||||
cameras = cams_grid,
|
||||
year = 1,
|
||||
species = "Gamswild",
|
||||
cfg = cfg_grid
|
||||
)
|
||||
|
||||
# combine data frame
|
||||
camera_counts <- list(
|
||||
camera_counts_roe_grid,
|
||||
camera_counts_red_grid,
|
||||
camera_counts_cham_grid
|
||||
) %>% bind_rows()
|
||||
|
||||
camera_counts[, ':=' (sampling = "grid",
|
||||
grid_spacing = gsm,
|
||||
cameras = nrow(cams_grid))]
|
||||
|
||||
grids[[n]] <- camera_counts
|
||||
n <- n + 1
|
||||
}
|
||||
|
||||
grids_results <- grids %>% bind_rows()
|
||||
|
||||
|
||||
# random sampling design --------------------- ##
|
||||
|
||||
|
||||
cfg_random <- CFG
|
||||
cfg_random$camera_design_mode <- "random"
|
||||
cfg_random$random_random_rotation <- TRUE
|
||||
|
||||
|
||||
randoms <- list()
|
||||
n <- 1
|
||||
|
||||
|
||||
for(cms in CFG$camera_numbers){
|
||||
|
||||
for(af in CFG$allocations_focus){
|
||||
|
||||
cms <- 20
|
||||
af <- 0.5
|
||||
|
||||
cams_random <- make_camera_design(
|
||||
n_cameras = cms,
|
||||
area = AREA,
|
||||
cfg = cfg_random,
|
||||
prop_focus = af)
|
||||
|
||||
# random sampling
|
||||
|
||||
detections_roe_random <- simulate_detections(
|
||||
tracks = tracks_roe,
|
||||
cameras = cams_random,
|
||||
cfg = cfg_random
|
||||
)
|
||||
|
||||
detections_red_random <- simulate_detections(
|
||||
tracks = tracks_red,
|
||||
cameras = cams_random,
|
||||
cfg = cfg_random
|
||||
)
|
||||
|
||||
detections_cham_random <- simulate_detections(
|
||||
tracks = tracks_cham,
|
||||
cameras = cams_random,
|
||||
cfg = cfg_random
|
||||
)
|
||||
|
||||
# random sampling
|
||||
camera_counts_roe_random <- summarise_camera_counts(
|
||||
det = detections_roe_random,
|
||||
cameras = cams_random,
|
||||
year = 1,
|
||||
species = "Rehwild",
|
||||
cfg = cfg_random
|
||||
)
|
||||
|
||||
camera_counts_red_random <- summarise_camera_counts(
|
||||
det = detections_red_random,
|
||||
cameras = cams_random,
|
||||
year = 1,
|
||||
species = "Rotwild",
|
||||
cfg = cfg_random
|
||||
)
|
||||
|
||||
camera_counts_cham_random <- summarise_camera_counts(
|
||||
det = detections_cham_random,
|
||||
cameras = cams_random,
|
||||
year = 1,
|
||||
species = "Gamswild",
|
||||
cfg = cfg_random
|
||||
)
|
||||
|
||||
# combine data frame
|
||||
camera_counts <- list(
|
||||
camera_counts_roe_random,
|
||||
camera_counts_red_random,
|
||||
camera_counts_cham_random
|
||||
) %>% bind_rows()
|
||||
|
||||
camera_counts[, ':=' (sampling = "random",
|
||||
grid_spacing = NA_integer_,
|
||||
cameras = cms,
|
||||
prop_focus = af)]
|
||||
|
||||
|
||||
randoms[[n]] <- camera_counts
|
||||
n <- n + 1
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
randoms_results <- randoms %>% bind_rows()
|
||||
|
||||
|
||||
run_results <- list(grids_results, randoms_results) %>% bind_rows()
|
||||
|
||||
run_results[, run := run]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Optimized Code ----------------------------------------------------------
|
||||
|
||||
source("fotofallen_power_simulation_schalenwild_rai.R")
|
||||
|
||||
res <- simulate_rai_designs(
|
||||
run_id = 1,
|
||||
CFG = CFG,
|
||||
SPECIES = SPECIES,
|
||||
AREA = AREA,
|
||||
|
||||
save_each_design = TRUE,
|
||||
|
||||
output_dir = "rai_results",
|
||||
|
||||
parallel = TRUE,
|
||||
n_cores = 4
|
||||
)
|
||||
|
||||
for (run_id in 1:100) {
|
||||
|
||||
message(
|
||||
"\n==============================",
|
||||
"\nRUN ", run_id,
|
||||
"\n=============================="
|
||||
)
|
||||
|
||||
simulate_rai_designs(
|
||||
run_id = run_id,
|
||||
CFG = CFG,
|
||||
SPECIES = SPECIES,
|
||||
AREA = AREA,
|
||||
parallel = TRUE,
|
||||
n_cores = 6,
|
||||
output_dir = "rai_results"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
# highly efficient parallelisation ------------------------ ##
|
||||
|
||||
future::plan(
|
||||
future::multisession,
|
||||
workers = 12
|
||||
)
|
||||
|
||||
all_runs <- future.apply::future_lapply(
|
||||
10:100,
|
||||
|
||||
function(run_id) {
|
||||
|
||||
simulate_rai_designs(
|
||||
run_id = run_id,
|
||||
CFG = CFG,
|
||||
SPECIES = SPECIES,
|
||||
AREA = AREA,
|
||||
|
||||
parallel = FALSE,
|
||||
|
||||
save_each_design = TRUE,
|
||||
output_dir = "rai_results"
|
||||
)
|
||||
},
|
||||
|
||||
future.seed = TRUE
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user