I'm following the answer on Filter out "incomplete" Sentinel-2 images in Earth Engine to make daily mosaics of Sentinel 2 images.
However, I was expecting that the resulting imageCollection (daily) would have less images than the original filtered collection (s2), as these are mosaicked together by date and orbit, but the number of images in each collection is the same.
//ee.Geometry.Rectangle(minLng, minLat, maxLng, maxLat) ie xmin, ymin, xmax, ymax
var aoi = ee.Geometry.Rectangle(-7.50,47.00,6.50,54.00); // region of all sites in Europe
var s2 = ee.ImageCollection('COPERNICUS/S2_SR')
.filterBounds(aoi)
.filterDate('2019-01-01', '2019-01-05') // // %Y-%m-%d
.map(function (image) {
return image
.set('date', image.date().format('yyyy-MM-dd'));
});
print(s2.size());
print(s2.first(), 'first S2 image');
var daily = ee.ImageCollection(
ee.Join.saveAll('images').apply({
primary: s2,
secondary: s2,
condition: ee.Filter.and(
ee.Filter.equals({
leftField: 'date',
rightField: 'date'
}),
ee.Filter.equals({
leftField: 'SPACECRAFT_NAME',
rightField: 'SPACECRAFT_NAME'
}),
ee.Filter.equals({
leftField: 'SENSING_ORBIT_NUMBER',
rightField: 'SENSING_ORBIT_NUMBER'
})
)
})
)
.map(function (image) {
return ee.ImageCollection(ee.List(image.get('images')))
.mosaic()
.set('system:time_start', ee.Date(image.get('date')).millis());
});
// print(daily);
print(daily.size());
var listOfImages = daily.toList(daily.size());
// print(listOfImages);
var img1 = ee.Image(listOfImages.get(1)); // second image
var img2 = ee.Image(listOfImages.get(100));
var img3 = ee.Image(listOfImages.get(200));
print(daily.first(), "first image in daily");
print(img2, "second image in daily");
Map.centerObject(aoi, 6);
Map.addLayer(daily.first(), {bands: 'B4,B3,B2', min: 300, max: 3000});
Map.addLayer(img1, {bands: 'B4,B3,B2', min: 300, max: 3000});
Map.addLayer(img2, {bands: 'B4,B3,B2', min: 300, max: 3000});
Map.addLayer(img3, {bands: 'B4,B3,B2', min: 300, max: 3000});
Map.addLayer(aoi, {}, 'aoi', true, 0.4);
When I display the first, and second image, for example, they appear the same, but with slightly different start times in the new field "time_start". Images 101 and 201 are different - I was expecting to get a smaller number of such images in the collection to process further.
Is this possible?
I can see now that the join adds a property images
to each image in the collection with the matching images. Then the mosaic part mosaics each image with those matches in images
, therefore producing multiple identical mosaics for each group of matches.
Either I could identify the unique lists of matches from each list in images
, or alternatively, I could get a list of unique dates, spacecraft names and orbits from the imageCollection s2, and then filter by these, and mosaic.
Any suggestions as to which is best and some pointers towards the code?