custom-scripts icon indicating copy to clipboard operation
custom-scripts copied to clipboard

SAR Deforestation Detection Index - from Time Series

Open zlatomirdd opened this issue 3 years ago • 0 comments

/*** Updated with two functions, for calculation SAR-DD from Time Series, with export to FLOAT32 / GTiff. Cheers, Zlatomir Dimitrov, SRTI-BAS. ***/

//VERSION=3.3 (auto-converted from 1) // // SAR for deforestation detection // ------------ // 2019 - Antonio Carlon Paredes // Update: 2022 - Zlatomir Dimitrov, SRTI-BAS // License: CC BY 4.0 // https://creativecommons.org/licenses/by/4.0/ // function setup() { /return { input: [{ bands: [ "VV", "VH" ] }], output: { id: "s1_sardd", bands: 3 } }/ return { input: ["VH", "VV", "dataMask"], output: { id: "s1_sardd", bands: 3, sampleType: SampleType.FLOAT32 }, mosaicking: Mosaicking.ORBIT } }

// VH: function calculateAverage_VH(samples) { var sum = 0 var nValid = 0 for (let sample of samples) { if (sample.dataMask != 0) { nValid++ sum += sample.VH } } return sum/nValid } // VV: function calculateAverage_VV(samples) { var sum = 0 var nValid = 0 for (let sample of samples) { if (sample.dataMask != 0) { nValid++ sum += sample.VV } } return sum/nValid }

const GAIN = 2.5; const WATER_LIMIT = 0.1; const FOREST_LIMIT = 0.2; const INVERSE_FACTOR = 25;

const GREEN_GRADIENT = [ [1.000, 0x80F300], [0.500, 0x406600], [0.000, 0x003300] ]

const RED_GRADIENT = [ [1.000, 0xFFFFFF], [0.525, 0xFF8600], [0.300, 0xFF6E00], [0.250, 0xAE0000], [0.000, 0x000000] ];

const GREEN_VIZ = new ColorGradientVisualizer(GREEN_GRADIENT, 0, 1); const RED_VIZ = new ColorGradientVisualizer(RED_GRADIENT, 0, 1);

const evaluatePixel = function (samples, scenes) { //let vv = samples.VV; //let vh = samples.VH; let vv = calculateAverage_VV(samples); let vh = calculateAverage_VH(samples);

let area = vv * vh;
let v_len = Math.sqrt(vv * vv + vh * vh);
let v_angle_weighted = 0;
if (vv > 0) {
	v_angle_weighted = Math.atan(vh/vv) / (Math.PI / 2);
}
let v_len_inverse = 0;
if (v_len > 0) {
	v_len_inverse = 1 / (INVERSE_FACTOR * v_len);
}

if (v_len < WATER_LIMIT) {
	return [0];
} else if (v_len > FOREST_LIMIT) {
  	let index = GAIN * v_len - v_angle_weighted;
    return GREEN_VIZ.process(index);
} else {
    let index = GAIN * v_len_inverse + v_angle_weighted;
    return RED_VIZ.process(index);
}

};

zlatomirdd avatar Jul 17 '22 11:07 zlatomirdd