400 Client Error :ailed to evaluate script! when trying retrieve sentinel1

  • 26 April 2024
  • 6 replies
  • 8 views

I’m trying to retrieve sentinel1 images using evalscript.
I have followed the instruction as appear here but I couldn’t understand the reason why I keep getting the 400 client error (bad request).

This is my evalscript:

evalscript = """
function setup() {
  return {
    input: {bands: ["VV","VH"]}
    output:{bands:  2, sampleType:"FLOAT32"}}
      }
      
function evaluatePixel(sample) {
  return [10 * Math.log((sample.VV)+0.0001) / Math.LN10, 10 * Math.log((sample.VH)+0.0001) / Math.LN10]
}
"""

and this is how I have tried to use it,
when dates is list of dates strings (e.g [‘2020-07-01’,‘2020-07-12’]…

or d in dates:
        request = SentinelHubRequest(
            evalscript=evalscript,
            input_data=[
                SentinelHubRequest.input_data(
                    data_collection=DataCollection.SENTINEL1_IW_DES,
                    time_interval=(d,d),
                    other_args = other_args = {"dataFilter":{"resolution":"HIGH","acquisitionMode":"IW"},"processing":{"backCoeff":"GAMMA0_TERRAIN","orthorectify":True,"demInstance":"COPERNICUS"},"id":"S1GRD"}
                )
            ],
            responses=[
                SentinelHubRequest.output_response('default', MimeType.TIFF)
            ],
            bbox=bbox,
            config=config
        )
        
        image = request.get_data()[0]
        
        plt.figure(figsize=(10,8))
        plt.imshow(image)

That returns the error:
400 Client Error: Bad Request for url: https://services.sentinel-hub.com/api/v1/process
Server response: “{“error”:{“status”:400,“reason”:“Bad Request”,“message”:“Failed to evaluate script!\nevalscript.js:5: SyntaxError: Unexpected identifier\n output:{bands: 2, sampleType:“FLOAT32”}}\n ^^^^^^\n”,“code”:“RENDERER_EXCEPTION”}}”

I haven’t been able to find the source of this error yet, please help me to understand what am I doing wrong as it seems to me very similar to the evaluate script in the doc.


6 replies

You have a mistake in the definition of the input in the setup function. See evalscripts in examples for S1 e.g. this one

Try this:

function setup() {
  return {
    input: ["VV", "VH"],
    output: { id:"default", 
              bands: 2,
              sampleType: "FLOAT32"
    }
  }
}

Hi Batic,

I have tried what you suggested (following the example), but I keep getting this error.

evalscript = """
function setup() {
  return {
    input: ["VV", "VH"],
    output: { id:"default", 
              bands: 2,
              sampleType: "FLOAT32"
    }
  }

function evaluatePixel(samples) {
  var vvdB = toDb(samples.VV)
  var vhdB = toDb(samples.VH)
  return [vvdB, vhdB]
}
"""

Server response: “{“error”:{“status”:400,“reason”:“Bad Request”,“message”:“Failed to evaluate script!\nevalscript.js:15: SyntaxError: Unexpected end of input\n}\n^\n”,“code”:“RENDERER_EXCEPTION”}}”

Hi Reut,

The first thing that I can see in your code is that you are missing a closing curly bracket in your setup function. The error actually points to this as it mentions SyntaxError: Unexpected end of input.

It can help to have some form of coding editor that helps with syntax errors to write your Evalscripts.

Maxim

Hi Maxim

you were right regard the {

but still getting same erro just without the syntax error:

evalscript = """
function setup() {
  return {
    input: ["VV", "VH"],
    output: { id:"default", 
              bands: 2,
              sampleType: "FLOAT32"
    }
  }
 }

function evaluatePixel(samples) {
  var vvdB = toDb(samples.VV)
  var vhdB = toDb(samples.VH)
  return [vvdB, vhdB]
}
"""

Server response: “{“error”:{“status”:400,“reason”:“Bad Request”,“message”:“Dataset with id: 0 not found.”,“code”:“RENDERER_EXCEPTION”}}”

You are using the “SIMPLE” mosaicking (which is by default when not explicitly specified), therefore I suggest you try with sample rather than samples in your evaluatePixel function: there is a difference, see here: https://docs.sentinel-hub.com/api/latest/evalscript/v3/#evaluatepixel-function (samples returns an array). erratum: this is just a naming convention: parameters are positional not named, therefore whatever you put with SIMPLE mosaicking will be an object.

If you keep getting an error despite this change, I would check if there is actually data on the dates you are querying.

just to give some more information-
the flow of the whole script before is that I define date range (in this case lets say from 1/10-10/02), then check if sentinel1 has availabe images with the get_dates() function and then everytime use those dates in order to generate one image per date.

When I use this with another evalscript (one of fusion data for example with sentinel 1) it works no problem (with same dates), so I believe there is still problem with the evalscript (after fixing it to sample as you mentions 🙂 )

evalscript = """
function setup() {
  return {
    input: ["VV", "VH"],
    output: { id:"default", 
              bands: 2,
              sampleType: "FLOAT32"
    }
  }
}
  
function evaluatePixel(sample) {

return [10 * Math.log((sample.VV)) / Math.LN10, 10 * Math.log((sample.VH)) / Math.LN10]
  
  }

Reply


Planet Monitoring
Investors

© 2024 Planet Labs PBC. All rights reserved.
| Privacy Policy | California Privacy Notice | California Do Not Sell
Your Privacy Choices | Cookie Notice | Terms of Use