I know that there are a lot of examples of how to mask clouds for sentiel-2 images, but what I want is sort the images over an area of interest without change anything of the image.
Applying a cloud mask in zones where there are to much clouds, changes dramatically the image (in this case in over Bogota-Colombia). And, in some cases it generates holes in the image. thats why i dont want to change anything about the image.
I am taking this code Filter Landsat images base on cloud cover over a region of interest as reference.
and here is how it will be with Sentinel-2 image.
//the parameter for sentiel-2 images for clouds is
//CLOUDY_PIXEL_PERCENTAGE
var ic =ee.ImageCollection('COPERNICUS/S2');
// A polygon representing the roi.
// my_polygon es a random polygon over Bogota Colombia (very cloudy zone)
var geometry = my_poligon;
var c = ic.filterBounds(geometry);
var withCloudiness = c.map(function(image) {
var cloud = ee.Algorithms.Landsat.simpleCloudScore(image).select('cloud');
var cloudiness = cloud.reduceRegion({
reducer: 'mean',
geometry: geometry,
scale: 30,
});
return image.set(cloudiness);
});
var filteredCollection = withCloudiness.filter(ee.Filter.lt('cloud', 10));
print(filteredCollection);
//my image with less clouds over my zone of interest
var my_image = ee.Image(filteredCollection.filterBounds(centroid)
.filterDate('2019-01-01', '2019-06-30')
.sort('CLOUDY_PIXEL_PERCENTAGE')
.first());