Is it possible to know which row/s causing error in Statistical API via Python?

I have a relatively long script in which I calculate multiple Sentinel-2 indices, and then I get an error.
Is it possible to get more information about the error, most importantly - which line caused the error? Otherwise, I need to kind of guess via trial and error, which takes a long time.

Just to be clear - The question here is not the specific error in this script (which I found and fixed), rather more generally, if it is possible to get the line number or some specific indication of where is the error in long scripts.

This is the script:

evalscript =‘’’
//VERSION=3
function setup() {
return {
input: [“B01”,“B02”,“B03”,“B04”,“B05”,“B06”,“B07”,“B08”,“B8A”,“B09”,“B11”,“B12”,“SCL”,“dataMask”],
output: [
{id:“coastal_blue”,bands:1,sampleType:“UINT16”},
{id:“blue”,bands:1,sampleType:“UINT16”},
{id:“green”,bands:1,sampleType:“UINT16”},
{id:“red”,bands:1,sampleType:“UINT16”},
{id:“rededge1”,bands:1,sampleType:“UINT16”},
{id:“rededge2”,bands:1,sampleType:“UINT16”},
{id:“rededge3”,bands:1,sampleType:“UINT16”},
{id:“NIR_narrow”,bands:1,sampleType:“UINT16”},
{id:“NIR”,bands:1,sampleType:“UINT16”},
{id:“SWIR_Cirrus”,bands:1,sampleType:“UINT16”},
{id:“SWIR1”,bands:1,sampleType:“UINT16”},
{id:“SWIR2”,bands:1,sampleType:“UINT16”},
{id:“NDVI”,bands:1,sampleType:“UINT16”},
{id:“NDVI8A”,bands:1,sampleType:“UINT16”},
{id:“VARir”,bands:1,sampleType:“UINT16”},
{id:“EVI2”,bands:1,sampleType:“UINT16”},
{id:“EVI”,bands:1,sampleType:“UINT16”},
{id:“NDRE”,bands:1,sampleType:“UINT16”},
{id:“CVI”,bands:1,sampleType:“UINT16”},
{id:“SAVI”,bands:1,sampleType:“UINT16”},
{id:“SAV2”,bands:1,sampleType:“UINT16”},
{id:“CCCI”,bands:1,sampleType:“UINT16”},
{id:“CIgreen”,bands:1,sampleType:“UINT16”},
{id:“CIRE”,bands:1,sampleType:“UINT16”},
{id:“GNDVI”,bands:1,sampleType:“UINT16”},
{id:“MCARI”,bands:1,sampleType:“UINT16”},
{id:“mNDVI”,bands:1,sampleType:“UINT16”},
{id:“VARIgreen”,bands:1,sampleType:“UINT16”},
{id:“VARIRE”,bands:1,sampleType:“UINT16”},
{id:“NIRv”,bands:1,sampleType:“UINT16”},
{id:“REg”,bands:1,sampleType:“UINT16”},
{id:“REb”,bands:1,sampleType:“UINT16”},
{id:“NDMI”,bands:1,sampleType:“UINT16”},
{id:“GVMI”,bands:1,sampleType:“UINT16”},
{id:“wetness”,bands:1,sampleType:“UINT16”},
{id:“NMDI”,bands:1,sampleType:“UINT16”},
{id:“NMDI2”,bands:1,sampleType:“UINT16”},
{id:“NSR1”,bands:1,sampleType:“UINT16”},
{id:“NSR2”,bands:1,sampleType:“UINT16”},
{id:“cloud_cover”,bands:1,sampleType: “UINT8”},
{id: “dataMask”,bands:1,sampleType:“UINT8”}
],
};
}

function cloud_detect(samples) {
var scl = samples.SCL;

if (scl === 1) { // SC_SATURATED_DEFECTIVE
    return 1;

} else if (scl === 3) { // SC_CLOUD_SHADOW
return 1;
} else if (scl === 6) { // SC_WATER
return 1;
} else if (scl === 7) { // SC_UNCLASSIFIED
return 1;
} else if (scl === 8) { // SC_CLOUD_MEDIUM_PROBA
return 1;
} else if (scl === 9) { // SC_CLOUD_HIGH_PROBA
return 1;
} else if (scl === 10) { // SC_THIN_CIRRUS
return 1;
} else if (scl === 11) { // SC_SNOW_ICE
return 1;
} else {
return 0;
}
}

