Create a Time-series to Display NDVI Values in Different Regions Across Images

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 learn to create a Time-series chart to display NDVI Values in Different Regions Across Image:

Before running this code make sure to create 3 Polygon Features using “Draw a Rectangle” tool. Should you have trouble in creating the polygon features, check this code for reference. For this tutorial I chose : State of Roraima, State of Amazonas, and Manaus in South America for my study area.

Study Area: State of Roraima, State of Amazonas, and Manaus in South America
var Area1 = Area1.set({label: 'State of Roraima'})
var Area2 = Area2.set({label: 'State of Amazonas'})
var Area3 = Area3.set({label: 'Manaus'})

Map.setOptions('HYBRID')

var regions = ee.FeatureCollection([Area1, Area2, Area3]);
Map.addLayer(regions, {}, "Study Area");
Map.centerObject(regions,6);

var cloudStreshold = 2;  // cloud threshold to apply 
print ('cloudStreshold', cloudStreshold)

//Load collections of surface reflectance for Landsat 5,7 and 8 in the area of interest and cloud masked   
var L5 = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
.filterDate('1985-01-01', '1998-12-31')
.filterBounds(regions)
.filter(ee.Filter.lt('CLOUD_COVER',cloudStreshold))

var L7 = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR')
.filterDate('1999-01-01', '2013-12-31')
.filterBounds(regions)
.filter(ee.Filter.lt('CLOUD_COVER',cloudStreshold))

var L8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterDate('2014-01-01', '2019-09-30')
.filterBounds(regions)
.filter(ee.Filter.lt('CLOUD_COVER',cloudStreshold))

// calculate LE5 NDVI 
// multiply 0.0001 is needed because the SR data is scaled by 10000
var L5_ndvi = L5.map(
  function(image) {
    var ndvi = image.expression(
      '(nir - red) / (nir + red)',
        {
          red: image.select('B3').multiply(0.0001),    // 620-670nm, RED
          nir: image.select('B4').multiply(0.0001),    // 841-876nm, NIR
        });
    // Rename that band to something appropriate
    return ndvi.select([0], ['ndvi']).set('system:time_start', image.get('system:time_start'));
  }
);

// calculate LE7 NDVI 
// multiply 0.0001 is needed because the SR data is scaled by 10000
var L7_ndvi = L7.map(
  function(image) {
    var ndvi = image.expression(
      '(nir - red) / (nir + red)',
        {
          red: image.select('B3').multiply(0.0001),    // 620-670nm, RED
          nir: image.select('B4').multiply(0.0001),    // 841-876nm, NIR
        });
    // Rename that band to something appropriate
    return ndvi.select([0], ['ndvi']).set('system:time_start', image.get('system:time_start'));
  }
);

// calculate LC8 NDVI - note the bands are different for LC8
// multiply 0.0001 is needed because the SR data is scaled by 10000
var L8_ndvi = L8.map(
  function(image) {
    var ndvi = image.expression(
      '(nir - red) / (nir + red)',
        {
          red: image.select('B4').multiply(0.0001),    // 620-670nm, RED
          nir: image.select('B5').multiply(0.0001),    // 841-876nm, NIR
        });
    // Rename that band to something appropriate
    return ndvi.select([0], ['ndvi']).set('system:time_start', image.get('system:time_start'));
  }
);


//Merge over a single collection
var collection = ee.ImageCollection(L5_ndvi.merge(L7_ndvi)).merge(L8_ndvi);

print(L5_ndvi)


var Timeseries = ui.Chart.image.seriesByRegion({
  imageCollection: collection,
  regions: regions,
  reducer: ee.Reducer.mean(),
  band: 'ndvi',
  scale: 30,
  xProperty: 'system:time_start',
  seriesProperty:'label'
});
print(Timeseries);
Time-series chart displaying ndvi values in different regions across images

Return to GEE NDVI Page Return to GEE Homepage

Leave a Reply

%d bloggers like this: