Mosaicking a Image Collection by Date (day) in Google Earth Engine
var poly = /* color: #d63000 */ee.Geometry.Polygon(
[[[-76.0803, 10.8656],
[-76.0913, 7.7436],
[-73.1909, 7.7545],
[-73.3776, 9.4273],
[-75.2124, 10.9304]]])
var start = ee.Date('2014-10-01');
var finish = ee.Date('2018-03-31');
var collection = ee.ImageCollection('COPERNICUS/S1_GRD')
.filterDate(start, finish)
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
.filter(ee.Filter.eq('instrumentMode', 'IW'))
.filterMetadata('resolution_meters', 'equals', 10)
.filterBounds(poly);
// 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 = collection.filterDate(date, date.advance(1,'day'))
// Make the mosaic
var image = ee.Image(filtered.mosaic())
// 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(newcol)
https://code.earthengine.google.com/20ad3c83a17ca27b28640fb922819208
Here is another solution that does not involve iterating through days, but maps through unique dates (after removing seconds, microseconds...) that appear in the image collection. It also adds the image date as the id as @erg asked in a commentary above.
function mosaicByDate(imcol){
// imcol: An image collection
// returns: An image collection
var imlist = imcol.toList(imcol.size())
var unique_dates = imlist.map(function(im){
return ee.Image(im).date().format("YYYY-MM-dd")
}).distinct()
var mosaic_imlist = unique_dates.map(function(d){
d = ee.Date(d)
var im = imcol
.filterDate(d, d.advance(1, "day"))
.mosaic()
return im.set(
"system:time_start", d.millis(),
"system:id", d.format("YYYY-MM-dd"))
})
return ee.ImageCollection(mosaic_imlist)
}