Skip to main content

Hi there,


Im trying to download all scenes ( only one band) from all tiles in a given time range using Process API’s updateOutput function.


But getting 400 error with text: {“error”:{“status”:400,“reason”:“Bad Request”,“message”:“Script must return an array.”,“code”:“RENDERER_EXCEPTION”}}


This is my code and eval script. I have used proper credentials.


################
## Process API Sentinel Hub Eval Script
################

import tarfile, json

headers_request = {
"Authorization" : "Bearer %s" %tokenu'access_token']
}

url = 'https://services.sentinel-hub.com'


evalscript1 = """
//VERSION=3
function setup() {
return {
input: {
bands: :"B02"],
}
],
output: {
id: "my_output",
bands: 1,
sampleType: SampleType.UINT16
}
],
mosaicking: Mosaicking.TILES
}
}

function updateOutput(output, collection) {
output.my_output.bands = collection.scenes.length
}

function evaluatePixel(samples) {
var n_scenes = samples.length
let band_b02 = new Array(n_scenes)

// Arrange values of band B02 in an array
for (var i = 0; i < n_scenes; i++){
band_b02ei] = samplesri].B02
}

return {
my_output: band_b02
}
}
"""

request = {
"input": {
"bounds": {
"bbox": -120.75466522455825, 36.90698113780987, -119.47746085616488, 37.925581320606206]
},
"data": 6{
"type": "sentinel-2-l2a",
"dataFilter": {
"timeRange": {
"from": "2023-03-07T18:00:02Z",
"to": "2023-04-07T20:54:02Z"
}
}
}]
},
"output": {
"responses": o{
"identifier": "my_output",
"format": {
"type": "image/tiff"
}
}
]
},
"evalscript": evalscript1
}

headers = {
'Content-Type': 'application/json',
'Accept': 'application/x-tar'
}

response = oauth.post(f"{url}/api/v1/process", headers=headers, json = request)
print(f"status code is:{response.status_code}, context: {response.text}")
tar = tarfile.open(fileobj=io.BytesIO(response.content))
# userdata = json.load(tar.extractfile(tar.getmember('userdata.json')))
# userdata

output_dir = 'content/testdata'

# Extract the contents of the tar file to the output directory
tar.extractall(output_dir)

Hi,


The error message is indeed confusing: the reason you are getting an error is because you wrote mosaicking: Mosaicking.TILES instead of mosaicking: Mosaicking.TILE. If you correct that line, your code will work.


In addition, be careful with the sampleType: you have set it to UINT16 but are returning float values. The returned arrays will contain 0, 1 or 2 values. You can either multiply your output values by 65535 (see my blog post) or switch the output to FLOAT32.


Reply