I am trying to remove images with clouds from a Sentinel-2 image collection with the following script:
// Remove images with clouds
var cloud_removal = function(image){
// save the quality assessment band QA60 as a variable
var cloud_mask = image.select('QA60');
// calculate the sum of the QA60-Band (because QA60 != 0 means cloud or cirrus presence)
var cloud_pixels = cloud_mask.reduceRegion( // reduceRegion computes a single object value pair out of an image
{reducer:ee.Reducer.sum(), // calculates the sum of all pixels..
geometry:aoi, // inside the specified geometry
scale:60}) // at this scale (matching the band resolution of the QA60 band)
.getNumber('QA60'); // extracts the values as a number
return ee.Algorithms.If(cloud_pixels.eq(0), image);
};
var s2_collection_noclouds = s2_collection_clipped.map(cloud_removal, true);
print('The clipped Sentinel-2 image collection without cloudy images: ', s2_collection_noclouds);
The problem is that the output ("s2_collection_noclouds") is an ee.FeatureCollection. I have already tried to cast the output as an image collection but it stays a feature collection:
var s2_collection_noclouds = ee.ImageCollection(s2_collection_clipped.map(cloud_removal, true));
What am i missing?