Google Earth Engine – Calculating Regular Day Interval Means in Image Collections

google-earth-enginelandsatmodisspatio-temporal-data

I've merged three Landsat collections in Google Earth Engine, now I need to calculate median values at regular time intervals, let's say 32 days, because I will create a collection to join with MODIS. However, when I do that, I lose the "system:time.start" information from Landsat Merged collections. Does anyone knows how to calculate this regular medians based on DOY? I want to filter the Landsat_merge collection to 32 days regular interval!

This is the code so far:
Code to access MODIS Landsat Joined collections

Best Answer

Here's a snippet to get you started, based on code in this blog post:

var temporalCollection = function(collection, start, count, interval, units) {
  // Create a sequence of numbers, one for each time interval.
  var sequence = ee.List.sequence(0, ee.Number(count).subtract(1));

  var originalStartDate = ee.Date(start);

  return ee.ImageCollection(sequence.map(function(i) {
    // Get the start date of the current sequence.
    var startDate = originalStartDate.advance(ee.Number(interval).multiply(i), units);

    // Get the end date of the current sequence.
    var endDate = originalStartDate.advance(
      ee.Number(interval).multiply(ee.Number(i).add(1)), units);

    return collection.filterDate(startDate, endDate).median()
        .set('system:time_start', startDate.millis())
        .set('system:time_end', endDate.millis());
  }));
};

var landsat8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA');

var result = temporalCollection(landsat8, '2016-01-01', 12, 32, 'day');

var first = ee.Image(result.first());
Map.addLayer(first, {bands: ['B4', 'B3', 'B2'], min: 0, max: 0.3}, 'first');

Note that another variant of this is described in this answer.

Related Question