Scripts for index images


#1

I’m not familiar with JS, so want to clarify that NDVI and NDWI in the “Python scripts template” use the standard equations? I think I’ve also seen:
return [B8A - B05 / B8A - B05]

NDVI: (NIR - Red) / (NIR + Red)
Sentinel 2 - Band 8a (NIR) & Band 4 (R )
Landsat 8 - Band 5 (NIR) & Band 4 (R )

NDWI: (SWIR - NIR) / (SWIR + NIR)
Sentinel 2 - Band 8a (NIR) & Band 11 (SWIR)
Landsat 8 – Band 5 (NIR) & Band 6 (SWIR)

Or is the below script (S2 NDVI) just ratios of the bands; values look correct for the downloaded S2 image? Can I similarly put the S2 band names for NDWI? Do similar scripts for L8?

let viz = new Identity();

function evaluatePixel(samples) {
let val = index(samples[0].B8A, samples[0].B04);
return viz.process(val);
}

function setup(ds) {
setInputComponents([ds.B04, ds.B8A]);
setOutputComponentCount(1);
}


#2

I am not sure, what your question is.
let val = index(samples[0].B8A, samples[0].B04);
is the same as
let val = (B8A-B04)/(B8A+B04);

You can find many configurations here:


#3

Thanks Grega, you answered my question. If they are both same, why use the big script in the template? Or does the big script offer any advantages?


#4

In this specific case, for simple indices, there is no reason to use the “big script”.
There are however more complicated cases, where the structure is required.
E.g. multi-temporal processing (cloudless mosaics):


or Leaf area index: