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')
.filterBounds(table).select('NDVI','SummaryQA')
.map(maskEmptyPixels);
var evicollection = collection.map(table_bounds);
var totalObsCount = evicollection
.select('NDVI')
.count();
var collectionCloudMasked = evicollection.map(maskClouds);
var clearObsCount = collectionCloudMasked
.select('NDVI')
.count()
.unmask(0);
Map.setCenter(35.94,-0.37,8);
Map.addLayer(
collectionCloudMasked.median(),
{bands: ['NDVI'],
gain: 0.07,
gamma: 1.4
},
'median of masked collection'
);
print(collectionCloudMasked);
//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')
.reduce(ee.Reducer.median())
.multiply(0.0001)
.clip(table);
Export.image.toDrive({
image: median1,
description: 'ndvi',
scale: 250, //100 for Band10
maxPixels: 1000000000000,
region: table,
crs: 'EPSG: 7767',
folder: 'Landsat-5'});