I have put together some GEE script to generate a cloud-masked NDVI mosaic over a pretty large AOI. However, I'd like to modify it so that the output image contains the mean NDVI pixel values for the time period. I'm new to GEE and I'm not sure the best way to implement this (.mean, or through a reducer?). I'm also not sure if I should calculate the mean before or after masking the clouds (it seems like masking first would be the best).
//polygon that contains the study area
var poly = ee.Geometry.Polygon(
[[[-122.203894, 43.805966],
[-120.027298, 37.792365],
[-114.769423, 38.723926],
[-116.502654, 44.826888]]]);
var l8collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(poly)
.filterDate('2015-05-01', '2015-08-30') //month period
.filterMetadata('CLOUD_COVER', 'less_than', 10);
print(l8collection);
// create function to mask clouds
var maskClouds = function(image){
var pixel_qa = image.select('pixel_qa');
return image.updateMask(pixel_qa.eq(322));
};
var l8masked = l8collection.map(maskClouds);
print (l8masked);
// Compute NDVI
var getNDVI = function(img){
return img.addBands(img.normalizedDifference(['B5','B4']).rename('NDVI'));
};
// map over image collection
var l8ndvi = l8masked.map(getNDVI);
print(l8ndvi);
var ndvi = l8ndvi.select('NDVI');
print(ndvi);
// Export
Export.image.toDrive({
image: ndvi.mosaic().clip(poly),
description: 'NDVI',
scale: 30,
maxPixels: 1e13,
skipEmptyTiles: true
});