1

I am trying to mask certain features from MODIS LAI image such as cloud cover and image quality. MODIS LAI has two quality control measures - FparLai_QC and FparExtra_QC. I tried doing it with the bitwiseExtract function but I don't know if I have done it properly. Could anyone let me know if this works?

// Load LAI data, filter by date and month.
var leaf = ee.ImageCollection("MODIS/061/MCD15A3H")
.filter(ee.Filter.date('2003-01-01', '2021-12-31')) // 2003-2021
.filter(ee.Filter.calendarRange(3, 5, 'month'))  // Only Mar-May observations
// MODIS composite has a single raster that fills the whole planet, so filtering with bound doesn't make any difference. You may want to clip the image.


var leaf_Siwate = leaf.map(function(img) {return img.clip(Siwate)})
//Map.addLayer(leaf_Siwate);
Map.centerObject(Siwate);

//print('leaf_Siwate', leaf_Siwate);

function bitwiseExtract(value, fromBit, toBit) {
  if (toBit === undefined)
    toBit = fromBit
  var maskSize = ee.Number(1).add(toBit).subtract(fromBit)
  var mask = ee.Number(1).leftShift(maskSize).subtract(1)
  return value.rightShift(fromBit).bitwiseAnd(mask)
}

var applyQaMask = function(leaf_Siwate) {
  var qa = leaf_Siwate.select('FparLai_QC')
  var qaMask = bitwiseExtract(qa, 0).eq(0)
  var dataQualityMask = bitwiseExtract(qa, 3, 4).eq(0)
  var mask = qaMask.and(dataQualityMask)
  return leaf_Siwate.updateMask(mask)
}
var leaf_QCMasked = leaf_Siwate.map(applyQaMask)

var applyQaMask_extra = function(leaf_QCMasked) {
  var qa_extra = leaf_QCMasked.select('FparExtra_QC')
  var cirrus = bitwiseExtract(qa_extra, 4).eq(0)
  var icloud = bitwiseExtract(qa_extra, 5).eq(0)
  var cshadow = bitwiseExtract(qa_extra, 6).eq(0)
  var mask_extra = cirrus.and(icloud).and(cshadow)
  return leaf_QCMasked.updateMask(mask_extra)
}
var leaf_ExtraQCMasked = leaf_QCMasked.map(applyQaMask_extra)

Map.addLayer(leaf_ExtraQCMasked, {min: 0, max: 255}, "leaf_ExtraQCMasked");
Map.addLayer(leaf_QCMasked, {min: 0, max: 255}, "leaf_QCMasked");
Map.addLayer(leaf_Siwate, {min: 0, max: 255}, "leaf_Siwate");

https://code.earthengine.google.com/?scriptPath=users%2Far02022720%2FObjective1%3AStackOverflow

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.