Google Earth Engine – Adding Each Image to Previous Image Error

google-earth-enginejavascriptmodis

The below code has written to add each image to the previous image using iteration function but I don't know why returns negative values while positive expected!

enter image description here

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

Map.centerObject(table);

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


var startYear = '2001';
var endYear = '2021';

var modisLST = ee.ImageCollection("MODIS/006/MOD11A2")
.filterDate(startYear, endYear)
.filter(ee.Filter.calendarRange(5,9))
.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(
  ui.Chart.image.series(cummulative, table, ee.Reducer.mean(), 1000, 'system:time_start')
  )

Best Answer

The values seem to be correct, maybe you intended to filter to the months 5-9 instead of the days 5-9?

.filter(ee.Filter.calendarRange(5,9))

This by default takes the calendar Range from the 5th of January to the 9th of January which generally have temperatures below freezing. If you change it to:

.filter(ee.Filter.calendarRange(5, 9, "month"))

You will get the summer months you probably wanted.