1

I am trying to create a mask that I can map over an image collection using the QA band from Surface Reflectance data in Google Earth Engine. Here are the indicator bits for the QA band:

  • 0:unused
  • 1:valid data (0=yes, 1=no)
  • 2:ACCA cloud bit (1=cloudy, 0=clear)
  • 3:unused
  • 4:ACCA snow mask
  • 5:land mask based on DEM (1=land, 0=water)
  • 6:DDV (Dense Dark Vegetation)

Here is my code I keep getting the error 'getQAbits' is not defined within this scope.

//filter

var sr1984 = ee.ImageCollection('LEDAPS/LT5_L1T_SR')
.filterDate('1984-06-20', '1984-08-31')
.filter(ee.Filter.or(
ee.Filter.and(ee.Filter.eq('WRS_PATH', 59),         
              ee.Filter.eq('WRS_ROW', 18)),
ee.Filter.and(ee.Filter.eq('WRS_PATH', 58), 
              ee.Filter.eq('WRS_ROW', 18))))

//addimage

var image = ee.Image(
  sr1984.filterBounds(region)
    .filterDate('1984-06-20', '1984-08-31')
    .sort('CLOUD_COVER')
    .first()
);

// helper function to extract the QA bits
function getQABits(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);
}

// A function to mask out cloudy pixels.
var maskQuality = function(image) {
 // Select the QA band.
 var QA = image.select('QA');
 // Get the internal_cloud_algorithm_flag bit.
 var internalQuality = getQAbits(QA,2,4,  'internal_quality_flag');
 // Return an image masking out cloudy areas.
 return image.updateMask(internalQuality.eq(0));
}

maskQuality(image);
Map.addLayer(image);
sr1984masked = sr1984.map(maskQuality)
2

You've got a capitalization error when you call that function. It's capital 'B'.

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.