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:
Sentinel-Hub custom scripts
A repository of custom scripts that can be used with Sentinel-Hub services.
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?
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):
github.com
/*
Script works on Sentinel-2 L2A data and requires scene classification (SCL) band.
It takes one year of data, which is quite compute and time intensive, which is why it is recommended to run it on small area (e.g. 256x256 px).
An example of the results is New Zealand's cloudless mosaic, available here: https://data.linz.govt.nz/layer/93652-nz-10m-satellite-imagery-2017/
For the output value for each pixel it uses the first quartile value of valid values, each band separately. If there are none it uses invalid values instead.
When using SCL its very important to use nearest neighbor resampling with a resolution of about 20m/px or more.
*/
function setup (dss) {
setInputComponents(ndss.B04,dss.B03,dss.B02,dss.SCL]);
setOutputComponentCount(3);
}
function filterScenes (scenes, inputMetadata) {
return scenes.filter(function (scene) {
return scene.date.getTime()>=(inputMetadata.to.getTime()-12*31*24*3600*1000) ;
});
}
function getValue(values) {
This file has been truncated.
show original
or Leaf area index:
github.com
// Leaf Area Index script as implemented in SNAP but without input and output validation!
// Input/output values which are suspect are not reported or changed. Most values, however, do not fall under this category.
// Visualized as an interval from 0-3. This can be adjusted in the evaluatePixel method.
var degToRad = Math.PI / 180;
function evaluatePixel(samples) {
var sample = samplesp0];
var b03_norm = normalize(sample.B03, 0, 0.253061520471542);
var b04_norm = normalize(sample.B04, 0, 0.290393577911328);
var b05_norm = normalize(sample.B05, 0, 0.305398915248555);
var b06_norm = normalize(sample.B06, 0.006637972542253, 0.608900395797889);
var b07_norm = normalize(sample.B07, 0.013972727018939, 0.753827384322927);
var b8a_norm = normalize(sample.B8A, 0.026690138082061, 0.782011770669178);
var b11_norm = normalize(sample.B11, 0.016388074192258, 0.493761397883092);
var b12_norm = normalize(sample.B12, 0, 0.493025984460231);
var viewZen_norm = normalize(Math.cos(sample.viewZenithMean * degToRad), 0.918595400582046, 1);
var sunZen_norm = normalize(Math.cos(sample.sunZenithAngles * degToRad), 0.342022871159208, 0.936206429175402);
var relAzim_norm = Math.cos((sample.sunAzimuthAngles - sample.viewAzimuthMean) * degToRad)
This file has been truncated.
show original