I am trying to export yearly median MODIS-based NDVI products at 250m spatial resolution. I am using the 16 day MODIS/061/MOD13Q1 product. I have found this code which I am following.

The yearly median NDVI image I produced looks like this:


Because I have very little knowledge in Google Earth Engine, I wanted to ask if the code to generate yearly median MODIS/061/MOD13Q1 product (free of cloud, cloud shadows and bad quality pixels) is correct.

I am asking this, because the areas highlighted in red are water bodies and, as far as I know, water bodies should have negative NDVI values. As you can see from the picture, the NDVI range of my image has no negative values (0.0066-0.7318).

Here is the code:

var table = ee.FeatureCollection("users/nikostziokas/mumbai_7767");

var maskEmptyPixels = function(image) {
  var withObs = image.select('NDVI').gt(0);
  return image.updateMask(withObs); 
var maskClouds = function(image) {
  var QA = image.select('SummaryQA');
  var bitMask = 1 << 10;
  return image.updateMask(QA.bitwiseAnd(bitMask).eq(0));

var table_bounds = function(image){
 return image.clip(table); 

var collection = ee.ImageCollection("MODIS/061/MOD13Q1")
               .filterDate('2018-01-01', '2018-12-31')
var evicollection = collection.map(table_bounds);

var totalObsCount = evicollection
var collectionCloudMasked = evicollection.map(maskClouds);

var clearObsCount = collectionCloudMasked

    {bands: ['NDVI'],
     gain: 0.07,
     gamma: 1.4
    'median of masked collection'
//Calculate the median for each band (B2 to B7), multiply by scale factor
//(0.0001), and clip to country polygon
var median1 = collectionCloudMasked.select('NDVI')

image: median1,
description: 'ndvi',
scale: 250, //100 for Band10
maxPixels: 1000000000000,
region: table,
crs: 'EPSG: 7767', 
folder: 'Landsat-5'});

1 Answer 1


By removing the maskEmptyPixels function, the water bodies have negative NDVI values.

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.