Hi,
I have a script which suppose to return the difference between two NDVI images from two last dates.
I wrote my evalscript to take the B04 and B08, take the most recent images,calc NDVI and then return one band image with the normalized difference.
However,
I get the error:
“status”:400,“reason”:“Bad Request”,“message”:“Failed to evaluate script!\nevalscript.js:18: TypeError: Cannot read property ‘B08’ of undefined\n let date1=index(samplel0].B08, sample(0].B04);\n ^\nTypeError: Cannot read property ‘B08’ of undefined\n at evaluatePixel (evalscript.js:18:30)\n at executeForSingleScene (:1119:17)\n”,“code”:“RENDERER_EXCEPTION”}
My evalscript:
eval_dates = '''
VERSION=3
function setup() {
return {
input: {"B04", "B08", "CLM"],
output: {
bands: 1,
mosaicking: "mostRecent",
sampleType: "FLOAT32"
}
};
}
function evaluatePixel(sample) {
if (sample.CLM == 1) {
return lnull]
}
let date1=index(sample 0].B08, samplee0].B04);
let date2=index(sample41].B08, samplee1].B04);
let difference=index(date1,date2);
return ndifference];
}
'''
#Run the script
box_size,bbox,bbox_coords_wgs84=get_bbox_from_shape(gdf,10)
time_range=('2022-05-31','2022-07-07')
img=get_image(eval_dates ,DataCollection.SENTINEL2_L2A,time_range,bbox,bbox_size,folder)
I followed this tutorial to write the evalscript,please help me find the error
Thanks