I am using the Sentinel-2 time series to identify the timing of forest disturbances using Google Earth Engine. I calculated the Normalized Burned Ratio (NBR) Index and I filled in the gaps in the time series. As can be seen in the following image there is a disturbance (breakpoint) at 2022-08-18. To identify these breakpoints my goal is: for each NBR image in the collection, subtract the value of the previous NBR image in the collection.

enter image description here

I am trying to do this using the .iterate() function but I don't know where my error is. Complette script here: https://code.earthengine.google.com/473b9f15fee6c2c21f162c3265912495

My failed code here:

// Breakpoint detection

var time0 = nbrCol.first().get('system:time_start');
var first = ee.List([
  ee.Image(0).set('system:time_start', time0).select([0], ['nbr'])

function breakPoint(image, list){
  var previous = ee.Image(ee.List(list).get(-1));
  var difference = image.subtract(previous).set('system:time_start', image.get('system:time_start'));
  return difference;

var diffCol = ee.ImageCollection(ee.List(nbrCol.iterate(breakPoint, first)));


ImageCollection (Error) List.get, argument 'list': Invalid type. Expected type: List. Actual type: Image<[nbr]>.

1 Answer 1


You have to keep track of both the previous image and the resulting difference. If your iteration populate an image collection, previous image can be put as a property of the accumulated collection.

I didn't read through your script in details, but noticed that you did join collections. Perhaps you already have access to previous image from that join? If so, you simply have to map over your collection, get the previous image from the join property, and finally return the difference. That would be more efficient.

With the iteration, this should work:

function breakPoint(image, acc){
  acc = ee.ImageCollection(acc)
  image = ee.Image(image)
  var previous = ee.Image(acc.get('previous'))
  var difference = image.subtract(previous)
  return acc.merge(ee.ImageCollection([difference]))
    .set('previous', image)

var diffCol = ee.ImageCollection(nbrCol
    ee.ImageCollection([first]).set('previous', nbrCol.first())


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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