I want to take out snow and use a less cloud Landsat image. I am not sure the code from var image.... I think this is the right order (filterData, sort, median and map) but it does not work.
function maskL8sr(image) {
// Bits 3 and 5 are cloud shadow and cloud, respectively.
var cloudShadowBitMask = (1 << 3);
var cloudsBitMask = (1 << 5);
var snowBitMask = (1 << 4);
var waterBitMask = (1 << 2);
// Get the pixel QA band.
var qa = image.select('pixel_qa');
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(snowBitMask).eq(0);
return image.updateMask(mask);
}
var image = ee.Image(ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterDate('2018-01-01', '2018-12-31')
.map(maskL8sr)
.sort('CLOUD_COVER')
.median());