function evaluatePixel(sample) {
let wetness = (sample.B020.14+sample.B030.18+sample.B040.33+sample.B080.34-sample.B110.62-sample.B120.42)
let NDVI = index(sample.B08, sample.B04)
var cloud_cover = cloud_detect(sample)
return {
coastal_blue: [10000sample.B01],
blue: [10000
sample.B02],
green: [10000sample.B03],
red: [10000
sample.B04],
rededge1: [10000sample.B05],
rededge2: [10000
sample.B06],
rededge3: [10000sample.B07],
NIR_narrow: [10000
sample.B8A],
NIR: [10000sample.B08],
SWIR_Cirrus: [10000
sample.B09],
SWIR1: [10000sample.B11],
SWIR2: [10000
sample.B12],
NDVI: [10000NDVI],
NDVI8A: [10000
index(sample.B8A, sample.B04)],
VARir: [10000*((sample.B08-sample.B04)/(sample.B08+sample.B04-sample.B02))],
EVI2: [10000*(2.4*(sample.B08-sample.B04)/(sample.B08+sample.B04+1))],
EVI: [10000*(2.5*(sample.B08-sample.B04)/(sample.B08+6* sample.B04-7.5* sample.B02+1))],
NDRE: [10000*((sample.B8A-sample.B05)/(sample.B8A+sample.B05))],
CVI: [10000*(sample.B08*(sample.B04/(sample.B03sample.B03)))],
SAVI1: [10000
(((sample.B08-sample.B04)/(sample.B08+sample.B04+0.5))(1+0.5))],
SAV2: [10000
(((sample.B08-sample.B04)/(sample.B08 + sample.B04 + (1-NDVI))) * (1 + (1-NDVI)))],
CCCI: [10000*(((sample.B8A-sample.B05)/(sample.B8A + sample.B05))/((sample.B8A-sample.B04)/(sample.B8A+sample.B04)))],
CIgreen: [10000*((sample.B08/sample.B03)-1)],
CIRE: [10000*((sample.B8A/sample.B05)-1)],
GNDVI: [10000*((sample.B08-sample.B03)/(sample.B08+sample.B03))],
MCARI: [10000*(((sample.B05-sample.B04)-0.2*(sample.B05-sample.B03))(sample.B05/sample.B04))],
mNDVI: [10000
sample.B12],
VARIgreen: [10000sample.B12],
VARIRE: [10000
sample.B12],
NIRv: [10000sample.B12],
REg: [10000
sample.B12],
REb: [10000sample.B12],
NDMI: [10000
index(sample.B8A, sample.B11)],
GVMI: [10000sample.B12],
wetness: [10000
sample.B12],
NMDI: [10000sample.B12],
NMDI2: [10000
sample.B12],
NSR1: [10000sample.B12],
NSR2: [10000
sample.B12],
SWIR2: [10000sample.B12],
wetness: [10000
wetness],
cloud_cover: [cloud_cover],
dataMask: [sample.dataMask]
}
}
‘’’

stats_request = {
“input”: {
“bounds”: {“geometry”: poly,“properties”: {“crs”: f"http://www.opengis.net/def/crs/EPSG/0/{EPSG_code}“}},
“data”: [{“type”: “sentinel-2-l2a”,“dataFilter”: {“mosaickingOrder”: “leastRecent”}}]
},
“aggregation”:{
“timeRange”:{“from”: f”{sd}T00:00:00Z",“to”: f"{ed}T00:00:00Z"},“aggregationInterval”:{“of”: “P1D”},
“evalscript”: evalscript,“resx”: res,“resy”: res
}
}

headers = {‘Content-Type’: ‘application/json’,‘Accept’: ‘application/json’}
url = “https://services.sentinel-hub.com/api/v1/statistics

response = oauth.request(“POST”, url=url , headers=headers, json=stats_request)
response.json()

This is a snippet of the error:

{‘data’: [{‘interval’: {‘from’: ‘2022-06-01T00:00:00Z’,
‘to’: ‘2022-06-02T00:00:00Z’},
‘error’: {‘type’: ‘BAD_REQUEST’,
‘message’: ‘Failed to evaluate script!\nundefined:1134: evaluatePixel must return an object containing arrays\n throw “evaluatePixel must return an object containing arrays”;\n ^\n’}},
{‘interval’: {‘from’: ‘2022-06-04T00:00:00Z’, ‘to’: ‘2022-06-05T00:00:00Z’},
‘error’: {‘type’: ‘BAD_REQUEST’,
‘message’: ‘Failed to evaluate script!\nundefined:1134: evaluatePixel must return an object containing arrays\n throw “evaluatePixel must return an object containing arrays”;\n ^\n’}},
{‘interval’: {‘from’: ‘2022-06-06T00:00:00Z’, ‘to’: ‘2022-06-07T00:00:00Z’},
‘error’: {‘type’: ‘BAD_REQUEST’,
‘message’: ‘Failed to evaluate script!\nundefined:1134: evaluatePixel must return an object containing arrays\n throw “evaluatePixel must return an object containing arrays”;\n ^\n’}},
{‘interval’: {‘from’: ‘2022-06-09T00:00:00Z’, ‘to’: ‘2022-06-10T00:00:00Z’},

If it matters then:

poly = {‘type’: ‘Polygon’,
‘coordinates’: [[[543524.2066699625, 4913672.475454833],
[543301.7360189715, 4914182.25130983],
[543585.5990637002, 4914305.715457292],
[543636.2003406108, 4914324.679479339],
[543636.5445322505, 4914324.827200528],
[543662.5099398704, 4914337.441878019],
[543662.6089071627, 4914337.491664552],
[543676.3631063607, 4914344.651227288],
[543678.5419234377, 4914345.355938862],
[543902.1623488602, 4913826.227753871],
[543524.2066699625, 4913672.475454833]]]}

EPSG_code = 32635


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