SmartCane/r_app/experiments/max_ci_field.r
Timon 6efcc8cfec Fix CI report pipeline: update tmap v4 syntax, add continuous color scales, fix formatting
- Updated all CI maps to use tm_scale_continuous() for proper tmap v4 compatibility
- Added fixed color scale limits (1-8 for CI, -3 to +3 for differences) for consistent field comparison
- Fixed YAML header formatting issues in CI_report_dashboard_planet.Rmd
- Positioned RGB map before CI overview map as requested
- Removed all obsolete use_breaks parameter references
- Enhanced error handling and logging throughout the pipeline
- Added new experimental analysis scripts and improvements to mosaic creation
2025-06-19 20:37:20 +02:00

55 lines
1.3 KiB
R

library(sf)
library(terra)
library(tidyverse)
library(lubridate)
library(exactextractr)
library(readxl)
# Vang alle command line argumenten op
args <- commandArgs(trailingOnly = TRUE)
# Controleer of er ten minste één argument is doorgegeven
if (length(args) == 0) {
stop("Geen argumenten doorgegeven aan het script")
}
# Converteer het eerste argument naar een numerieke waarde
end_date <- as.Date(args[1])
if (is.na(end_date)) {
end_date <- lubridate::dmy("28-08-2024")
}
offset <- as.numeric(args[2])
# Controleer of weeks_ago een geldig getal is
if (is.na(offset)) {
# stop("Het argument is geen geldig getal")
offset <- 7
}
week <- week(end_date)
# Converteer het tweede argument naar een string waarde
project_dir <- as.character(args[3])
# Controleer of data_dir een geldige waarde is
if (!is.character(project_dir)) {
project_dir <- "chemba"
}
new_project_question = FALSE
source("parameters_project.R")
source("ci_extraction_utils.R")
raster_files <- list.files(merged_final,full.names = T, pattern = ".tif")
# Load all raster files
rasters <- lapply(raster_files, function(file) {
r <- rast(file)
r[[which(names(r) == "CI")]] # Select the CI band
})
# Calculate the maximum CI per pixel
max_ci_raster <- do.call(terra::app, c(rasters, fun = mean, na.rm = TRUE))
plot(max_ci_raster)