Use costum script within sentinelhubrequest fails


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 = """

// Date Definition 
var beforeflood_date = "2022-01-01"; var duringflood_date = "2022-01-19"; //    

// Selection of polarization 
function setup() {
  return {
    input: [{
      bands: [
    output: { bands: 3 },
    mosaicking: "ORBIT"

function filterScenes (scenes) {  
return scenes.filter(function (scene) {
// set dates for before-and-during flood analysis
var allowedDates = [beforeflood_date,duringflood_date]; 
var sceneDateStr = dateformat(;
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();
  var isodate = yyyy+'-'+mm+'-'+dd;
  return isodate;

function evaluatePixel(samples,scenes) {  
  var outbe = 0;
  var outdu = 0;  
  // before-flood image
  outbe = calcFM(samples[1]);
  // during-flood image
  outdu = calcFM(samples[0]);  
  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(
            SentinelHubRequest.output_response('default', MimeType.TIFF)
    return request.get_data()



I don’t understand the error message and why it has problem with the VV.

Could you help me find my error?



Hi Reut,

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.

Hello Maxim,

thank you for your answer :slight_smile:

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…

1 Like