Dateien nach "/" hochladen

This commit is contained in:
2026-08-18 22:48:25 +00:00
parent 687c12922b
commit b2981a3019
5 changed files with 1588 additions and 0 deletions
+245
View File
@@ -0,0 +1,245 @@
#
# Libraries ---------------------------------------------------------------
source("fotofallen_power_simulation_schalenwild_grid.R")
# Data --------------------------------------------------------------------
CFG <- list(
crs = 32632, # Beispiel: UTM 32N; an Projektgebiet anpassen
years = 1:5,
survey_days = 30,
fixes_per_day = 1440/5, # 30-min Schritte; fuer feinere Detektion erhoehen
n_replicates = 500, # 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, 60),
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, 400, 500, 700),
grid_random_rotation = TRUE,
grid_clip_to = "outer", # "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
)
# ---- 2. Artprofile ----------------------------------------------------------
# home_range_ha beeinflusst die Streuung um das Streifgebietszentrum.
# step_scale_m beeinflusst kurzfristige Bewegung; attraction_strength die
# Rueckkehr zu Attraktionspunkten. Gamswild kann zusaetzlich durch ein
# Habitat-/Topographie-Raster gewichtet werden (siehe habitat_weight_function).
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()
# Simulation --------------------------------------------------------------
tracks_demo <- simulate_tracks(
species = "Gamswild",
year = 1,
pars = SPECIES[["Gamswild"]],
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:", "Gamswild"),
subtitle = id_demo,
fill = "Zone"
) +
theme_bw()
# test run parallel
CFG$n_replicates <- 5
system.time({
ans_test <- run_power_analysis_parallel(
species_names = "Rehwild",
cfg = CFG,
n_cores = 10
)
})
ans_test$summary
CFG$n_replicates <- 5
system.time({
ans_test <- run_power_analysis(
species_names = "Gamswild",
cfg = CFG
)
})
CFG$n_replicates <- 500
CFG$parallel <- TRUE
CFG$n_cores <- 7
# Power Analysis ----------------------------------------------------------
# run in parallel
n.cores <- max(
1,
parallel::detectCores() - 4
)
ans <- run_power_analysis_parallel(
species_names = c(
"Rehwild",
"Rotwild",
"Gamswild"
),
cfg = CFG,
n_cores = n.cores,
seed = 777
)
ans <- run_power_analysis(
species_names = c("Rehwild", "Rotwild", "Gamswild"),
cfg = CFG
)
data.table::fwrite(ans$raw, "power_raw.csv")
data.table::fwrite(ans$summary, "power_summary.csv")
# Output ------------------------------------------------------------------
ans$summary
ggplot(
ans$summary,
aes(
x = n_cameras,
y = power,
group = factor(grid_spacing_m),
linetype = factor(grid_spacing_m)
)
) +
geom_line() +
geom_point() +
geom_hline(
yintercept = CFG$target_power,
linetype = 2
) +
facet_wrap(~ species) +
scale_y_continuous(limits = c(0, 1)) +
labs(
x = "Mittlere tatsächliche Kamerazahl",
y = "Statistische Power",
linetype = "Rasterabstand (m)",
title = "Power zur Erkennung einer Abnahme der Fokusflächennutzung"
) +
theme_bw()
# Auch im Grid-Modus wird gegen die tatsaechlich resultierende Kamerazahl geplottet.
p <- ggplot(ans$summary,
aes(x = n_cameras, y = power,
group = if (identical(CFG$camera_design_mode, "grid"))
factor(grid_spacing_m) else factor(prop_focus),
linetype = if (identical(CFG$camera_design_mode, "grid"))
factor(grid_spacing_m) else factor(prop_focus))) +
geom_line() + geom_point() +
geom_hline(yintercept = CFG$target_power, linetype = 2) +
facet_wrap(~ species) +
scale_y_continuous(limits = c(0,1)) +
labs(x = "Gesamtzahl Kameras", y = "Power",
linetype = if (identical(CFG$camera_design_mode, "grid"))
"Grid-Abstand (m)" else "Anteil Fokus",
title = "Power zur Erkennung einer Abnahme der Fokusflaechennutzung") +
theme_bw()
p
ggsave("power_sampling_design.png", p, width = 10, height = 6, dpi = 300)
# Kleinstes Design je Art mit Ziel-Power:
recommendation <- ans$summary[reaches_target == TRUE][
order(n_cameras, -power), .SD[1], by = species]
print(recommendation)