2

I'm trying to isolate ocean cover from OLCI imagery using a bitmask from the quality_flags band. But it's masking all the pixels, and I notice when I mask the ocean and leave the land, the land is very patchy compared to non-masked imagery.

Here's a link: https://code.earthengine.google.com/8b979aedb7f91352ccd792c63af8ca39

Here's the code I'm using:

//Land mask
function maskLand(image) {
  // Bit 31 is land/sea cover
  var LandBitMask = ee.Number(2).pow(31).int();
  // Get the pixel QA band
  var qf = image.select('quality_flags');
  // The flags should be set to one, indicating water cover.
  var mask = qf.bitwiseAnd(LandBitMask).eq(1);
  return image.updateMask(mask)
}

//Create image collection for area and date range
var lis_collection = ee.ImageCollection(olci)
  .filterBounds(lis)
  .filterDate('2018-05-01', '2018-10-01');

//Mask the image collection to water
var lis_mask = lis_collection.map(maskLand);

//Mosaic, clip, and display the area
var lis_area = lis_mask.mosaic();
var lis_area = lis_area.clip(lis);
print(lis_area);
Map.addLayer(lis_area, oa5vis, "Long Island Sound radiance");

Is there a better way to do this?

Perhaps some kind of mask I can run on the clipped mosaic instead of a function to run on the image collection.

1 Answer 1

2

I got this working eventually by modifying a different method I found someone using to mask clouds in Landsat.

//Create functions to mask land from mosaic
var getQABits = function(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 land and cloud pixels.
var land_pixels = function(image) {
  // Select the QA band.
  var qf = image.select(['quality_flags']);
  // Get the bit that flags land.
  return getQABits(qf, 31,31, 'Land_pixels').eq(0);
  // Return an image masking out cloudy areas.
};

var maskLand = function(image) {
  var lp = land_pixels(image);
  image = image.updateMask(lp);
  return image;
};

Then by running maskLand on an OLCI image. Once I found a good image to use this on, I kept the output mask and applied it to my other images.

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.