I tried to use sentinel 2 data to calculate the information on the time dimension of each pixel in a area of interest (such as calculate the percentile, median or maxmin of each pixel). I know I can first download all the images in the time interval and calculate it in the local PC. But according to the official description of Sentinel-hub, this can be done in the cloud through API. I used the S2L1CWCSInput function from eo-learn library in the python environment to submit the request through the evalscript of customurlParam, and the time interval parameter of the execute() function is set to 2017/01/01 - 2017/12/31. But in the test, through the debugging code "throw new Error (samples.length)", I found that the length of the input parameter (samples) of the function (evaluationPixel) was always one (sometimes two). I think that means, only data from one time (or one scene) was in the processing.
I have already set the layer in the called dashboard with "temporal: true". I refered to some example custom scripts for multi-temporal data processing, including api version of v1, v2 and v3. I tested them in python, still the length of the input parameter (samples) of the function (evaluationPixel) was always one, such as the example agriculture_growth_stage script from github. I also confirmed it in the sentinel-hub playground and dashboard layer preview.
And some codes can’t be executed at all, such as https://github.com/sentinel-hub/custom-scripts/blob/master/sentinel-2/s2gm/script.js. I have tried it in python, playground, dashboard all.
I would like to ask how to use the custom evalscript to get the information from the time dimension of each pixel, or get all the data in the time interval at each pixel through evaluationPixel()? Is evaluationPixel() can just get sample of only one scene at one time? Is temporal analysis is actually invalid for OGC API and sentinel hub API through python?
Here is my custom_evalscript:
//VERSION=2
function setup(ds) {
return {
components: [ds.B04, ds.B08],
output:[{
id: 'ndvi',
sampleType: SampleType.AUTO,
componentCount: 1
}],
temporal: true
}
}
function evaluatePixel(samples) {
var message = samples.length
throw new Error(message)
var ndvi = []
for (var i = 0; i < samples.length; i++) {
ndvi[i] = index(samples[i].B08, samples[i].B04);
}
var ndvi0 = index(samples[0].B08, samples[0].B04);
return [ndvi0];
}
my python code:
from eolearn.core import LinearWorkflow, FeatureType, OverwritePermission, SaveToDisk
from eolearn.io import S2L1CWCSInput
from sentinelhub import BBox, CRS, CustomUrlParam
add_data = S2L1CWCSInput(
layer='BANDS-S2-L1C',
feature=(FeatureType.DATA, 'BANDS'),
custom_url_params={CustomUrlParam.EVALSCRIPT: custom_script},
resx='10m',
resy='10m',
maxcc=0.2
)
path_out = './eopatches/'
if not os.path.isdir(path_out):
os.makedirs(path_out)
save = SaveToDisk(path_out, overwrite_permission=OverwritePermission.OVERWRITE_PATCH)
workflow = LinearWorkflow(
add_data
save
)
time_interval = ['2017-01-01', '2017-12-31']
extra_param = {
add_5indices:{'bbox': BBox({'min_x':112, 'max_x':112.01, 'min_y':34, 'max_y':34.01}, CRS.WGS84), 'time_interval': time_interval},
save: {'eopatch_folder': 'eopatch_test'},
}
workflow.execute(extra_param)
and the information from “throw new Error (samples.length)”:
DownloadFailedException: During execution of task S2L1CWCSInput: Failed to download from: ...
with HTTPError:
400 Client Error: Bad Request for url: ...
Server response: "Failed to evaluate script!
evalscript.js:19: Error: 1
throw new Error(message)
^
Error: 1
at evaluatePixel (evalscript.js:19:11)"