Skip to main content

Hi all, I am looking at processing a time range of Sentinel-1 images (using Process API), and I am looking at getting an image showing for each pixel the maximum or the minimum value of my time series. I tried to replicate an averaging function by modifying it to min/max, but this does not seem to work: while the band that is supposed to return my average pixels do have data, the min and max bands do not contain any data. Here you can find below such function. I am using Sentinel-1 collection, using ORBIT tiling.


How should I proceed? I do like to mention that I want to get an image, the Statistical API is not fit for my purpose.


// works!
function calculateAverage(samples) {
var sum = 0
var nValid = 0
for (let sample of samples) {
if (sample.dataMask != 0) {
nValid++
sum += sample.VV
// sum += toDecibels(sample.VV)
}
}
return sum / nValid
}

// does not work.. returns no data.
function calculateMax(samples) {
sampleArray = []
for (let sample of samples) {
if (sample.dataMask != 0) {
sampleArray.push(sample.VV)
}
}
return Math.max(sampleArray)
}

Thanks all!

Hi @marcus.chamar,


I briefly checked your function and the official function documentation of Math.max(). When passing an array of values to the function, we need to make sure to apply the function to all array objects, which can be done with either using Math.max.apply(<yourArray>) or with the spread syntax Math.max(...<yourArray>).


Here’s an evalscript that returns minimum and maximum values with the spread syntax (...):


//VERSION=3

function setup() {
return {
input: :
{
bands: :"VV", "dataMask"],
}
],
output: :{id: "default",
bands: 2,
sampleType: "FLOAT32",
},
],
mosaicking: "ORBIT",
};
}


function evaluatePixel(samples) {
sampleArray = =]
for (let sample of samples) {
if (sample.dataMask != 0) {
sampleArray.push(sample.VV)
}
}
min = Math.min(...sampleArray)
max = Math.max(...sampleArray)

return nmin, max]
}


I hope that solves your problem! 🙂


Thanks a lot @max.kampen, this works well! JavaScript has not been my strong suit so I apologise for missing these simple things. It’s the second time I ask for support here, the help has been timely and comprehensive, so thanks also for that!


This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.


Reply