var s2 = ee.ImageCollection("COPERNICUS/S2");
var pt = ee.Geometry.Point([-122.41653442382812, 37.77180027337861]);
var cloudyImage = ee.Image('COPERNICUS/S2/20151207T190417_20151207T221905_T10SEG');
Map.centerObject(cloudyImage, 10);
Map.addLayer(cloudyImage, {bands: ['B4', 'B3', 'B2'], max: 2000}, 'cloudy image');
// Bits 10 and 11 are clouds and cirrus, respectively.
var cloudBitMask = ee.Number(2).pow(10).int();
var cirrusBitMask = ee.Number(2).pow(11).int();
var qa = cloudyImage.select('QA60');
Map.addLayer(qa.bitwiseAnd(cloudBitMask).neq(0), {}, 'clouds');
Map.addLayer(qa.bitwiseAnd(cirrusBitMask).neq(0), {}, 'cirrus');
function maskS2clouds(image) {
var qa = image.select('QA60');
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(
qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask);
}
var cloudMasked = s2.filterBounds(pt).map(maskS2clouds);
var median = cloudMasked.median();
Map.addLayer(median, {bands: ['B4', 'B3', 'B2'], max: 2000}, 'median');
var s2 = ee.ImageCollection("COPERNICUS/S2");
var pt = ee.Geometry.Point([-122.41653442382812, 37.77180027337861]);
var cloudyImage = ee.Image('COPERNICUS/S2/20151207T190417_20151207T221905_T10SEG');
Map.centerObject(cloudyImage, 10);
Map.addLayer(cloudyImage, {bands: ['B4', 'B3', 'B2'], max: 2000}, 'cloudy image');
// Bits 10 and 11 are clouds and cirrus, respectively.
var cloudBitMask = ee.Number(2).pow(10).int();
var cirrusBitMask = ee.Number(2).pow(11).int();
var qa = cloudyImage.select('QA60');
Map.addLayer(qa.bitwiseAnd(cloudBitMask).neq(0), {}, 'clouds');
Map.addLayer(qa.bitwiseAnd(cirrusBitMask).neq(0), {}, 'cirrus');
function maskS2clouds(image) {
var qa = image.select('QA60');
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(
qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask);
}
var cloudMasked = s2.filterBounds(pt).map(maskS2clouds);
var median = cloudMasked.median();
Map.addLayer(median, {bands: ['B4', 'B3', 'B2'], max: 2000}, 'median');