Skip to main content

Here is the evalscript i am trying to run, but it throws bad http error: 400.


calculate_ndvi_stats= """

//VERSION=3
function setup() {
return {
input: [{
bands: [
"B04",
"B08",
"B11",
"SCL",
"CLM",
"dataMask"
]
}],
output: [
{
id: "indices",
bands: 3
},
{
id: "dataMask",
bands: 1
}]
}
}

function evaluatePixel(samples) {
let ndvi = (samples.B08 - samples.B04)/(samples.B08 + samples.B04)

var validNDVIMask = 1
if (samples.B04 + samples.B08 == 0 ){ //check if all the bands are 0
validNDVIMask = 0
}

lef ndmi =(samples.B08 - samples.B11) / (samples.08 + samples.B11)

}

var validNDMIMask = 1
if (samples.B08 + samples.B11 == 0 ){ //check if all the bands are 0
validNDMIMask = 0
}
var noWaterMask = 1
if (samples.SCL == 6 ){ //check if pixels are classified as water using SCL band
noWaterMask = 0
}
// masking cloudy pixels
let combinedMask = samples.dataMask
if (samples.CLM > 0) {
combinedMask = 0;
}

return {
indices: [ndvi,ndmi],
dataMask: [samples.dataMask * validNDVIMask * noWaterMask * combinedMask] //if even one of the three exclusion criteria is 0, the pixel will be excluded
}
}
"""

It will be great if I can get help to run this. I am looking to get a NDVI time series for a specific area of interest

In the setup, you specify that “indices” output will have 3 bands, but you only return 2: ndvi and ndmi.


There also seems to be a syntax error in your script - an extra “}” after the ndmi.


Reply