I have tried to apply a cloud mask for a landsat 8 collection using code1, code2, and code3 but none will work.
code1 encounters the error of not working even after changing
var mask = img.select(['cfmask']).neq(4)
to
var mask = img.select(['pizel_qa_bands']).neq(3)
code2 encounters the problem of not being a time series dataset. I want to be able to extract pixel values for each image over a period of time but this code only gives one output of pixel values.
and I can't adapt my script to code3.
Here is my script and all i want to do is remove the clouds and cloud cover from a Landsat8 image collection
var l8_mayo = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterDate('2000-01-01', '2018-12-31')
.filter(ee.Filter.eq('WRS_PATH', 208))
.filter(ee.Filter.eq('WRS_ROW', 23));
var visParams = {bands: ['B4', 'B3', 'B2'], max: 0.3};
Map.setCenter(-9, 53, 8);
Map.addLayer(l8_mayo, visParams, 'l8_mayo collection');`
Answer
code2 works. Adapt it properly with right parameters (Always check metadata):
var l8_mayo = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterDate('2000-01-01', '2018-12-31')
.filter(ee.Filter.eq('WRS_PATH', 208))
.filter(ee.Filter.eq('WRS_ROW', 23));
var visParams = {bands: ['B4', 'B3', 'B2'], max: 0.3};
Map.setCenter(-9, 53, 8);
Map.addLayer(l8_mayo, visParams, 'l8_mayo collection');
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(['BQA']);
// Get the internal_cloud_algorithm_flag bit.
return getQABits(QA, 7,8, 'Cloud_shadows').eq(1);
// 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(['BQA']);
// Get the internal_cloud_algorithm_flag bit.
return getQABits(QA, 4,4, '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 l8_mayo_free = l8_mayo.map(maskClouds);
Map.addLayer(l8_mayo_free, visParams, 'l8_mayo collection without clouds');
Link: https://code.earthengine.google.com/44cb99f8210800462da56640a275e674
There are some areas with cloud borders in image collection. Is a very cloudy area. BQA isn't perfect
No comments:
Post a Comment