0

The below code is going to calculate accumulative temperature by adding each image to the previous ones. Despite it works and plots values but csv file shows many dates have been missed before. Does anyone have a solution on this problem?

enter image description here

Code link: https://code.earthengine.google.com/0de85ad6e2fe8de2a39fb9dd6012f978

Map.centerObject(table);

var startYear = '2010-01-01';
var endYear = '2011-01-01';


var lst = function(img){
  var bands = img.select('LST_Day_1km').multiply(0.02).clip(table);
  return bands
  .copyProperties(img,['system:time_start','system:time_end']);
};

var modisLST = ee.ImageCollection("MODIS/006/MOD11A2")
.filterDate(startYear, endYear)
.filterBounds(table)
.map(lst);


var time0 = modisLST.first().get('system:time_start');

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

var accumulate = function(img, list){
  
  var previous = ee.Image(ee.List(list).get(-1));
  var added = img.add(previous)
  .set('system:time_start', img.get('system:time_start'));
  
  return ee.List(list).add(added);
};


var cummulative = ee.ImageCollection(ee.List(modisLST.iterate(accumulate, first)));

print(cummulative);


print(
  ui.Chart.image.series(cummulative, table, ee.Reducer.first(), 1000, 'system:time_start')
  );
  

1 Answer 1

0

As soon as you encounter a masked pixel when accumulating your value, the result will be masked.

  var added = img.add(previous)

To workaround that, you could unmask img to the value 0

  var added = img.unmask(0).add(previous)

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.