# Calculate NDVI for a Single Month over 36 years (1985-2019)

The Normalized Difference Vegetation Index (NDVI) is a simple graphical indicator that can be used to analyze remote sensing measurements, typically, but not necessarily, from a space platform, and assess whether the target being observed contains live green vegetation or not.

The NDVI is calculated from these individual measurements as follows:

NDVI= (NIR-Red) \ (NIR+Red)

In this tutorial, we will stack all the Landsat images for the month of September collected from year 1984 through 2019, and calculate NDVI.

``````var geometry = /* color: #ff0000 */geometry;// tiled automatic download Landsat 8.

var colLT5 = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR');
var colLE7 = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR');
//var colLC8 = ee.ImageCollection("LANDSAT/LC8_SR");
var colLC8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR');

var west = -78.719;
var east = -77.885; //-103;
var north = 38.825;
var south = 38.286;
var Name = "Pilot"; //Provide output file name
var Ear_date = '-09-01';
var Late_date = '-09-30';

var FileName = 'Sep_West-Virgina_1984-2018';
//-----------------------------------//
var resolution = 30;
var projection = "EPSG:5070";

var littleBox = ee.Geometry.Rectangle(west,north,east,south);
var polygon = ee.Feature(littleBox);

Map.centerObject(littleBox,7);

var yearArray1 = [];
for (var year = 1984; year < 2019; year+=1){
yearArray1.push(year);
}

return image;
}

function CleanMaxNDVI(Collect,nd85) {
var MaxNdvi = Collect.map(function(img){
var ndvi = img.select('NDVI');
});
return MaxNdvi.qualityMosaic('NDVI');
}

function maxNDVI(img){
var ndvi = img.normalizedDifference(['nir','red']).rename(['NDVI']);
}

//var LonColl = ee.ImageCollection();
function comps(yearArray){
//var collection = [];
for (var i = 0; i < yearArray.length; i++) {
var year = yearArray[i];
print (year);
if (year < 1999){
var collection = colLT5.filterDate(year+Ear_date,year+Late_date)
.select([0,1,2,3,4,6],['blue','green','red','nir','swir1','swir2'])
.filterBounds(littleBox);

}else if (year >= 1999 & year <= 2018){
var l5coll = colLT5.filterDate(year+Ear_date,year+Late_date)
.select([0,1,2,3,4,6],['blue','green','red','nir','swir1','swir2'])
.filterBounds(littleBox);
var l7coll = colLE7.filterDate(year+Ear_date,year+Late_date)
//.map(final)year+Ear_date,year+Late_date
.select([1,2,3,4,5,6],['blue','green','red','nir','swir1','swir2'])
.filterBounds(littleBox);
collection = ee.ImageCollection(l7coll.merge(l5coll));

}else if (year > 2012){
//print (year+Ear_date,year+Late_date);
collection = colLC8.filterDate(year+Ear_date,year+Late_date)
//.map(final)year+Ear_date,year+Late_date
.select([1,2,3,4,5,6],['blue','green','red','nir','swir1','swir2'])
.filterBounds(littleBox);
}

//var Composite = ee.Algorithms.Landsat.simpleComposite(collection, 75, 3);
var NDVIcomp = collection.map(maxNDVI);

if (year == yearArray[0]){
var LonColl = ee.ImageCollection(NDVIcomp.qualityMosaic('NDVI'));
} else {
var newAnnComp = ee.ImageCollection(NDVIcomp.qualityMosaic('NDVI'));
//var LonColl = ee.ImageCollection(newAnnComp.merge(LonColl));
}

}

var nd90 = LonColl.select('NDVI').reduce(ee.Reducer.percentile([75]));

var ndvi90 = CleanMaxNDVI(LonColl,nd90);
return ndvi90;
}

var map1 = comps(yearArray1);

var reMap = map1
.reproject(projection, null, 30);

Export.image.toDrive({
image: reMap,
description: FileName,
folder: 'LANDSAT',
scale: resolution,
crs: projection,
region: littleBox,
maxPixels: 52041951120
});

print("is it good?");
var now = new Date();
print(now);``````