Problem with Sentinel-Hub WMS Python API and Multi-Temporal Custom Script

Hello.

I’m working with a multi-temporal script and it works fine when I tried with Postman and GetMap Service, but when I try to get the same result using Python API, it launches an exception on "Server response: “Failed to evaluate script! evalscript.js:4: TypeError: Cannot read property ‘B02’ of undefined” so I made the next test:

  1. Checked the tiles returned and there are enough to process the algorithm.
  2. Test the python code with another layer that just uses one tile for the analysis and it works fine!

So, here is the Error:

400 Client Error: Bad Request for url: https://services.sentinel-hub.com/ogc/wcs/cc37e3d2-1540-49cd-MASKED?SERVICE=wcs&WARNINGS=False&MAXCC=20.0&Geometry=MULTIPOLYGON+(((-5.130655606+-80.09303936399999%2C+-5.130700222+-80.0930637%2C+-5.130635326+-80.093128596%2C+-5.130493366+-80.09324622%2C+-5.13038791+-80.09332328399999%2C+-5.130278398+-80.09338818000001%2C+-5.130217558+-80.09344901999999%2C+-5.130181054+-80.093517972%2C+-5.130075598+-80.093627484%2C+-5.12990119+-80.09376538799999%2C+-5.129795734+-80.093887068%2C+-5.129674054+-80.094004692%2C+-5.12953615+-80.09411420399999%2C+-5.129532094+-80.09412637199999%2C+-5.129317126+-80.094312948%2C+-5.129256286+-80.094235884%2C+-5.129195446+-80.094162876%2C+-5.129112298+-80.09407567199999%2C+-5.129045374+-80.094004692%2C+-5.128980478+-80.09390531999998%2C+-5.129043346+-80.09387287199998%2C+-5.129116354+-80.09380797599998%2C+-5.12914069+-80.09374510799998%2C+-5.12919139+-80.093700492%2C+-5.129337406+-80.09357881199999%2C+-5.129483422+-80.093444964%2C+-5.129609158+-80.093371956%2C+-5.12969839+-80.0932665%2C+-5.129803846+-80.093169156%2C+-5.129949862+-80.09303125199999%2C+-5.130047206+-80.092909572%2C+-5.130201334+-80.09278789199999%2C+-5.13034735+-80.092694604%2C+-5.130655606+-80.09303936399999)))&ShowLogo=False&Upsampling=BILINEAR&BBOX=-5.130700222%2C-80.094312948%2C-5.128980478%2C-80.092694604&FORMAT=image%2Fpng&CRS=EPSG%3A4326&TIME=2020-06-05T15%3A44%3A43%2F2020-06-05T15%3A44%3A43&RESX=1m&RESY=1m&COVERAGE=TEST_02&REQUEST=GetCoverage&VERSION=1.1.2
Server response: “Failed to evaluate script!
evalscript.js:4: TypeError: Cannot read property ‘B02’ of undefined
let ngdr = index(sample.B02,sample.B03);
^
TypeError: Cannot read property ‘B02’ of undefined
at isClouds (evalscript.js:4:26)
at isWeed (evalscript.js:16:9)
at evaluatePixel (evalscript.js:56:7)
at executeForMultipleScenes (:1004:14)”

Hi @robinson,

I had a look at your script using the Requests Builder, using console.log to print variables.

If I understand the parameters of the WCS request correctly, you are requesting data for 1 date: TIME=2020-06-05T15%3A44%3A43%2F2020-06-05T15%3A44%3A43.

If you look at the number of scenes returned in your evalscript for your BBOX there is only 1. Therefore, when you get to the isWeed function where you set the index from 1 to 3: let i=0;i<=3;i++ and call samples[i], once the index goes past 0, there is no available scene and it returns an error.

If I set dates so that there are more than 3 scenes within the time range, then your evalscript runs for me.

I hope I understood your script correctly. Let me know otherwise :wink:

Maxim