Download Error in Statistical API

Hi, I am trying to download B02 reflectance from sentinel2_L2A source but i am receiving an error during it. I am attaching both the error and the evalscript.

B02_evalscript = """

//VERSION=3

function evaluatePixel(sample) {
    let val = sample.B02;
    return [val, sample.dataMask];
}

function setup() {
  return {
    input: [{
      bands: [
        "B02",
        "dataMask"
      ]
    }],    
    output: [
      {
      id: "B02",
        bands: 1,
        sampleType: SampleType.FLOAT32
      },
      {
        id: "dataMask",
        bands: 1
      }
    ]
  }
}
DownloadFailedException: Failed to download from:
https://services.sentinel-hub.com/api/v1/statistics
with HTTPError:
400 Client Error: Bad Request for url: https://services.sentinel-hub.com/api/v1/statistics
Server response: "{"status": 400, "reason": "Bad Request", "message": "Failed to evaluate script!\nundefined:1084: evaluatePixel must return an object containing arrays\n            throw \"evaluatePixel must return an object containing arrays\";\n            ^\n", "code": "COMMON_EXCEPTION"}"

Can you pinpoint where the problem lies.

Thanks
Sidharrth

Hi Sidharrth,

No worries, it is a fairly simple fix, please notice in the evaluatePixel() function that you need to specify both outputs by the ID you assign in the setup() function like I have done in the evalscript below. Hope that this helps you out, you should see this method in all the examples found here.

//VERSION=3

function setup() {
  return {
    input: [{
      bands: [
        "B02",
        "dataMask"
      ]
    }],    
    output: [
      {
      id: "B02",
        bands: 1,
        sampleType: SampleType.FLOAT32
      },
      {
      id: "dataMask",
        bands: 1
      }
    ]
  }
}

function evaluatePixel(sample) {
    let val = sample.B02;
    return {
        B02: [val],
        dataMask: [sample.dataMask]
        }}

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