Output datamask requested but missing from function setup()

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;
  }

Have a look here

the error i am getting, which is output datamask requested but missing from function setup() is not indicative because i am not using any datamask
would you please help me to solve it

Statistical API needs datamask as an output. This is explained in the documentation I linked you. Please read it carefully.

If something from the documentation is not clear, don’t hesitate to ask about specifics on the forum.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.