gap fill for raster stack in R

20 views Asked by At

I have irregular time series NDVI raster stack over a year and there is no data for July. I would like to generate the irregular time series to a monthly regular time series to run bfast model in R. First, I run the monthly NDVI, so I get monthly for all year 2022 except the july. How can I gap the missing data in July in R?

My script and data below:

setwd("P:/Mosaic")
listsen2 =list.files(pattern = ".tif$", all.files=TRUE,full.names = FALSE) 
sen2=stack(listsen2) # Create a raster stack from the .tif files
listsen2_dates =  substr(basename(listsen2), 1, 8) # Extract dates from file names
listsen2_dates <- as.Date(listsen2_dates, "%Y%m%d") # Convert dates to Date objects
names(sen2) <- listsen2_dates # Assign the extracted dates as layer names to the raster stack
# Convert layer names to dates
layer_name <- sub('.', '', names(sen2))
layer_name <- ymd(layer_name)
indices <- format(as.Date(layer_name, format = "%Y-%m-%d"), format = "%Y-%m") 
NDVI_mean <- stackApply(sen2, indices, mean)

enter image description here

0

There are 0 answers