NDVI Time series in Google Earth Engine.

The Normalized Difference Vegetation Index (NDVI)is a spectral index used to quantify the greenness of vegetation. Earlier on, we had calculated NDVI and this blog will focus on a time series chart of NDVI of a region over a period of time as follows:

  • Define and import the region of interest. This is done using the geometry tool.
  • Import the image collection.
  • Add and center the layer for region of interest.
Map.addLayer(geometry, {color: 'red'}, 'Forest');
Map.centerObject(geometry);
  • Filter the image collection for time, cloud cover and bounds to the region of interest.
var filtered = sentinel
  .filter(ee.Filter.date('2019-01-01', '2020-01-01'))
  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
  .filter(ee.Filter.bounds(geometry));
  • Mask clouds from the image.
function maskclouds(image) {
  var qa = image.select('QA60');
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(
             qa.bitwiseAnd(cirrusBitMask).eq(0));
  return image.updateMask(mask)//.divide(10000)
      .select("B.*")
      .copyProperties(image, ["system:time_start"]);
}

var filtered = filtered.map(maskclouds);
  • Compute the NDVI using a function and map it over the collection.
function computeNDVI(image) {
  var ndvi = image.normalizedDifference(['B8', 'B4']).rename('ndvi');
  return image.addBands(ndvi);
}


var withNdvi = filtered.map(computeNDVI);
  • Create the chart to show the NDVI values over the given time period.
var chart = ui.Chart.image.series({
  imageCollection: withNdvi.select('ndvi'),
  region: geometry,
  reducer: ee.Reducer.mean(),
  scale: 20
}).setOptions({
      lineWidth: 1,
      title: 'NDVI Time Series',
      interpolateNulls: true,
      vAxis: {title: 'NDVI'},
      hAxis: {title: '', format: 'YYYY-MMM'}
    });
print(chart);

Patience Kori

A GIS enthusiast keen to use location analytics, web mapping, web design, and web development to find solutions to the day-to-day challenges in the world. An avid reader especially in the growing trends of machine learning, the internet of things, and artificial intelligence.

Previous Post
Next Post

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.