error to generate regular raster stack time series in R

15 Views Asked by At

I try to convert regular time series raster stack using bfastts funcion in bfast model in R. When I can generate a time series for 1 pixel (s in the example). However, I cannot generate time series for all pixels of raster stack tura (s_tura). When run the script below, it has

Error in NextMethod("[<-") : 
  number of items to replace is not a multiple of replacement length
# load data
library(raster)
library(lubridate)
library(sf)
library(bfastSpatial)
library(bfast)
library(zoo)

data(tura)
names(tura)
dates <- getZ(tura) ## get the image dates
selected_pixel <- 90
s <- bfastts(as.vector(tura[selected_pixel]), dates, type = c("irregular"))# create a regular time-series
tura_matrix <- raster::extract(tura, 1:ncell(tura), df = TRUE) # Convert raster stack to a matrix
tura_matrix <- as.matrix(tura_matrix[, -1]) 
s_tura <- bfastts(tura_matrix, dates, type = c("irregular"))
0

There are 0 best solutions below