1. Go to sepal.io and log in to your account.

  2. Click on Terminal and create a new session type 14 c4.8xlarge, 36 CPU.

  3. Open Rstudio from the Process menu.

Create a new R script and copy the following code:

  workshop_folder <- "~/wur_bfast_workshop" 
  dir.create(file.path(workshop_folder)) # Creates a directory for this workshop in your SEPAL account

  download.file("https://www.dropbox.com/sh/299x5vdroyaqqs1/AAByVqMU3rH6LIxb2jIxPuDMa/R-scripts?dl=1",
                file.path(workshop_folder,"R-scripts.zip"),"auto",mode="wb") 
  unzip(file.path(workshop_folder,"R-scripts.zip"),exdir=file.path(workshop_folder,"R-scripts"))

These lines download a copy of the full scripts of this tutorial, as an alternative to copy-pasting the code snippets. You should find the scripts in ~/wur_bfast_workshop/R-scripts

Installation and loading of required R packages

Bfast and its required dependencies can be installed directly from github:

if (!require(devtools)){ # install only if not installed
  install.packages("devtools", repos="http://cran.rstudio.com/")
  library(devtools)
}
if (!require(stringr)){ # install only if not installed
  install.packages("stringr", repos="http://cran.rstudio.com/")
  library(stringr)
}
if (!require(bfastSpatial)){ # install only if not installed
  install_github("loicdtx/bfastSpatial")
  library(bfastSpatial)
}

Downloading the data

if(!file.exists(file.path(workshop_folder,"data.zip"))){
  download.file("https://www.dropbox.com/sh/299x5vdroyaqqs1/AAC73-EIRslzrw2B5xEpw1eza/data?dl=1",
                file.path(workshop_folder,"data.zip"),"auto",mode="wb")
  unzip(file.path(workshop_folder,"data.zip"),exdir=file.path(workshop_folder,"data"))
}

Loading the input data for analysis

ndmiStack <- brick(file.path(workshop_folder,"data/Peru_ndmi_stack.grd"))
ndmiStack
## class       : RasterBrick 
## dimensions  : 334, 334, 111556, 235  (nrow, ncol, ncell, nlayers)
## resolution  : 30, 30  (x, y)
## extent      : 374055, 384075, -676185, -666165  (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
## data source : /home/andrei/wur_bfast_workshop/data/Peru_ndmi_stack.grd 
## names       : LT50080642000123, LT50080642000139, LT50080642000171, LT50080642000203, LT50080642000219, LT50080642000251, LT50080642000267, LT50080642000315, LT50080642000331, LT50080642001013, LT50080642001029, LT50080642001109, LT50080642001125, LT50080642001205, LT50080642001221, ... 
## min values  :             -664,             2528,             1755,               NA,            -1499,             -686,               NA,            -1644,            -2533,            -1520,            -2046,             -908,             1817,             1902,            -2809, ... 
## max values  :             5206,             4627,             5902,               NA,             6162,             6712,               NA,             6921,             5963,             6455,             6339,             6732,             5374,             4686,             5727, ... 
## time        : 2000-05-02, 2016-09-27 (min, max)
ndviStack <- brick(file.path(workshop_folder,"data/Peru_ndvi_stack.grd"))
ndviStack

Creating an output directory

All the results will be saved in this folder

results_directory <- file.path(workshop_folder,"data/Bfast_results")
if (!dir.exists(results_directory)){
  dir.create(results_directory)
}