I’m trying to get quarterly (3-month window) median composites of the VV/VH sentinel 1 imagery.
I’ve set up the following script, but it doesn’t seem to work (it returns all the images rather than the median, and the entire array is zeros).
The script has mean/median functions, and I’m testing them both out to see which is a better compositing method.
Curious if anyone has input into either/and:
- How to set up a median composite script
- How to run the script for each quarter within a year (currently I’m planning to just call the function 4 times with different start and end dates
//VERSION=3 (auto-converted from 1) + dataMask to control background color + scaling to UINT16 range
function mean(values) {
var total = 0, i;
for (i = 0; i < values; i += 1) {
total += values[i];
}
return total / values.length;
}
function median(values) {
if (values.length === 0) return 65535;
if (values.length === 1) return values[0];
values.sort(function(a, b) {
return a - b;
});
var half = Math.floor(values.length / 2);
return values[half];
}
function validate(samples) {
if (samples.dataMask == 0) {
return false;
} else {
return true;
}
}
function evaluatePixel(samples) {
var factor = 65535
var vv = []
var vh = []
var a = 0;
for (var i = 0; i < samples.length; i++) {
var sample = samples[i];
if (sample.VV > 0 && sample.VH > 0) {
var isValid = validate(sample);
if (isValid) {
vv[a] = sample.VV * factor;
vh[a] = sample.VH * factor;
a = a + 1;
}
}
}
return [median(vv), median(vh)];
}
function setup() {
return {
input: [{
bands: [
"VV",
"VH",
"dataMask",
]
}],
output: {
bands: 2,
sampleType:"UINT16",
mosaicking: "ORBIT"
}
}
}

