2

I want to create a quality image that describes the number of valid (unmasked) observations per pixel time series given a MODIS vegetation image collection.

I want to get a sense for how frequently a given location is masked out because of poor quality or cloud cover to use as a metric to qualify analysis results. For example, if during a given season six observations (images) exist, I want to calculate a map layer that is the count of unmasked observations, so that I can exclude results from pixel time series where the number of observations is less than 3, for instance.

This code block produces a MODIS vegetation index image collection for northern hemisphere summer months and uses the quality band to update each image's mask. How can I count the per-pixel number of unmasked observations given this collection?

// Load all MODIS 13Q1 data from a few months in 2018.
var modisVegCol = ee.ImageCollection("MODIS/006/MOD13Q1")
  .filterDate('2018-05-01', '2018-07-31');

// Define a function to mask image by quality band.
function qualityMask(img) {
  // Make boolean image where high quality pixels are value 1 and all else 0.
  var mask = img.select('SummaryQA').eq(0);
  // Update the image mask and return it.
  return img.updateMask(mask);
}

// Apply quality mask to all images in the collection.
modisVegCol = modisVegCol.map(qualityMask);

// Print the first image.
print(modisVegCol.first());

// Map NDVI mean of the observations.
Map.setCenter(-100.56, 40.97, 4);
Map.addLayer(modisVegCol.select('NDVI').mean(), {min: 0, max: 8000});

Code Editor script

1 Answer 1

1
  1. Write a function that extracts the mask from each image in the collection and returns an image collection composed of a series of image masks.

  2. Apply the mask extractor function to the masked MODIS image collection.

  3. .sum() the extracted mask collection to count the number of unmasked (valid) observations per-pixel time series.

  4. Optionally apply .selfMask() to the result of summing the extracted mask collection to set pixels with 0 valid observations as masked.

The following code block implements these steps in the provided script.

// Load all MODIS 13Q1 data from a few months in 2018.
var modisVegCol = ee.ImageCollection("MODIS/006/MOD13Q1")
  .filterDate('2018-05-01', '2018-07-31');

// Define function to mask image by quality metric. In this case
// the MODIS 'SummaryQA' band.
function qualityMask(img) {
  // Make boolean image where high quality pixels are value 1 and all else 0.
  var mask = img.select('SummaryQA').eq(0);
  // Update the image mask and return it.
  return img.updateMask(mask);
}

// Define a function to calculate the number of valid observations for a given
// pixel's time series. Takes a collection of masked images.
function countValidPixels(collection) {
  // For each image in the collection return the mask; returns an image
  // collection.
  return collection.map(function(img) {
    return img.select(0).mask();
  })
  // Sum the masks; this gives valid pixel count.
  .sum()
  // Optionally mask pixels that have 0 observation over the give time series.
  .selfMask();
}

// Apply quality mask to all images in the collection.
modisVegCol = modisVegCol.map(qualityMask);

// Apply the valid pixel counting function.
var validPixelCount = countValidPixels(modisVegCol);

// Check the result.
print(validPixelCount);
Map.addLayer(validPixelCount, {min: 1, max: 6}, 'Valid Pixel Count');

Code Editor script

Related questions with answers:

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.