1

I'm trying to filter Landsat images based on the percent of cloud cover for my ROI. I have tried to adapt code in link one and link two but cannot get what I want. My ROI has been imported as a feaureCollection and covers 8 Landsat tiles.

This is my code

//select images from image collection
var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1')
//LT05, LE07, LC08
.filterDate('1980-01-01', '2018-12-31')
.filter(ee.Filter.or(
ee.Filter.and(ee.Filter.eq('WRS_PATH', 208),         
              ee.Filter.eq('WRS_ROW', 22)),
ee.Filter.and(ee.Filter.eq('WRS_PATH', 208),         
              ee.Filter.eq('WRS_ROW', 23)),
ee.Filter.and(ee.Filter.eq('WRS_PATH', 208),         
              ee.Filter.eq('WRS_ROW', 24)),              
ee.Filter.and(ee.Filter.eq('WRS_PATH', 207),         
              ee.Filter.eq('WRS_ROW', 22)),              
ee.Filter.and(ee.Filter.eq('WRS_PATH', 207),         
              ee.Filter.eq('WRS_ROW', 23)),              
ee.Filter.and(ee.Filter.eq('WRS_PATH', 207),         
              ee.Filter.eq('WRS_ROW', 24)),
ee.Filter.and(ee.Filter.eq('WRS_PATH', 206),         
              ee.Filter.eq('WRS_ROW', 23)),
ee.Filter.and(ee.Filter.eq('WRS_PATH', 206),         
              ee.Filter.eq('WRS_ROW', 24))));

var c = l8.map(function(img) { return img.clip(my_geom); });

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

return image.set(cloudiness);
});
var filteredCollection = withCloudiness.filter(ee.Filter.lt('cloud', 20));
print(filteredCollection);

So I have two problems:

1: When using Landsat 8, the code runs, but it does not filter based on a threshold, 20% in this case. When i write the output to a file it gives two columns, cloud_cover and cloud_cover_land, both have observations of cloud greater than 20%.

2: When I try using Landsat 5 or 7 my file is empty...but I know there are scenes that are below 20% cloud cover for Landsat 5.

What I am I doing wrong?

2

The problem is that simpleCloudScore wants a TOA image and you're passing it raw images. The fact that L8 does anything is simply coincidence.

var c = ee.ImageCollection('LANDSAT/LT05/C01/T1_TOA')
  .filterDate('1980-01-01', '2018-12-31')
  .filter(ee.Filter.rangeContains('WRS_PATH', 206, 208))
  .filter(ee.Filter.rangeContains('WRS_ROW', 22, 24))

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

  return image.set(cloudiness);
});

var filteredCollection = withCloudiness.filter(ee.Filter.lt('cloud', 20));

print(withCloudiness.size())
print(filteredCollection.size());
0

About your second question, try this way to filter clouds from all collections

//mascara de nuvem e sombra

function maskL8sr(image) {
  // Bits 3 and 5 are cloud shadow and cloud, respectively.
  var cloudShadowBitMask = (1 << 3);
  var cloudsBitMask = (1 << 5);
  // Get the pixel QA band.
  var qa = image.select('pixel_qa');
  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
                 .and(qa.bitwiseAnd(cloudsBitMask).eq(0));
  return image.updateMask(mask);
}

///PADRONIZAR NOME DAS BANDAS____________________________________________________________________________________

var bname = ['blue', 'green', 'red', 'nir', 'swir1', 'swir2', 'temp','pixel_qa']
var bl4 = ['B1',   'B2',    'B3',  'B4',  'B5',    'B7',    'B6', 'pixel_qa'] //Landsat 7
var bl5 = ['B1',   'B2',    'B3',  'B4',  'B5',    'B7',    'B6', 'pixel_qa'] //Landsat 7
var bl7 = ['B1',   'B2',    'B3',  'B4',  'B5',    'B7',    'B6', 'pixel_qa'] //Landsat 7
var bl8 = ['B2',   'B3',    'B4',  'B5',  'B6',    'B7',    'B10', 'pixel_qa'] //Landsat 8

var rename_bands = function(img,input) {
return img.select(input, bname)
}

//IMPORTAR COLEÇÕES

var L4 = ee.ImageCollection("LANDSAT/LT04/C01/T1_SR")
           //.filterDate('1982-01-01', '1993-12-01')
           .filterMetadata('CLOUD_COVER', 'less_than',10)
           .filterBounds(table)
           //.map(cloudMaskL457)
           .map(function(image){return image.clip(table)})

print('L4', L4)           
           
var L5 = ee.ImageCollection("LANDSAT/LT05/C01/T1_SR")
           //.filterDate('1984-01-01', '2012-05-05')
           .filterMetadata('CLOUD_COVER', 'less_than',10)
           .filterBounds(table)
           //.map(cloudMaskL457)
           .map(function(image){return image.clip(table)})
           
print ('l5', L5)

var L7 =  ee.ImageCollection('LANDSAT/LE07/C01/T1_SR')
            .filterDate('1999-01-01', '2004-12-31')
           .filterMetadata('CLOUD_COVER', 'less_than',10)
           .filterBounds(table)
           //.map(cloudMaskL457)
           .map(function(image){return image.clip(table)})
                     
print('L7', L7)    

var L8 =  ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
           //.filterDate('2013-04-01', '2020-12-16')
           .filterMetadata('CLOUD_COVER', 'less_than',10)
           .filterBounds(table)
           .map(function(image){return image.clip(table)});                     

print('l8', L8)
 
//RENOMEAR BANDAS E JUNTAR

var L4n  = rename_bands(L4, bl4)    
var L5n  = rename_bands(L5, bl5)
var L7n  = rename_bands(L7, bl7)
var L8n  = rename_bands(L8, bl8)

var lsat = L4n.merge(L5n).merge(L7n).merge(L8n)
              //.filterMetadata('CLOUD_COVER', 'less_than',10)
             // .filterMetadata('IMAGE_QUALITY', 'equals', 9)
                .map(maskL8sr);

print('COLEÇÃO', lsat)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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