I am now using fmask algorithm to eliminate the cloud covered areas on Landsat images.
I choose a period of time (Jan 1st 2017 to Dec 31st 2017), and selected the study area (Florida). I want to get all of the Landsat 8 images under the above mentioned conditions, then apply the algorithm to mask the cloud.
I hoped the images taken for the same area but on different observation days could all get cloud masked, overlapped together and then I can do some statistical calculation.
However, I can only get the cloud masked images for Dec 31st 2017. I have tried a lot but still cannot overlap the images for the whole year.
My code is attached below
//Choose country using GEE Feature Collection
var region = ee.FeatureCollection('TIGER/2016/States')
.filter(ee.Filter.or(
ee.Filter.eq('NAME', 'Florida')));
//Add region outline to layer ‐ for selected states
//Map.addLayer(region,{}, 'Florida');
var landsat8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR');
// Fmask classification values var FMASK_CLEAR_GROUND = 0; var FMASK_WATER = 2; var FMASK_CLOUD_SHADOW = 3; var FMASK_SNOW = 4; var FMASK_CLOUD = 5;
var mosaic = landsat8 .filterBounds(region) .filterDate('2017-01-01', '2017-12-31') .mosaic();
var getQABits = function(image, start, end, newName) {
// Compute the bits we need to extract.
var pattern = 0;
for (var i = start; i <= end; i++) {
pattern += Math.pow(2, i);
}
// Return a single band image of the extracted QA bits, giving the band
// a new name.
return image.select([0], [newName])
.bitwiseAnd(pattern)
.rightShift(start);
};
// A function to mask out cloudy pixels.
var cloud_shadows = function(image) {
// Select the QA band.
var QA = image.select(['pixel_qa']);
// Get the internal_cloud_algorithm_flag bit.
return getQABits(QA, 3,3, 'Cloud_shadows').eq(0);
// Return an image masking out cloudy areas.
};
// A function to mask out cloudy pixels.
var clouds = function(image) {
// Select the QA band.
var QA = image.select(['pixel_qa']);
// Get the internal_cloud_algorithm_flag bit.
return getQABits(QA, 5,5, 'Cloud').eq(0);
// Return an image masking out cloudy areas.
};
var maskClouds = function(image) {
var cs = cloud_shadows(image);
var c = clouds(image);
image = image.updateMask(cs);
return image.updateMask(c);
};
var mosaic_free = maskClouds(mosaic);
var visParams = {bands: ['B4', 'B3', 'B2'],min: [0,0,0],max: [2000, 2000, 2000]};
Map.addLayer(mosaic, visParams, 'With clouds');
Map.addLayer(mosaic_free, visParams, 'Cloud free');
Could anybody help me to figure out what's wrong with that?