library(terra)
terra 1.8.5
Wesley Rancher
December 27, 2024
January 21, 2025
# iterate over a sequence of years and pull out files specific to the year in the sequence
# mosaics <- list()
# years <- seq(2019, 2023)
# years_string <- as.character(years)
# for (i in seq_along(years_string)) {
#
# #pull out unique year
# year <- years_string[[i]]
# files_one_year <- list_of_files[grepl(year, list_of_files)]
files_one_year <- list_of_files
list_of_rasters <- lapply(files_one_year, function(file) {
r <- rast(file)
r
})
# get band names for retention
#band_names <- names(list_of_rasters[[1]])
#flattened_band_names <- unlist(band_names)
# turn list in sprc and mosaic
coll_of_rasters <- sprc(list_of_rasters)
#print(paste0(year, " start: ", Sys.time()))
mosaiced_raster <- merge(coll_of_rasters)
|---------|---------|---------|---------|
=========================================
#print(paste0(year, " finish: ", Sys.time()))
#names(mosaiced_raster) <- band_names
#print(names(mosaiced_raster))
#save it
# output_filename <- paste0(file_dir, "s1v-mosaic-", year, ".tif")
# print(output_filename)
# #writeRaster(mosaiced_raster, filename = output_filename, filetype = "GTiff", overwrite = TRUE)
# mosaics[[i]] <- mosaiced_raster
# rm(list_of_rasters, coll_of_rasters, mosaiced_raster)
# gc()
#}