0

I'm trying to filter clouds over a specific region for an NDVI time series using Landsat collection 2.

I tried filtering with simple cloud score but it doesn't seem to work (maybe because there is no simpleCloudScore?).

Here's part of my full code:

var extent = 
    /* color: #44c239 */
    /* displayProperties: [
      {
        "type": "rectangle"
      }
    ] */
    ee.Geometry.Polygon(
        [[[35.66951628813774, 33.212344469176244],
          [35.66951628813774, 33.18720738523013],
          [35.69560881743462, 33.18720738523013],
          [35.69560881743462, 33.212344469176244]]], null, false);
          
// Applies scaling factors for LS 457.
function applyScaleFactors457(image) {
  var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
  var thermalBand = image.select('ST_B6').multiply(0.00341802).add(149.0);
  return image.addBands(opticalBands, null, true)
              .addBands(thermalBand, null, true);
}

var startdate = '2000-08-01';
var enddate= '2021-08-01';

var LS7Collection = ee.ImageCollection('LANDSAT/LE07/C02/T1_L2')
  .filterBounds(extent)
  .filterDate(startdate, enddate)
  .map(applyScaleFactors457);

//filer clouds by region ????
var c = LS7Collection.filterBounds(extent);

var withCloudiness = c.map(function(image) {
  var cloud = ee.Algorithms.Landsat.simpleCloudScore(image).select('cloud');
  var cloudiness = cloud.reduceRegion({
    reducer: 'mean', 
    geometry: extent, 
    scale: 30,
  });
  return image.set(cloudiness);
});

var LS7Collection = withCloudiness.filter(ee.Filter.eq('cloud', 0));
print(LS7Collection);

Link to the full code: https://code.earthengine.google.com/?scriptPath=users%2Ftomcol%2Fpersonal%3ANDVI%20SERIES%20LANDSAT%207

1
  • Welcome to GIS SE. Thank you for taking the Tour. Unfortunately, you seem to have missed the emphasis on asking One question per Question. A bulleted list of questions will quickly generate close votes. You've also got a ton of code to pour through. Please cut it down to just the relevant code snippet for a single issue.
    – Vince
    Commented May 18, 2022 at 12:24

1 Answer 1

0

ee.Algorithms.Landsat.simpleCloudScore() won't work because the input for this algorithm is a TOA image:

Arguments:

- image (Image): The Landsat TOA image to process.

Since your product is SR, you can use SR_CLOUD_QA (bitmask):

  • Bit 0: Dark Dense Vegetation (DDV)
  • Bit 1: Cloud
  • Bit 2: Cloud Shadow
  • Bit 3: Adjacent to Cloud
  • Bit 4: Snow
  • Bit 5: Water

This layer will help you to define the cloud

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);
};

var clouds = function(image) {
  // Select the QA band.
  var QA = image.select(['SR_CLOUD_QA']);
  // Get the internal_cloud_algorithm_flag bit.
  return getQABits(QA, 1,1, 'Clouds').eq(1);
};

Full example code for one cloudy date: https://code.earthengine.google.com/46592b18ddb7ed11b4986f2f0698d70f

2
  • Great! that fixes the cloud score problem. but how can I filter cloud percent over the extent for the whole collection? I added the link to the full code above. Commented May 24, 2022 at 6:17
  • Create a dictionary with cloud reducer and then filter by id. That's a new question, I can't add more details in my answer
    – aldo_tapia
    Commented May 24, 2022 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.