0

I'm working on creating an NDVI time series and I'm trying to filter out clouds over a specific region so I wont get huge gaps in the time series.

Is there a way to reduce the extent by cloud percent?

Part of the 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 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);
};

var cloudper = function(image){
  return image.reduceRegion({
  reducer: ee.Reducer.mean(),
  geometry: extent,
  scale: 30,
  maxPixels: 1e9
})};

//var LS7Collection = LS7Collection.filter(ee.Filter.lessThan(cloudper(c.map(clouds)), 10));
//print(LS7Collection);

my full code: https://code.earthengine.google.com/?accept_repo=users/tomcol/personal

2
  • I'm not sure how you want this to work in detail. You're not trying to mask out cloudy pixels in individual scenes, or mask out pixels that have too many cloudy pixels in the time-series, but to exclude scenes with too high cloud cover? Jun 9, 2022 at 13:03
  • I managed to mask out cloudy pixels from the collection but I get NULL values instead. I want to generate a collection with scenes that have specified cloudy pixel percentage over specific regions. Jun 15, 2022 at 13:22

1 Answer 1

0

I found one way of doing this.

By cliping the image collection to the region of interest and then applying a "CLOUD_COVER" filter with wanted cloud percent.

I used this code:

var LS8 = ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")
var LS8Collection = LS8.map(function(image){return image.clip(regions)});
var LS8Collection = LS8Collection.filter(ee.Filter.lte('CLOUD_COVER_LAND', 10));
print(LS8Collection);

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.