Files
ffdaten_simulation_R/simulations_overview.R
T
2026-08-18 22:48:25 +00:00

441 lines
11 KiB
R

library(tidytable)
# Make CFG ----------------------------------------------------------------
CFG
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
)
# Define Movement Data ----------------------------------------------------
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")
SPECIES
# Simulate Tracks ---------------------------------------------------------
tracks_roe <- simulate_tracks(
species = "Rehwild",# "Rotwild", "Gamswild",
year = 1,
pars = SPECIES$Rehwild,
area = AREA,
cfg = CFG
)
tracks_red <- simulate_tracks(
species = "Rotwild", #"Rehwild", #"Gamswild",
year = 1,
pars = SPECIES$Rotwild,
area = AREA,
cfg = CFG
)
tracks_cham <- simulate_tracks(
species = "Gamswild", #"Rotwild", #"Rehwild", #
year = 1,
pars = SPECIES$Gamswild,
area = AREA,
cfg = CFG
)
# Simulate Camera Locations -----------------------------------------------
# grid sampling design --------------------- ##
cfg_grid <- CFG
cfg_grid$camera_design_mode <- "grid"
cfg_grid$grid_random_rotation <- TRUE
cams_grid <- make_camera_design(
area = AREA,
cfg = cfg_grid,
grid_spacing_m = 300
)
# random sampling design --------------------- ##
cfg_random <- CFG
cfg_random$camera_design_mode <- "random"
cfg_random$random_random_rotation <- TRUE
cfg_random$camera_numbers <- 30
cams_random <- make_camera_design(
n_cameras = cfg_random$camera_numbers,
area = AREA,
cfg = cfg_random,
prop_focus = .75
)
# Plot Tracks -------------------------------------------------------------
# single individuals as an example
id_demo <- unique(tracks_demo$animal_id)[1]
one_animal <- tracks_demo[animal_id == id_demo]
one_sf <- st_as_sf(
one_animal,
coords = c("x", "y"),
crs = CFG$crs,
remove = FALSE
)
animals <- st_as_sf(
tracks_demo,
coords = c("x", "y"),
crs = CFG$crs,
remove = FALSE
)
ggplot() +
geom_sf(data = AREA$zones, aes(fill = zone), alpha = 0.20) +
geom_path(
data = animals,
aes(x = x, y = y, group = animal_id, color=animal_id),
linewidth = 0.35, alpha=.3
) +
geom_sf(data = animals[1, ], size = 2.5) +
coord_sf() +
labs(
title = paste("Beispielbewegung eines Individuums:", "Rehwild"),
#subtitle = id_demo,
fill = "Zone"
) +
theme_bw()
tracks_demo <- simulate_tracks(
species = "Rotwild",
year = 1,
pars = SPECIES[["Rotwild"]],
area = AREA,
cfg = CFG
)
id_demo <- unique(tracks_demo$animal_id)[1]
one_animal <- tracks_demo[animal_id == id_demo]
one_sf <- st_as_sf(
one_animal,
coords = c("x", "y"),
crs = CFG$crs,
remove = FALSE
)
ggplot() +
geom_sf(data = AREA$zones, aes(fill = zone), alpha = 0.20) +
geom_path(
data = one_animal,
aes(x = x, y = y),
linewidth = 0.35
) +
geom_sf(data = one_sf[1, ], size = 2.5) +
coord_sf() +
labs(
title = paste("Beispielbewegung eines Individuums:", "Rotwild"),
subtitle = id_demo,
fill = "Zone"
) +
theme_bw()
# add camera locations
ggplot() +
geom_sf(data = AREA$zones, aes(fill = zone), alpha = 0.25) +
geom_sf(data = cams_demo, shape = 21, size = 2.5) +
coord_sf() +
labs(
title = paste("Zufällig verschobenes Kameraraster:",
300, "m"),
subtitle = paste(nrow(cams_demo), "potenzielle Kamerastandorte"),
fill = "Zone"
) +
theme_bw()
# Simulate Detections -----------------------------------------------------
# grid sampling
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
)
# 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
)
# # pruefen ob tiere in kameranähe gelangen
#
# tracks_sf <- sf::st_as_sf(
# tracks_demo,
# coords = c("x", "y"),
# crs = CFG$crs,
# remove = FALSE
# )
#
# nearest_camera <- sf::st_nearest_feature(
# tracks_sf,
# cams_demo
# )
#
# distance_to_camera <- as.numeric(
# sf::st_distance(
# tracks_sf,
# cams_demo[nearest_camera, ],
# by_element = TRUE
# )
# )
#
# summary(distance_to_camera)
#
# sum(distance_to_camera <= CFG$detection_radius_m)
#
#
# # schneller funktionstest
#
# CFG_test <- CFG
# CFG_test$fixes_per_day <- 288
# CFG_test$detection_radius_m <- 100
# CFG_test$p_detect_5m <- 0.99
# CFG_test$p_detect_18m <- 0.50
#
# tracks_test <- simulate_tracks(
# "Rehwild",
# 1,
# SPECIES$Rehwild,
# AREA,
# CFG_test
# )
#
# cameras <- make_camera_design(
# area = AREA,
# cfg = CFG_test,
# grid_spacing_m = 250
# )
#
# det_test <- simulate_detections(
# tracks_test,
# cams_test,
# CFG_test
# )
#
# print(det_test)
#
# summarise_camera_counts(
# det = det_test,
# cameras = cams_test,
# year = 1,
# species = "Rehwild",
# cfg = CFG_test
# )
# Summarise Detections ----------------------------------------------------
# grid sampling
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
)
# 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_grid[, sampling := "grid"],
camera_counts_red_grid[, sampling := "grid"],
camera_counts_cham_grid[, sampling := "grid"],
camera_counts_roe_random[, sampling := "random"],
camera_counts_red_random[, sampling := "random"],
camera_counts_cham_random[, sampling := "random"]
) %>% bind_rows()
# Test Statistics ---------------------------------------------------------
# RAI
ggplot(camera_counts, aes(species, RAI_100_days)) +
geom_boxplot() +
facet_grid(sampling~zone)
# REM Density
rem_density_index(camera_counts = camera_counts_roe_grid,
species_pars = SPECIES$Rehwild,
cfg = cfg_grid)
2*cfg_grid$detection_radius_m /1000
camera_counts_roe_grid[, density_index := (events/effort_days)/pmax(1e-9, SPECIES$Rehwild$speed_km_day*0.04)]
camera_counts_roe_grid
camera_counts_roe_grid
# compare multiple years (if simulated)
fit_change_test(camera_counts_roe_grid)