For the below posted evalscript
and json request
, at run time, i receive a tar
file composed of only one band which is always has been the last one listed. in other words, for the bands specified in my question below, i receive a tar
file contains only
percentageOfCloudy
. When i comment out all the relevant code for percentageOfCloudy
in both of the evalscript
and json request
, then i receive a tar
contains only the band of percentageOfCloudFree
and so on. i receive always a tar
contains the
last band listed.
does this issue has any thing to do with sentinelhub api or it is related the backend
json request:
"input": {
"bounds": {
"geometry": coordsInEPSG3857,
"properties": {
"crs": "http://www.opengis.net/def/crs/EPSG/0/3857"
}
},
"data": [
{
"dataFilter": {
"timeRange": {
"from": sYear + "-" + sMonth + "-" + sDay + "T" + "00:00:00Z",
"to": eYear + "-" + eMonth + "-" + eDay + "T" + "00:00:00Z"
}
},
"type": satMissionType
}
]
},
"output": {
// "width": 1535.8321176437041,
// "height": 1646.6445869835497,
// "resx": LSP,
// "resy": LSP,
"responses": [
{
"identifier": "default",
"format": {
"type": "image/tiff",
},
"identifier": "averages",
"format": {
"type": "image/tiff",
},
"identifier": "numOfCloudFreeSamples",
"format": {
"type": "image/tiff",
},
"identifier": "numOfCloudySamples",
"format": {
"type": "image/tiff",
},
"identifier": "percentageOfCloudFree",
"format": {
"type": "image/tiff",
},
"identifier": "percentageOfCloudy",
"format": {
"type": "image/tiff",
}
},
]
},
"evalscript": evalscript,
evalscript:
//VERSION=3
// Script to extract a time series of NDVI values using
// Sentinel 2 Level 2A data and metadata file.
function setup() {
return {
input: [{
bands: ["B04", "B08", "CLD"],
units: "DN"
}],
output: [
{
id: "default",
bands: 5,
sampleType: "FLOAT32",
nodataValue: NaN,
},
{
id: "averages",
bands: 1,
sampleType: "FLOAT32",
nodataValue: NaN,
},
{
id: "numOfCloudFreeSamples",
bands: 1,
sampleType: "FLOAT32",
nodataValue: NaN,
},
{
id: "numOfCloudySamples",
bands: 1,
sampleType: "FLOAT32",
nodataValue: NaN,
},
{
id: "percentageOfCloudFree",
bands: 1,
sampleType: "FLOAT32",
nodataValue: NaN,
},
{
id: "percentageOfCloudy",
bands: 1,
sampleType: "FLOAT32",
nodataValue: NaN,
}
],
mosaicking: Mosaicking.ORBIT
}
}
// function updateOutput(output, collection) {
// output.default.bands = collection.scenes.length
// }
function samplesParser(samples) {
const cloudFreeSamples = new Array();
const cloudySamples = new Array();
samples.forEach((sample) => {
if (sample.CLD > 0) {
cloudySamples.push(sample);
} else {
cloudFreeSamples.push(sample);
}
});
return [cloudySamples, cloudFreeSamples];
}
function calcAverage(samples) {
let sum = 0;
for(let i = 0;i < samples.length; i++) {
sum += samples[i];
}
let avg = sum / samples.length;
return avg;
}
function calcNDVIForSamples(samples) {
const ndvis = new Array(samples.length).fill(NaN);
samples.forEach((sample, index) => {
ndvis[index] = (sample.B08 - sample.B04) / (sample.B08 + sample.B04) ;
});
return ndvis;
}
function calcPercentage(total, incidences) {
if (total <= 0) {
return NaN;
}
return ((incidences / total) * 100);
}
function evaluatePixel(samples) {
if (samples.length < 1) {
return {
default: [NaN, NaN, NaN, NaN, NaN],
averages: [NaN],
numOfCloudFreeSamples: [NaN],
numOfCloudySamples: [NaN],
// percentageOfCloudFree: [NaN],
// percentageOfCloudy: [NaN]
};
}
const parsedSamples = samplesParser(samples);
const ndvis = calcNDVIForSamples(parsedSamples[1]);
const averages = calcAverage(ndvis);
const numOfCloudySamples = parsedSamples[0].length;
const numOfCloudFreeSamples = parsedSamples[1].length;
const totalNumOfSamples = numOfCloudySamples + numOfCloudFreeSamples;
const percentageOfCloudy = calcPercentage(totalNumOfSamples, numOfCloudySamples);
const percentageOfCloudFree = calcPercentage(totalNumOfSamples, numOfCloudFreeSamples);
return {
default: [averages, numOfCloudFreeSamples, numOfCloudySamples, percentageOfCloudFree, percentageOfCloudy],
averages: [averages],
numOfCloudFreeSamples: [numOfCloudFreeSamples],
numOfCloudySamples: [numOfCloudySamples],
percentageOfCloudFree: [percentageOfCloudFree],
percentageOfCloudy: [percentageOfCloudy],
};
}