Learn how to calculate and visualize NDVI using MODIS MOD09GA in Google Earth Engine. Step-by-step tutorial with code and use cases.
Calculating NDVI Using MODIS in Google Earth Engine. Understanding vegetation health is crucial for various environmental monitoring and agricultural applications. The Normalized Difference Vegetation Index (NDVI) is a widely used and simple yet powerful indicator that quantifies the greenness of vegetation using satellite imagery. This article will guide you through a Google Earth Engine (GEE) script that calculates the NDVI from MODIS satellite data, providing a practical example of how remote sensing can be used to assess vegetation conditions. Whether you're an environmental scientist, an agriculture enthusiast, or simply curious about Earth observation, this example demonstrates a fundamental technique in analyzing our planet's green cover.
What This Script Does
This Google Earth Engine script performs a straightforward calculation of the Normalized Difference Vegetation Index (NDVI) using a single image from the MODIS (Moderate Resolution Imaging Spectroradiometer) collection. The script loads a specific MODIS surface reflectance image, extracts the Near-Infrared (NIR) and Red bands (which are highly sensitive to vegetation), and then applies the NDVI formula. The resulting NDVI values, ranging from -1 to +1, are then visualized on a map using a custom color palette, where higher values indicate denser and healthier vegetation, and lower values suggest sparse or stressed vegetation, or even non-vegetated surfaces. This script provides a clear and concise illustration of how to leverage GEE's capabilities for basic vegetation analysis.
This script demonstrates how to compute NDVI using a single MODIS image using
GEE’s built-in .normalizedDifference()
function. Specifically, it loads a MODIS surface reflectance image for
March 9, 2012, and computes NDVI using the near-infrared (NIR) and red bands.
The NDVI is calculated using the formula:
Where:
-
NIR = Band 2 (
sur_refl_b02
) [841–876 nm] -
RED = Band 1 (
sur_refl_b01
) [620–670 nm]
It then centers the map over Kansas, USA, and displays both a true-color composite and the computed NDVI using a rich green-brown color palette for better interpretation.
Google Earth Engine (GEE) Code Sample
// The input image to reduce, in this case an SRTM elevation map.
var image = ee.Image('CGIAR/SRTM90_V4');
// The region to reduce within.
var poly = ee.Geometry.Rectangle([-109.05, 41, -102.05, 37]);
// Reduce the image within the given region, using a reducer that
// computes the max pixel value. We also specify the spatial
// resolution at which to perform the computation, in this case 200
// meters.
var max = image.reduceRegion({
reducer: ee.Reducer.max(),
geometry: poly,
scale: 200
});
// Print the result (a Dictionary) to the console.
print(max);
Step-by-Step Explanation:
-
// NormalizedDifference example.
and subsequent comments: These are comments providing context and explaining the purpose of the script, including the NDVI formula and the specific MODIS bands used for Red and Near-Infrared (NIR). -
var img = ee.Image('MODIS/006/MOD09GA/2012_03_09');
: This line loads a specific image from the MODIS Surface Reflectance Daily Global 500m (MOD09GA) collection. The identifier'MODIS/006/MOD09GA'
specifies the dataset, and'2012_03_09'
selects the image captured on March 9, 2012. The loaded image is stored in a variable namedimg
. -
var ndvi = img.normalizedDifference(['sur_refl_b02', 'sur_refl_b01']);
: This is the core of the NDVI calculation.-
img.normalizedDifference()
: This is a built-in Google Earth Engine function that calculates the normalized difference between two bands of an image. -
['sur_refl_b02', 'sur_refl_b01']
: This is an array specifying the names of the two bands to be used in the calculation.-
'sur_refl_b02'
corresponds to the Near-Infrared (NIR) band (841-876nm) in the MOD09GA product. -
'sur_refl_b01'
corresponds to the Red band (620-670nm) in the MOD09GA product.
-
-
The result of this calculation, the NDVI image, is stored in a variable named
ndvi
. The NDVI is calculated using the formula:
-
-
var palette = ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', ... ];
: This line defines a color palette as an array of hexadecimal color codes. This palette will be used to visually represent the different NDVI values on the map. White ('FFFFFF'
) typically represents low or negative NDVI values (e.g., clouds, water, bare soil), while shades of green ('99B718'
to'011301'
) represent increasing levels of healthy vegetation. -
Map.setCenter(-94.84497, 39.01918, 8);
: This line centers the map view to a specific latitude and longitude (-94.84497, 39.01918) at a zoom level of 8. This helps to focus the initial map display on an area where the MODIS image is likely to cover. -
Map.addLayer(img.select(['sur_refl_b01', 'sur_refl_b04', 'sur_refl_b03']), {gain: [0.1, 0.1, 0.1]}, 'MODIS bands 1/4/3');
: This line adds the original MODIS image to the map for reference.-
img.select(['sur_refl_b01', 'sur_refl_b04', 'sur_refl_b03'])
: This selects the Red (sur_refl_b01
), Near-Infrared (sur_refl_b04
in this band combination for a common false-color composite), and Blue (sur_refl_b03
) bands for visualization. -
{gain: [0.1, 0.1, 0.1]}
: This applies a gain factor to each band to enhance the visual appearance of the image. -
'MODIS bands 1/4/3'
: This is the name that will appear in the map layer control.
-
-
Map.addLayer(ndvi, {min: 0, max: 1, palette: palette}, 'NDVI');
: This line adds the calculated NDVI image to the map. -
ndvi
: This is the NDVI image object created earlier. -
{min: 0, max: 1, palette: palette}
: This defines the visualization parameters for the NDVI layer. It specifies that NDVI values ranging from 0 to 1 will be mapped to the colors defined in thepalette
. Although the theoretical range of NDVI is -1 to +1, for healthy vegetation, values typically fall between 0 and 1. -
'NDVI'
: This is the name that will appear in the map layer control for the NDVI layer.
Applications
The ability to calculate NDVI using tools like Google Earth Engine has numerous real-world applications, including:
- Vegetation Health Monitoring: Assessing the vigor and health of forests, grasslands, and agricultural crops. Declines in NDVI can indicate stress due to drought, disease, or pest infestations.
- Agricultural Management: Monitoring crop growth stages, estimating biomass, and assessing the impact of irrigation and fertilization practices.
- Drought Assessment: Identifying areas affected by drought by observing reductions in vegetation greenness over time.
- Land Cover Change Detection: Monitoring changes in vegetation cover due to deforestation, reforestation, or natural disturbances like fires.
- Urban Vegetation Analysis: Studying the distribution and health of urban green spaces and their impact on the urban environment.
- Ecosystem Monitoring: Tracking changes in ecosystem productivity and phenology (the timing of biological events like leaf emergence and senescence).
- Fire Severity Assessment: Evaluating the impact of wildfires on vegetation by comparing pre- and post-fire NDVI values.
Visualization Example
Unfortunately, I cannot directly embed interactive Google Earth Engine maps or applications within this HTML code for Blogger. However, you can include a static screenshot of the NDVI visualization you obtain in the GEE Code Editor. To do this:
- Run the script in the Google Earth Engine Code Editor.
- Once the NDVI layer is displayed on the map, adjust the zoom and pan to show a relevant area.
- Take a screenshot of the map.
- Upload the screenshot to your Blogger post using the image upload tool.
- You can then insert the image here with a descriptive alt text.
Here is a preview of what it might look like:
Once run in the Earth Engine Code Editor, this script will render:
-
A true-color MODIS composite (
bands 1/4/3
) -
An NDVI layer with a continuous green scale representing vegetation density:
-
Values close to 0 → bare soil or sparse vegetation
-
Values closer to 1 → dense and healthy vegetation
-
Negative values → water bodies, clouds, or snow
-
Notes
-
Customization: You can easily change the date in the
ee.Image()
function to analyze NDVI for different time periods. Exploring time series of NDVI can reveal important trends in vegetation health. - Region of Interest: To focus on a specific geographic area, you can define a Region of Interest (ROI) using geometric tools in the GEE Code Editor and then filter or clip the MODIS image to that region.
- NDVI Range: While the script visualizes NDVI from 0 to 1, be aware that the theoretical range is -1 to +1. Negative values typically represent non-vegetated surfaces like water, snow, or clouds.
- Atmospheric Correction: The MOD09GA product is a surface reflectance product, meaning it has undergone atmospheric correction. This is crucial for accurate NDVI analysis.
References
- Google Earth Engine Documentation: https://developers.google.com/earth-engine
Prepared by: Jamal Chaaouan | GEE Academy @ GeoJamal.com
COMMENTS