How to Remove Cloud Cover from Landsat Imagery

46 views Asked by At

I am trying to calculate average annual MSAVI2 point estimates, but I would like account for cloud cover in my analysis. I think this can be achieved by filtering my data to only include images with less than 10% cloud cover. I think can do this using the ee.Algorithms.Landsat.simpleComposite function, however when I apply the function to my filtered variable, I keep getting running the rest of my code which says that filtered.map is not a function.

My guess is that the simpleComposite function somehow changes the class of the filtered object, but I'm unsure how to correctly implement ee.Algorithms.Landsat.simpleComposite to only include images with less than 10% cloud cover.


var LS7 = ee.ImageCollection("LANDSAT/LE07/C02/T1"),

//filtering data
var filtered = LS7.filterDate('2016-01-01', '2016-12-31');
var filtered = ee.Algorithms.Landsat.simpleComposite({collection: filtered,asFloat:true})

 

// Map over the collection to produce the desired data as a collection.
var MSAVI2_collection = filtered.map(function (image) {
  return image.expression(
    '(2 * NIR + 1 - sqrt(pow((2 * NIR + 1), 2) - 8 * (NIR - RED)) ) / 2', 
    {
      'NIR': image.select('B4'), 
      'RED': image.select('B3')
    }
  );
});

//take an average of all MSAVI2 Values.
var MSAVI2 = MSAVI2_collection.median();

//add the MSAVI2 layer
Map.addLayer(MSAVI2, {min: -0.15, max: 0.15}, 'MSAVI2');
1

There are 1 answers

0
ciranzo On

I keep getting running the rest of my code which says that filtered.map is not a function.

The reason is that the output of ee.Algorithms.Landsat.simpleComposite is a simple image, not an ImageCollection ee object (according to the function documentation), and ee.Image does not have a map method.

To compute the MSAVI2 expression in a single image, follow this method:

// Check the image type of 'filtered' variable
print(ee.Algorithms.ObjectType(filtered));

// Compute MSAVI2 index
var getMSAVI2 = function(img){
  return img.expression(
    '(2 * NIR + 1 - sqrt(pow((2 * NIR + 1), 2) - 8 * (NIR - RED)) ) / 2', 
    {
      'NIR': img.select('B4'), 
      'RED': img.select('B3')
    });
};

// Apply above function to the composite image
var MSAVI2 = getMSAVI2(filtered);

//add the MSAVI2 layer
Map.addLayer(MSAVI2, {min: -0.15, max: 0.15}, 'MSAVI2');