Learn how to calculate and export 90th Percentile Annual NDVI for years 1985-2019 using Landsat 8, 7, and 5 scenes (Study Area: Turkey)

What is NDVI?

The Normalized Difference Vegetation Index (NDVI) is referred to as the continuity index to the existing National Oceanic and Atmospheric Administration-Advanced Very High-Resolution Radiometer (NOAA-AVHRR) derived NDVI.

The NDVI is calculated from these individual measurements as follows:

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

In this tutorial, we will look at a simple method to calculate Annual NDVI Time Series for Ethiopia (sample area). You can edit the code and calculate NDVI for any country. In addition, we will learn to export the data to our drive so that we can download and use it other processing tool such as ArcGIS.

Learn about Data

USGS Landsat 8 Surface Reflectance Tier 1

This dataset is the atmospherically corrected surface reflectance from the Landsat 8 OLI/TIRS sensors. These images contain 5 visible and near-infrared (VNIR) bands and 2 short-wave infrared (SWIR) bands processed to orthorectified surface reflectance, and two thermal infrared (TIR) bands processed to orthorectified brightness temperature.

USGS Landsat 7 Surface Reflectance Tier 1

This dataset is the atmospherically corrected surface reflectance from the Landsat 7 ETM+ sensor. These images contain 4 visible and near-infrared (VNIR) bands and 2 short-wave infrared (SWIR) bands processed to orthorectified surface reflectance, and one thermal infrared (TIR) band processed to orthorectified brightness temperature. The VNIR and SWIR bands have a resolution of 30m / pixel. The TIR band, while originally collected with a resolution of 120m / pixel (60m / pixel for Landsat 7) has been resampled using cubic convolution to 30m.

USGS Landsat 5 Surface Reflectance Tier 1

This dataset is the atmospherically corrected surface reflectance from the Landsat 5 ETM sensor. These images contain 4 visible and near-infrared (VNIR) bands and 2 short-wave infrared (SWIR) bands processed to orthorectified surface reflectance, and one thermal infrared (TIR) band processed to orthorectified brightness temperature. The VNIR and SWIR bands have a resolution of 30m / pixel. The TIR band, while originally collected with a resolution of 120m / pixel (60m / pixel for Landsat 7) has been resampled using cubic convolution to 30m.

All these data have been atmospherically corrected using LaSRC and includes a cloud, shadow, water and snow mask produced using CFMASK, as well as a per-pixel saturation mask.

In this tutorial, we will learn the following things:

  • to write a function to loop through Landsat 5,7, and 8 images starting from 1985 through 2019.
  • to compute NDVI using NIR and Red Bands (remember Landsat 5 and 7, and Landsat 8 images have assigned different Band Numbers for NIR and Red Bands. Be careful while selecting the bands.
  • to compute 90th annual NDVI
  • export these 90th percentile annual NDVI to your drive.
Exporting NDVI to your drive

Here is the code:

// Select your country
var countries = ee.FeatureCollection("ft:1tdSwUL7MVpOauSgRzqVTOwdfy17KDbw-1d9omPw")
var country_name = ['Turkey']
var roi = countries.filter(ee.Filter.inList('Country', country_name));
var projection = "EPSG:5070"; //" "EPSG:4269";  
Map.addLayer(roi,{},"Study Area"+country_name);
Map.centerObject(roi,5);  //Zoom to Study area

//==================================//
// LANDSAT NDVI COMPOSITE CREATION //
//==================================//

// NDVI Functions
/*These 2 functions are used to calculate the NDVI for Landsat 5/7 and Landsat 8, respectively.*/
var getNDVI57 = function(image) {
  var ndvi = image.normalizedDifference(['B4', 'B3']);
  return(ndvi); 
  
};

var getNDVI8 = function(image){
  var ndvi = image.normalizedDifference(['B5', 'B4']);
  return(ndvi); 
  
};

// Main function
var createNDVIComposite = function(){
  //Set year range
  var yearrangeStart = 1985;
  var yearrangeStop = 2019;

/* The start and stop years, which are inclusive (i.e., the above example will produce a composite for each year from 1985 to 2017), are set.*/
// Moving into the loop, the next variables of importance are:
  for(var loopYear = yearrangeStart; loopYear <= yearrangeStop; loopYear +=1){
    //Set years date range
    var start = ee.Date.fromYMD(loopYear, 1, 1);
    var end = ee.Date.fromYMD(loopYear, 12, 31);
  
    //Landsat 8
    var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR") 
    .filterBounds(roi) 
    .filterDate(start, end) 
    .filterMetadata('CLOUD_COVER', 'less_than', 80) 
    .map(getNDVI8);
    
    //Landsat7
    var l7 = ee.ImageCollection("LANDSAT/LE07/C01/T1_SR") 
    .filterBounds(roi) 
    .filterDate(start, end) 
    .filterMetadata('CLOUD_COVER', 'less_than', 80) 
    .map(getNDVI57);
    
    //Landsat5
    var l5 = ee.ImageCollection("LANDSAT/LT05/C01/T1_SR")
    .filterBounds(roi)
    .filterDate(start, end)
    .filterMetadata('CLOUD_COVER', 'less_than', 80)
    .map(getNDVI57);

    //Merge collections
    var mergedCollection = ee.ImageCollection(l8.merge(l7).merge(l5))
    .reduce(ee.Reducer.max())
    .reduce(ee.Reducer.percentile([90]));

    var finalOutput = mergedCollection
    .clip(roi).rename(loopYear.toString());
    
    Map.addLayer(finalOutput, {'min': 0,'max': [1], palette: [ 'red', 'orange','green']},"Annual_NDVI_"+country_name+"_"+loopYear, false);
    
    //Generate filename for export
    var filename = ("Annual_NDVI_"+country_name+"_").concat(loopYear.toString());
    Export.image.toDrive({
      image: finalOutput,
      description: filename,
      scale: 30,
      region: roi,
      crs: projection,
      maxPixels: 800000000
      
    })
  }
}

//-----------------------------------// 
// MAIN FUNCTION EXECUTION // 
//-----------------------------------// 
var comp = createNDVIComposite();
2019 Annual 90th Percentile NDVI of Turkey

7 thoughts on “Learn how to calculate and export 90th Percentile Annual NDVI for years 1985-2019 using Landsat 8, 7, and 5 scenes (Study Area: Turkey)”

  1. Pingback: Use 2018 Landsat 8 Scenes for Land Cover Classification in Google Earth Engine (Study Area: Dubai) – DINESH SHRESTHA

  2. Pingback: Land Cover Change Analysis between 1999 and 2018 in GEE (Study Area: Mumbai) – DINESH SHRESTHA

  3. Pingback: Time-lapse: Animate 30m Landsat images generated 90th percentile Annual NDVI from 1999 to 2018 (Study Area: South America) – DINESH SHRESTHA

  4. thanks for sharing knowledge
    I try ndvi it’s work success can please help in EVI vegetation index because when
    I try to write evi expression but it is not working
    I didn’t know where’s the problem
    thanks in advance

  5. thanks for your information it’s help me a lot
    the code work with ndvi values but it is not working in evi vegetation index
    there’s a problem with it
    can you please help in EVI vegetation index?
    thanks in advance

Leave a Reply

%d bloggers like this: