NDVI - MODIS
Next, we will look at two alternative ways to access the NDVI from MODIS bands: One that is again almost identical to that of Sentinel-2 and Landsat 8 using band maths, and one that uses a MODIS-dataset that already includes NDVI bands.
Alternative 1
For the first variant, we will access the MOD09GA.006 Terra Surface Reflectance Daily Global 1km and 500m dataset.
Make sure to check the data documentation for the MODIS-dataset to find out which bands store which information and how to adress them.
// NormalizedDifference example for MODIS.
//
// Compute Normalized Difference Vegetation Index over MOD09GA product.
// NDVI = (NIR - RED) / (NIR + RED), where
// RED is sur_refl_b01, 620-670nm
// NIR is sur_refl_b02, 841-876nm
//Access boundary data
var extent_lebanon = ee.FeatureCollection("FAO/GAUL/2015/level0")
.filter(ee.Filter.eq('ADM0_NAME', 'Lebanon')); //filter for entry that equals the UN country name 'Lebanon'
// Center the map on the boundary of our aoi
Map.centerObject(extent_lebanon, 9);
//Access a MODIS ImageCollection.
var modis = ee.ImageCollection('MODIS/006/MOD09GA')
.filterBounds(extent_lebanon)
.filterDate('2020-07-01', '2020-07-31')
.select('sur_refl_b01', 'sur_refl_b02', 'sur_refl_b03', 'sur_refl_b04', 'sur_refl_b05', 'sur_refl_b06', 'sur_refl_b07')
//Turn MODIS ImageCollection into a single Image by reducing it to the median, then clip it to the boundary of our aoi
var modis_median = modis.median()
.clip(extent_lebanon);
// Use the normalizedDifference(A, B) to compute (A - B) / (A + B)
var ndvi = modis_median.normalizedDifference(['sur_refl_b02', 'sur_refl_b01']);
// Create a variable containing NDVI-Visualization parameters
var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green']};
// Display the input image and the NDVI derived from it.
Map.addLayer(modis_median.select(['sur_refl_b01', 'sur_refl_b04', 'sur_refl_b03']),
{gain: [0.1, 0.1, 0.1]}, 'MODIS July 2020 Lebanon Bands 1/4/3');
Map.addLayer(ndvi, ndviParams, 'NDVI MODIS July 2020 Lebanon');
Alternative 2
For the second variant, we will use the MOD13Q1.006 Terra Vegetatoin Indices 16-Day Global 250m dataset.
Make sure to check the data documentation for the MODIS-dataset to find out which bands store which information and how to adress them.
// Let's have a look at an alternative, more convenient way:
// Directly access the NDVI through specific MODIS collections
// Check the data catalog for MODIS products that already include the NDVI
var modis_2 = ee.ImageCollection('MODIS/006/MOD13Q1')
.filterBounds(extent_lebanon)
.filterDate('2020-07-01', '2020-07-31');
print(modis_2, 'July 2020 Lebanon MODIS 2');
// Check out the dataset in the console:
// Temporal resolution of 16 days, so we have 2 images in our imagecollection
// NDVI and EVI (Enhanced Vegetation Index) are already available as bands
// The documentation states that we need to apply a scaling factor of 0.0001 for the NDVI-bands to be displayed correctly
// To do so, we will need to write a short function
var scale_factor = function(image) {
return image.expression('float(b("NDVI")*0.0001)') //the value 0.0001 will be multiplied to all pixels of our ImageCollection
};
// Select the NDVI-Bands
var ndvi_2 = modis_2.select('NDVI');
// Apply the scaling factor
var ndvi_2_scaled = ndvi_2.map(scale_factor);
//Reduce the ImageCollection to an Image using the mean values and clip it to our aoi
var ndvi_2_scaled_clipped = ndvi_2_scaled.mean().clip(extent_lebanon);
//visualize the data
var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green']};
Map.addLayer(ndvi_2_scaled_clipped, ndviParams, 'NDVI MODIS July 2020 Lebanon Alternative');
If you inspect both alternative approaches, you will see that ndvi_2 has a higher spatial resolution! The spatial and temporal resolution are also specified in the products names.
A countless number of different MODIS-datasets are available on the Google Earth Data Catalog. There should be one for just about any geoscientific interest, so it's always worth exploring them!