sentinel-hub/custom-scripts

Example query for agricultural growth stage

JoeyFaulkner opened this issue · 2 comments

Hi! I would like to try this @hareldunn script (https://github.com/sentinel-hub/custom-scripts/blob/master/sentinel-2/agriculture_growth_stage/script.js) but I get this error [CDATA[ Failed to evaluate script!\nTypeError: Cannot read property \'getMonth\' of undefined ]].

My query has parameters:

{'TIME': '2016-05-01/2018-04-21', 
'GEOMETRY': <shapely.geometry.polygon.Polygon object at 0x7f90505e0b70>, 
'WIDTH': 1280, 'HEIGHT': 1280, 
'CRS': 'EPSG:4326', 
'ATM_FILTER': 'ATMCOR', 
'EVALSCRIPTURL': 'https://raw.githubusercontent.com/sentinel-hub/custom-scripts/master/sentinel-2/agriculture_growth_stage/script.js', 
'LAYER': 'NDVI'}

querying the FIS service (though I get the same error querying WMS too). I'm sure I'm making a simple mistake, could I get an example of a working query using this script?

Thanks! Let me know if this wasn't clear enough.

Ho Joey, some ideas, which you can try:
-the script requires "multi-temporal processing", which is triggered by adding TEMPORAL=true parameter
-FIS service itself does not support multi-temporal processing so you should try it on WMS/WCS/WMTS
-I suggest you first try the query with shorter time period, e.g. one quarter (this is certainly not related with the error you get, but might affect performance significantly)

If you copy-paste this script in "temporal Playground" (we have set it up as a prototype), you will see it works:
https://apps.sentinel-hub.com/sentinel-playground-temporal/?source=S2&lat=40.4&lng=-3.730000000000018&zoom=12&preset=CUSTOM&layers=B04,B03,B02&maxcc=20&gain=1.0&temporal=true&gamma=1.0&time=2015-01-01%7C2016-10-09&atmFilter=&showDates=false&evalscript=ZnVuY3Rpb24gICAgc2V0dXAgKGRzcykgewogIHNldElucHV0Q29tcG9uZW50cyhbZHNzLkIwNCxkc3MuQjA4XSk7CiAgc2V0T3V0cHV0Q29tcG9uZW50Q291bnQoMyk7Cn0KCmZ1bmN0aW9uIGNhbGNORFZJKHNhbXBsZSkgewogIHZhciBkZW5vbSA9IHNhbXBsZS5CMDQrc2FtcGxlLkIwODsKICByZXR1cm4gKChkZW5vbSE9MCkgPyAoc2Ft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MywgMC4xLCAwLjcpOwogIAogIHJldHVybiBbYXZnMSxhdmcyLGF2ZzNdOwoKCn0KZnVuY3Rpb24gZmlsdGVyU2NlbmVzIChzY2VuZXMsIGlucHV0TWV0YWRhdGEpIHsKICAgIHJldHVybiBzY2VuZXMuZmlsdGVyKGZ1bmN0aW9uIChzY2VuZSkgewoJICByZXR1cm4gc2NlbmUuZGF0ZS5nZXRUaW1lKCk%2BPShpbnB1dE1ldGFkYXRhLnRvLmdldFRpbWUoKS0zKjMxKjI0KjM2MDAqMTAwMCkgOwogICAgfSk7Cn0%3D

Awesome, the temporal flag solved my problem. Thanks! :)