Skip to content

Commit 3910eaa

Browse files
authored
Merge pull request #349 from azlinszkysinergise/main
updated radar vegetation index code to v3, added code for monthly mosaics
2 parents e3ec215 + f416f0e commit 3910eaa

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed

sentinel-1/radar_vegetation_index_code_dual_polarimetric/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ grand_parent: Sentinel
55
layout: script
66
permalink: /sentinel-1/radar_vegetation_index_code_dual_polarimetric/
77
nav_exclude: true
8+
scripts:
9+
- [Copernicus Browser, script.js]
10+
- [Sentinel-1 Monthly Mosaics, sentinel_1_mosaics.js]
811
examples:
912
- zoom: '11'
1013
lat: '15.9973'

sentinel-1/radar_vegetation_index_code_dual_polarimetric/script.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,22 @@ IIT Bombay
66
This code is based on:
77
Nasirzadehdizaji, Rouhollah, et al. "Sensitivity Analysis of Multi-Temporal Sentinel-1 SAR Parameters to Crop Height and Canopy Coverage." Applied Sciences 9.4 (2019): 655.
88
*/
9+
/// updated to version 3 by András Zlinszky and GitHub Copilot
910

10-
return [(4*VH)/(VV+VH)];
11+
function setup() {
12+
return {
13+
input: ["VV", "VH"],
14+
output: { bands: 3 }
15+
};
16+
}
17+
18+
function evaluatePixel(sample) {
19+
let VV = sample.VV;
20+
let VH = sample.VH;
21+
22+
// Calculate RVI
23+
let rvi = (4 * VH) / (VV + VH);
24+
25+
// Return RVI as grayscale
26+
return [rvi, rvi, rvi];
27+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
Radar Vegetation index for Sentinel-1
3+
Subhadip Dey
4+
IIT Bombay
5+
6+
This code is based on:
7+
Nasirzadehdizaji, Rouhollah, et al. "Sensitivity Analysis of Multi-Temporal Sentinel-1 SAR Parameters to Crop Height and Canopy Coverage." Applied Sciences 9.4 (2019): 655.
8+
*/
9+
/// adapted by András Zlinszky for Sentinel-1 quarterly mosaics
10+
11+
function setup() {
12+
return {
13+
input: ["VV", "VH", "dataMask"],
14+
output: [
15+
{ id: "default", bands: 4 },
16+
{ id: "index", bands: 1, sampleType: "FLOAT32" },
17+
{ id: "eobrowserStats", bands: 1, sampleType: "FLOAT32" },
18+
{ id: "dataMask", bands: 1 }
19+
]
20+
};
21+
}
22+
23+
var water_threshold = 10; // Lower means more water
24+
const rvi_min = -0.1; // Lower limit of the color ramp
25+
const rvi_max = 1; // Upper limit of the color ramp
26+
const num_steps = 9; // Number of steps in the ramp
27+
28+
// Define the colors for the ramp from light sand brown to deep fir green
29+
const colors = [
30+
[0.93, 0.91, 0.71], // Light sand brown
31+
[0.87, 0.85, 0.61], // Sandy beige
32+
[0.8, 0.78, 0.51], // Light tan
33+
[0.74, 0.72, 0.42], // Golden brown
34+
[0.69, 0.76, 0.38], // Olive green
35+
[0.64, 0.8, 0.35], // Light moss green
36+
[0.57, 0.75, 0.32], // Moss green
37+
[0.5, 0.7, 0.28], // Forest green
38+
[0.38, 0.59, 0.21] // Deep fir green
39+
];
40+
41+
// Generate the ramp dynamically
42+
const rvi_ramp = [];
43+
const step_size = (rvi_max - rvi_min) / (num_steps - 1);
44+
45+
for (let i = 0; i < num_steps; i++) {
46+
const value = rvi_min + i * step_size;
47+
rvi_ramp.push([value, colors[i]]);
48+
}
49+
50+
visualizer = new ColorRampVisualizer(rvi_ramp, rvi_min, rvi_max);
51+
52+
function evaluatePixel(samples) {
53+
let VV = samples.VV;
54+
let VH = samples.VH;
55+
let dataMask = samples.dataMask;
56+
57+
// Calculate RVI
58+
let rvi = (4 * VH) / (VV + VH);
59+
rvi = Math.max(rvi_min, Math.min(rvi_max, rvi)); // Clamp to the range
60+
61+
// Apply water threshold
62+
if (VV / VH >= water_threshold) {
63+
return {
64+
default: [0.7, 0.8, 0.9, 1.0], // Water color (light greyish blue)
65+
index: [rvi],
66+
eobrowserStats: [rvi],
67+
dataMask: [dataMask]
68+
};
69+
} else {
70+
// Get the color from the ramp
71+
let color = visualizer.process(rvi);
72+
return {
73+
default: color.concat([dataMask]),
74+
index: [rvi],
75+
eobrowserStats: [rvi],
76+
dataMask: [dataMask]
77+
};
78+
}
79+
}

0 commit comments

Comments
 (0)