I am doing a time series analysis of NDVI using the bfast package in R. Bfast requires a time series (TS) object.

I have successfully created a data frame with the NDVI at various point locations for tiffs in a given directory (code for this is at the bottom of the post).

Problem 1: the code does not extract the date of the images. Landsat file names give year and Julian day starting at the 10th character (YYYYDDD) so this should be possible. But how? And will the Julian day be recognized as a date?

Problem 2: once the date is extracted, how do I create TS object from the data frame?

Thanks for any tips! I'm new at R, so be gentle.

Code for extracting values at point locations:

pts <- readOGR(getwd(), "MyPoints")
LS.files <- list.files(getwd(),pattern="\\.tif$", full.names=FALSE)
India.LS <- stack(LS.files)
pts@data <- data.frame(pts@data, extract(India.LS, pts))

This will require some coercion on your part. The column names resulting from extract correspond to the raster names of your stack. You will need to start looking into the ts class objects and how to specify series and timesteps. It sounds like you may need to transpose your data, using t(), to orient it correctly.

Here is a quick example that generates three series and a monthly timestep (1961-1969) using coercion of a 3x100 matrix:

( myTimeDat <- ts(matrix(rnorm(300), 100, 3), start=c(1961, 1), frequency=12) ) 
  class( myTimeDat ) 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.