I have filtered a Sentinel-2 image and created a cloud mask for it based on its QA60 band. It works fine and displays with this mask applied. However, when I try to export it to a drive, I get the following error message:
Error: Image.clipToBoundsAndScale, argument 'input': Invalid type. Expected type: Image. Actual type: ImageCollection.
Why is this happening and how can I fix it? My code is below.
//define the cloud mask layer
function maskS2clouds(image) {
var qa = image.select('QA60');
var cloudBitMask = 1 <<10;
var cirrusBitMask = 1 <<11;
//layer called mask = the cloudy bits
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
//'image' is a layer with the mask applied to it
return image.updateMask(mask).divide(10000);
}
//image collection is filtered
var dataset = ee.ImageCollection("COPERNICUS/S2")
.filterBounds(geometry)
.filterDate('2015-08-26', '2015-08-28')
.map(maskS2clouds);
//image with mask applied
Map.addLayer(dataset);
//exported to drive
Export.image.toDrive({
image:dataset,
description: '2015_CLOUDFREE',
folder: 'users/emilywest2',
region: geometry.geometry,
scale: 10,
});