I am trying to create LAI (Leaf Area Index) ImageCollection from Sentinel-2 https://code.earthengine.google.com/558a6788e0c9db0c645ac6cd49debe51.

My process is like this: S2_collection -> output_collection_LAI (using SL2P library) -> LAI_collection_withTime (adding 'time_start' from S2_collection, this step for creating LAI profile in the future).

But I realised that when I used the filterDate function for the LAI_collection_withTime, it seemed not work.

For example, when I tested the size of S2_collection from '2019-01-01' to '2019-01-31', it was 48. But when I filtered the LAI_collection_withTime from '2019-01-01' to '2019-01-16', it was still 48, while it should be 24.

The code is below:

var dictionariesSL2P = require('users/richardfernandes/SL2P:dictionaries-SL2P'); // Specify collection and algorithms
var S2 = require('users/richardfernandes/SL2P:toolsS2')                     // Cloud masking and geometry for S2
var ib = require('users/richardfernandes/SL2P:imageBands')                     // Cloud masking and geometry
var SL2P = require('users/richardfernandes/SL2P:SL2P')                     // Cloud masking and geometry

var collectionName_harmonized = "COPERNICUS/S2_SR_HARMONIZED";

// Fetch collection options and filtered S2 composite
var colOptions = ee.Dictionary(ee.Dictionary(dictionariesSL2P.make_collection_options()).get(collectionName_harmonized));
var S2_collection = ee.ImageCollection(collectionName_harmonized)
            .filterDate('2019-01-01', '2019-01-31')

switch (collectionName_harmonized) {
    S2_collection = S2_collection.map(S2.S2MaskClear)

var var_LAI = 'LAI'
var output_collection_LAI = ee.ImageCollection(SL2P.applySL2P(collectionName_harmonized, S2_collection, var_LAI, dictionariesSL2P));


var matchedTimeStart = function(image){
  var timeStart = S2_collection.filter(ee.Filter.equals('system: index', image.get('system: index')))
  return image.set('system:time_start', timeStart);
var LAI_collection_withTime = output_collection_LAI.map(matchedTimeStart);

var filteredCollection = ee.ImageCollection(LAI_collection_withTime).filterDate('2019-01-01', '2019-01-16');

1 Answer 1


I believe it is because you have a misplaced space in your system:index property keys inside the matchedTimeStart function.

var matchedTimeStart = function(image){
  //                                     remove the space here |      and the space here |
  //                                                           V                         V
  var timeStart = S2_collection.filter(ee.Filter.equals('system:index', image.get('system:index')))
  return image.set('system:time_start', timeStart);

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.