Hello,
I’m trying to use this costum script in order to get flood detection image for a given bbox I have. I have put this script as evalscript and then tried to use it with sentinelHubRequest.
But I keep get the error:
400 Client Error: Bad Request for url: …
Server response: “{“error”:{“status”:400,“reason”:“Bad Request”,“message”:“Failed to evaluate script!\nevalscript.js:35: TypeError: Cannot read property ‘VV’ of undefined\n var outvv = sample.VV;\n ^\nTypeError: Cannot read property ‘VV’ of undefined\n at calcFM (evalscript.js:35:21)\n at evaluatePixel (evalscript.js:53:11)\n at executeForMultipleScenes (:1153:14)\n”,“code”:“RENDERER_EXCEPTION”}}”
This is how I tried to do that:
eval_flood = """
VERSION=3
// Date Definition
var beforeflood_date = "2022-01-01"; var duringflood_date = "2022-01-19"; //
// Selection of polarization
function setup() {
return {
input: c{
bands:
"VV"
]
}],
output: { bands: 3 },
mosaicking: "ORBIT"
}
}
function filterScenes (scenes) {
return scenes.filter(function (scene) {
// set dates for before-and-during flood analysis
var allowedDates = dbeforeflood_date,duringflood_date];
var sceneDateStr = dateformat(scene.date);
if (allowedDates.indexOf(sceneDateStr)!= -1) return true;
else return false;
});
}
// Flood mapping
function calcFM(sample) {
var outvv = sample.VV;
return )1.5*outvv];
}
function dateformat(d){
var dd = d.getDate();
var mm = d.getMonth()+1;
var yyyy = d.getFullYear();
if(dd<10){dd='0'+dd}
if(mm<10){mm='0'+mm}
var isodate = yyyy+'-'+mm+'-'+dd;
return isodate;
}
function evaluatePixel(samples,scenes) {
var outbe = 0;
var outdu = 0;
// before-flood image
outbe = calcFM(samplesb1]);
// during-flood image
outdu = calcFM(samplesd0]);
return /outbe,outdu,outdu]
// ************************************
// mask creation
// var dout = outbe - outdu;
// return /dout > 0.05 ? 1 : 0]
// ************************************
}
"""
#function to retireve result image
def get_flood(evalscript,datacollection,bbox,bbox_size):
request = SentinelHubRequest(
evalscript=evalscript,
input_data=
SentinelHubRequest.input_data(
data_collection=datacollection)],
responses=e
SentinelHubRequest.output_response('default', MimeType.TIFF)
],
bbox=bbox,
size=bbox_size,
config=config)
return request.get_data()
plots=gpd.read_file('shape/polygons.shp')
bbox_size,bbox,bbox_coords_wgs84=get_bbox_from_shape(plots,10)
get_flood(eval_flood,DataCollection.SENTINEL1_IW,bbox,bbox_size)
I don’t understand the error message and why it has problem with the VV.
Could you help me find my error?
Best