i am using the evalscript
posted below with statistical api
when paste it the request builder
, receive the following error:
output datamask requested but missing from function setup()
request:
-d '{
"input": {
"bounds": {
"bbox": [
12.44693,
41.870072,
12.541001,
41.917096
]
},
"data": [
{
"dataFilter": {},
"type": "sentinel-2-l2a"
}
]
},
"aggregation": {
"timeRange": {
"from": "2024-04-02T00:00:00Z",
"to": "2024-05-02T23:59:59Z"
},
"aggregationInterval": {
"of": "P1D"
},
"width": 512,
"height": 343.697,
"evalscript": "function setup() {\n return {\n input: [{\n bands: [\"B04\", \"B08\"],\n units: \"DN\"\n }],\n output: [\n {\n id: \"default\",\n bands: 1,\n sampleType: \"FLOAT32\",\n nodataValue: NaN,\n },\n ],\n mosaicking: Mosaicking.ORBIT\n }\n }\n\n function updateOutput(output, collection) {\n output.default.bands = collection.scenes.length\n }\n\n function evaluatePixel(samples) {\n // Precompute an array to contain NDVI observations\n var n_observations = samples.length;\n let ndvi = new Array(n_observations).fill(NaN);\n \n //Fill the array with NDVI values\n samples.forEach((sample, index) => {\n ndvi[index] = (sample.B08 - sample.B04) / (sample.B08 + sample.B04) ;\n });\n \n return ndvi;\n }"
},
"calculations": {
"default": {}
}
}'
evalscript:
function setup() {
return {
input: [{
bands: ["B04", "B08"],
units: "DN"
}],
output: [
{
id: "default",
bands: 1,
sampleType: "FLOAT32",
nodataValue: NaN,
},
],
mosaicking: Mosaicking.ORBIT
}
}
function updateOutput(output, collection) {
output.default.bands = collection.scenes.length
}
function evaluatePixel(samples) {
// Precompute an array to contain NDVI observations
var n_observations = samples.length;
let ndvi = new Array(n_observations).fill(NaN);
//Fill the array with NDVI values
samples.forEach((sample, index) => {
ndvi[index] = (sample.B08 - sample.B04) / (sample.B08 + sample.B04) ;
});
return ndvi;
}