3

I want to mask pixels based on the quality band information for image collection Landsat 5. this is a code but the image-collection is empty afterward. I would be thankful if anyone could help me.

var startDate = '1992-01-01'
var endDate =   '1993-01-01'
var cloudCover = 30
var collection1992 = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
                        .filter(ee.Filter.eq('WRS_PATH', 170))
                        .filter(ee.Filter.eq('WRS_ROW', 32))
                        .filterDate(startDate,endDate)
                        .filterMetadata('CLOUD_COVER','less_than',cloudCover)
                        .sort('system:time_start')
// cloud mask 66,130
var collection1992_noclouds = collection1992.map(function(img) {
                var mask1 = img.select('pixel_qa').eq(66).eq(130)
                return img.UpdateMask(mask1)
                    })
Map.addLayer(collection1992_noclouds, {}, 'collection1992_noclouds')
2

The collection is not empty; rather, it contains images which are entirely masked.

var mask1 = img.select('pixel_qa').eq(66).eq(130)

This line

  • takes the pixel_qa band,
  • transforms it into an image which is 1 wherever the value was 66 and 0 otherwise,
  • and then compares that with 130.

So the mask is always zero the way you have constructed it.

Did you mean that you want to select values of 66 or 130? Then you need to compare against both and combine them. Here's one way to do that:

var collection1992_noclouds = collection1992.map(function(img) {
  var pixel_qa = img.select('pixel_qa');
  return pixel_qa.eq(66).max(pixel_qa.eq(130));
});
  • Thank you for your response. My mistake was in the way of choosing the values as you mentioned. Thanks. – Mahsa Jami May 22 '18 at 17:33
  • @MahsaJami Glad to hear it. If your problem is solved, please click the checkmark to accept my answer so the question is listed as answered. – Kevin Reid May 22 '18 at 18:07

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.