I want to reduce every single image in a collection, but I have not been able to make it. The process is really easy and works with a single image, but I need to do the same for every image in the collection.
My code:
// Statistics function
var stats = function(img) {
var image = ee.Image(img);
var reducers = ee.Reducer.mean().combine({
reducer2: ee.Reducer.stdDev(),
sharedInputs: true
});
var stats = image.reduceRegion({
reducer: reducers,
//geometry: geometry(),
bestEffort: true,
});
return stats;
}
//Load collection
var collection = ee.ImageCollection('COPERNICUS/S2');
// Extract the image index from collection and make a list
var index = ee.List(['20190101T160509_20190101T160509_T17RNJ',
'20190104T160649_20190104T161509_T17RLH',
'20190104T160649_20190104T161509_T17RMJ',
'20190104T160649_20190104T161509_T17RMK']);
// Filter collection by image id list
var coll = collection
.filter(ee.Filter.inList('system:index',index));
The reducer works perfectly for a single image
// Apply the statistics function over the whole extent of a single image
var one_stats = stats(coll.first());
print('One Stats',one_stats)
But, it does not work properly for every image in a collection
// Apply the statistics function over the whole extent of every image
var all_stats = coll.map(stats);
print('All Stats',all_stats)