Thanks a lot for the reply, that worked! Can the statsitics api also take in data fusion? I tried to adapt the script s1+s2 for calculating ndvi, following the same logic as above, but only got NaN results or errors :
curl -X POST https://services.sentinel-hub.com/api/v1/statistics
-H 'Content-Type: application/json'
-d '{
"input": {
"bounds": {
"bbox": [
0.576168,
5.889986,
0.592098,
5.900488
]
},
"data": [
{
"dataFilter": {},
"processing": {
"orthorectify": "true",
"backCoeff": "SIGMA0_ELLIPSOID"
},
"id": "s1",
"type": "sentinel-1-grd"
},
{
"dataFilter": {},
"id": "l2a",
"type": "sentinel-2-l2a"
}
]
},
"aggregation": {
"timeRange": {
"from": "2019-04-05T00:00:00Z",
"to": "2019-04-29T23:59:59Z"
},
"aggregationInterval": {
"of": "P5D",
"lastIntervalBehavior": "SHORTEN"
},
"resx": "10",
"resy": "10",
"evalscript": "//VERSION=3\nfunction setup() {\n return {\n input: [{\n datasource: \"s1\",\n bands: [\"VV\", \"VH\", \"dataMask\"]\n },\n {\n datasource: \"l2a\",\n bands: [\"B02\", \"B03\", \"B08\", \"B04\", \"SCL\", \"dataMask\"]\n }\n ],\n output: [\n {\n id: \"data\",\n bands: 1\n },\n {\n id: \"dataMask\",\n bands: 1\n }\n ]\n }\n}\n\nfunction toDb(linear) {\n // Convert the linear backscatter to DB (Filgueiras et al. (2019), eq. 3)\n return 10 * Math.LN10 * linear\n}\n\nfunction calc_s1_ndvi(sigmaVV, sigmaVH) {\n // Convert sigma0 to Decibels\n let vh_Db = toDb(sigmaVH)\n let vv_Db = toDb(sigmaVV)\n // Calculate NRPB (Filgueiras et al. (2019), eq. 4)\n let NRPB = (vh_Db - vv_Db) / (vh_Db + vv_Db)\n // Calculate NDVI_nc with approach A3 (Filgueiras et al. (2019), eq. 14)\n let NDVInc = 2.572 - 0.05047 * vh_Db + 0.176 * vv_Db + 3.422 * NRPB\n return NDVInc\n}\n\nfunction evaluatePixel(samples) {\n var s1 = samples.s1[0]\n var s2 = samples.l2a[0]\n\n // Calculate S2 NDVI\n let ndvi = (samples.B08 - samples.B04)/(samples.B08 + samples.B04)\n \n // Calculate S1 NDVI\n let s1_ndvi = calc_s1_ndvi(s1.VV, s1.VH)\n // Use the S2-L2A classification to identify clouds\n if ([7, 8, 9, 10].includes(s2.SCL)) {\n // If clouds are present use S1 NDVI\n return {\n data: [s1_ndvi],\n dataMask: [samples.dataMask]\n }\n } else {\n // Otherwise use s2 NDVI\n return {\n data: [ndvi],\n // Exclude nodata pixels, pixels where ndvi is not defined and water pixels from statistics:\n dataMask: [samples.dataMask]\n }\n }\n}"
},
"calculations": {
"default": {}
}
}'
Any suggestions on if this might work?
Thanks again!