Skip to main content

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

Hi,

This error could very well mean that there is no data in your AOI on the specified dates (2022-01-01 and/or 2022-01-19).

You would have to check your area of interest specified in shape/polygons.shp, but I ran some tests and noticed that for a randomly picked area ([-1.861176, 51.024121, -1.666484, 51.102228]) I get the same error as you because there is no acquisition on the 1st January 2022. If I change my beforeflood_date to the 2nd January 2022 (that has an S1 acquisition over my bbox) then the script works fine.

I would suggest you check data availability over your AOI as a first step.


Hi,

thank you for your answer 🙂

so it means that always need to check dates which have available tiles?
then, just wonder, how does the script works in sentinel hub playground?
because is written the same, so is just “tuned” already to the correct dates?


Since the dates are hard-coded in the Evalscript, yes you will have to check if the area you are looking at has acquisitions on these specific dates. Same for Sentinel Hub Playground: you will notice that the examples in the Custom Scripts repository are “tuned” to each location. If you take example 1 and go to Salisbury, UK it won’t work anymore…


Reply