adjusted dates to iso dates

This commit is contained in:
Martin Folkerts 2025-01-07 14:24:38 +01:00
parent 4db80688ca
commit dd1ee2b1a0
3 changed files with 32 additions and 5 deletions

View file

@ -144,10 +144,16 @@ CI_quadrant <- readRDS(here(cumulative_CI_vals_dir,"All_pivots_Cumulative_CI_qua
# rename(pivot_quadrant = field)
path_to_week_current = here(weekly_CI_mosaic, paste0("week_",week, "_", year, ".tif"))
path_to_week_minus_1 = here(weekly_CI_mosaic, paste0("week_",week_minus_1, "_", year_1, ".tif"))
path_to_week_minus_2 = here(weekly_CI_mosaic, paste0("week_",week_minus_2, "_", year_2, ".tif"))
path_to_week_minus_3 = here(weekly_CI_mosaic, paste0("week_",week_minus_3, "_", year_3, ".tif"))
# path_to_week_current = here(weekly_CI_mosaic, paste0("week_",week, "_", year, ".tif"))
# path_to_week_minus_1 = here(weekly_CI_mosaic, paste0("week_",week_minus_1, "_", year_1, ".tif"))
# path_to_week_minus_2 = here(weekly_CI_mosaic, paste0("week_",week_minus_2, "_", year_2, ".tif"))
# path_to_week_minus_3 = here(weekly_CI_mosaic, paste0("week_",week_minus_3, "_", year_3, ".tif"))
path_to_week_current = get_week_path(weekly_CI_mosaic, today, 0)
path_to_week_minus_1 = get_week_path(weekly_CI_mosaic, today, -1)
path_to_week_minus_2 = get_week_path(weekly_CI_mosaic, today, -2)
path_to_week_minus_3 = get_week_path(weekly_CI_mosaic, today, -3)
log_message("required mosaic paths")
log_message(paste("path to week current",path_to_week_current))

Binary file not shown.

View file

@ -212,3 +212,24 @@ cum_ci_plot2 <- function(pivotName){
subchunkify(g, 3.2, 10)
}
get_week_path <- function(mosaic_path, input_date, week_offset) {
# Convert input_date to Date object (in case it's a string)
input_date <- as.Date(input_date)
# Get the start of the week for the input date (adjust to Monday as the start of the week)
start_of_week <- floor_date(input_date, unit = "week", week_start = 1)
# Calculate the new date after applying the week offset
target_date <- start_of_week + weeks(week_offset)
# Get the week number and year of the target date
target_week <- sprintf("%02d", isoweek(target_date)) # Left-pad week number with a zero if needed
target_year <- isoyear(target_date)
# Generate the file path for the target week
path_to_week <- here(mosaic_path, paste0("week_", target_week, "_", target_year, ".tif"))
# Return the path
return(path_to_week)
}