0

I have an image collection which has undergone certain processes such as resampling and rescaling. Now I am trying to mosaic the images based on the date of acquisition.

I tried the code from Mosaicking Image Collection by Date (day) in Google Earth Engine

var start = ee.Date(start_date);
var finish = ee.Date(end_date);

// Difference in days between start and finish
var diff = finish.difference(start, 'day');

// Make a list of all dates
var range = ee.List.sequence(0, diff.subtract(1)).map(function(day) 
{return start.advance(day,'day')});

// Funtion for iteraton over the range of dates
var day_mosaics = function(date, newlist) {
// Cast
date = ee.Date(date);
newlist = ee.List(newlist);

// Filter collection between date and the next day
var filtered = Res_collection.filterDate(date, date.advance(1,'day'));

// Make the mosaic
var image = ee.Image(filtered.mosaic()).set('system:time_start',filtered.get('system:time_start'));

// Add the mosaic to a list only if the collection has images 
return ee.List(ee.Algorithms.If(filtered.size(), newlist.add(image), newlist));
};

// Iterate over the range to make a new list, and then cast the list to an imagecollection
var newcol = ee.ImageCollection(ee.List(range.iterate(day_mosaics, ee.List([]))));
print('Mosaic', newcol);

But I am getting 0 images in my output. I think I am losing the system:time_start property somewhere before the mosaic step (during resampling and rescaling) because the code runs fine before doing the processes.

Can someone identify the mistake that I am making?

My full code: https://code.earthengine.google.com/8f85b69b3009168cf76ae5e23471affc

2
  • Since you didn't share your asset, I can't check the code. My approach to this (since I had this issue before) is to create a new property called year-DOY, where I store date as Year-DayOfYear format. I call this property in the imagecollection creating a list, then I distinct (for removing duplicates) and finally I map by this later list.
    – aldo_tapia
    May 2, 2022 at 14:04
  • 1
    Thank you so much for your suggestion, it worked. May 2, 2022 at 16:21

0

Your Answer

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