0

I am trying apply the cloud mask function but I am getting errors saying Qa60 is not found. Ideas?

//1 Mask Clouds
function maskS2clouds(sentColl) {
var qa = sentColl.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0));

  return sentColl.updateMask(mask).divide(10000);
}
//2. Define Sentinel-2 Image Collection
var sentColl = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
                  .filterDate('2019-06-01', '2019-08-31')
                  .filterMetadata ('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 10)
                  .filterBounds(AOI)
                  .select(['B2', 'B3', 'B4', 'B8'])
                  .map(maskS2clouds);
                 
print(sentColl);

//4. Compute the median in each band and each pixel. Band names are B2_Median, B3_Median etc.
 var imgMed = sentColl.reduce(ee.Reducer.median());
 //5. Output image. Add it to map.
var VisualizeP = {
bands:['B2_median', 'B3_median', 'B4_median'],
min:15,
max:5001,
gamma:1.30,
};
//Map.addLayer(imgMed,VisualizeP);
Map.centerObject(AOI,10);

//Clip image
var NS_Sent_2019 = imgMed.clip(AOI)
 Map.addLayer(NS_Sent_2019,VisualizeP);
 //6. Export image 
Export.image.toDrive({
  image:imgMed,
  description: 'Y2019',
  scale: 5,
  region: AOI,
  maxPixels:16792443500
})
0

1 Answer 1

3

One line before you call the maskS2clouds function, you call select(), which is throwing away the QA60 band. Reverse those two lines.

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.