for the code mentioned below, i request one tiff composed of five bands averages, numOfCloudFreeSamples, numOfCloudySamples, percentageOfCloudFree, percentageOfCloudy
at run time, i receive a tiff with the aforementioned bands.
my question is, now i want to have each band as a seperate tiff respectively. in other words, in addition to the tiff that is composed of the aforementioned five bands, i want to have each band of those five as a seperate tiff file.
i want to achieve that in a single request, i do not want to make seperate request for each one-band-tiff. is it possible to modify the below posed evalscript so i can get six output tiffs in a single request, where
1st tiff is composed of five bands
2nd tiff is composed of averages band
3rd tiff is composed of numOfCloudFreeSamples band
4th tiff is composed of numOfCloudySamples band
5th tiff is composed of percentageOfCloudFree band
6th tiff is composed of percentageOfCloudy band
thanks
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,
},
],
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 [NaN, NaN, NaN, NaN, 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 [averages, numOfCloudFreeSamples, numOfCloudySamples, percentageOfCloudFree, percentageOfCloudy];
}