Skip to main content Link Menu Expand (external link) Document Search Copy Copied

MODIS Normalized difference moisture index - NDMI

//VERSION=3
const moistureRamps = [
        [-0.8, 0x800000],
        [-0.24, 0xff0000],
        [-0.032, 0xffff00],
        [0.032, 0x00ffff],
        [0.24, 0x0000ff],
        [0.8, 0x000080]
      ];

const viz = new ColorRampVisualizer(moistureRamps);

function setup() {
  return {
    input: ["B02", "B06","dataMask"],
    output: [
      { id: "default", bands: 4 },
      { id: "index", bands: 1, sampleType: "FLOAT32" }
    ]
  };
}

function evaluatePixel(samples) {
  let val = index(samples.B02, samples.B06); 
  // The library for tiffs works well only if there is only one channel returned.
  // So we encode the "no data" as NaN here and ignore NaNs on frontend.
  const indexVal = samples.dataMask === 1 ? val : NaN;
  return {
    default: [...viz.process(val),samples.dataMask],
    index: [indexVal] 
  };
}

Evaluate and visualize

Description

The well known and widely used NDVI is a simple, but effective index for quantifying green vegetation. It normalizes green leaf scattering in Near Infra-red wavelengths with chlorophyll absorption in red wavelengths.

The value range of the NDVI is -1 to 1. Negative values of NDVI (values approaching -1) correspond to water. Values close to zero (-0.1 to 0.1) generally correspond to barren areas of rock, sand, or snow. Low, positive values represent shrub and grassland (approximately 0.2 to 0.4), while high values indicate temperate and tropical rainforests (values approaching 1). It is a good proxy for live green vegetation; see [1] for details.

The normalized difference vegetation index, abbreviated NDVI, is calculated using near infrared and red wavelengths.

NDMI = (NIR - SWIR) / (NIR + SWIR)

For MODIS, the NDMI is calculated using NIR band 2 and SWIR band 6:

NDMI = (B02 - B06) / (B02 + B06)

Description of representative images

MODIS NDMI of Europe. Acquired on 5. february of 2020, processed by Sentinel Hub.

L8 NDVI