I am trying to create a decent cloudfree mosaic of Landsat 7 Tier 2 TOA reflectance around the Amery Iceshelf in Antarctica. I did find a good script for landsat 8 TOA (Apply a cloud mask to a Landsat8 collection in Google Earth Engine - time series) and those work for me, however when I try to change this to landsat 7 with the correct parameters, it doesn't.
Next to the couldmask issue, the result is a collection, whereas I would like to have 1 (mosaiced) image. Any idea?
This is the code I am using at the moment:
var geometry = /* color: #00ffff */ee.Geometry.Polygon(
[[[92.57694067490729, -70.98282239796863],
[57.06912817490718, -70.57777747363254],
[51.35623754990718, -76.61497412799037],
[91.96170629990729, -77.28946992862909],
[92.66483129990729, -71.18228294956876]]]);
// TOA L7 dataset
var mosaic = ee.ImageCollection("LANDSAT/LE07/C01/T2_TOA")
.filterDate('1999-12-01', '2003-03-01')
// .filterMetadata('CLOUD_COVER', 'less_than',10)
.filterBounds(geometry)
// .sort('CLOUD_COVER',false)
// .first()
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 mosaic_free = mosaic.map(maskClouds);
var visParamsPanSharp = {bands: ['red', 'green', 'blue'],min: [0,0,0],max: [1, 1, 1]};
Map.addLayer(mosaic, visParams, 'With clouds');
Map.addLayer(mosaic_free, visParams, 'Cloud free');