0

I created a cloud-free median composite for a selected time and location from Landsat 5 SR imagery. Unfortunately, significant portions of the composite appear hazy and for the hazy pixels, the red, green, and blue band values are twice what they should be. I would like to apply a haze mask similar to the various cloud masks available but using the sr_atmos_opacity band. Unfortunately, attempts to modify existing cloud mask codes (e.g., like the one below) have failed to do anything.

How do I mask pixels from the collection when sr_atmos_opacity is >0.3 (or 300 unscaled)?

var cloudMaskL457 = function(image) {   
     var qa = image.select('pixel_qa');   
     var cloud = qa.bitwiseAnd(1 << 5)
              .and(qa.bitwiseAnd(1 << 7))
              .or(qa.bitwiseAnd(1 << 3));
}; 
var dataset = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
              .filterDate('1990-05-14', '1990-09-14')
              .map(cloudMaskL457).filterBounds(geometry); 
  return image.updateMask(cloud.not());
};

1 Answer 1

1

I'm not familiar with the specific application to cloud masking, but the code you show cannot work because the function cloudMaskL457 does not return anything. It just declares variables qa and cloud and does nothing with them. You need to return the image you want.

I tried adding this and it seemed to do something reasonable:

return image.mask(cloud.not());

Any advice on how best to mask pixels from the collection when sr_atmos_opacity is >0.3 (or 300 unscaled) would be most appreciated.

Again, I'm not familiar with the data set or science, but this should be simple to do:

function mask_by_sr_atmos_opacity() {
  return image.mask(image.select('sr_atmos_opacity').lte(300));
}

A mask image needs to have value 1 for the pixels you want to keep, and 0 for the pixels you want to discard, so we're using lte to select pixels whose sr_atmos_opacity value is less than or equal to 300.

In this case you don't need any of the qa or cloud definitions, unless you want to mask by those as well (which might be best done as a separate function, to keep things clearer).

1
  • I updated the cloud mask in the original post to include the return command, in case anyone else uses it in the future. I somehow managed not to copy it the first time around. Nonethess, I modified the code you sent just a little and it worked great to filter out the haze. var hazeMask = function (image) { return image.mask(image.select('sr_atmos_opacity').lte(300)); } var l5 = l5.map(hazeMask)
    – Meco Lonoc
    Feb 17, 2020 at 23:02

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.