From f416f0e7984b06e4481762728fd64542f7c4d398 Mon Sep 17 00:00:00 2001 From: azlinszky Date: Wed, 23 Apr 2025 16:11:43 +0200 Subject: [PATCH] updated radar vegetation index code to v3, added code for monthly mosaics --- .../README.md | 3 + .../script.js | 19 ++++- .../sentinel_1_mosaics.js | 79 +++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 sentinel-1/radar_vegetation_index_code_dual_polarimetric/sentinel_1_mosaics.js diff --git a/sentinel-1/radar_vegetation_index_code_dual_polarimetric/README.md b/sentinel-1/radar_vegetation_index_code_dual_polarimetric/README.md index 237f036e..55790f1a 100644 --- a/sentinel-1/radar_vegetation_index_code_dual_polarimetric/README.md +++ b/sentinel-1/radar_vegetation_index_code_dual_polarimetric/README.md @@ -5,6 +5,9 @@ grand_parent: Sentinel layout: script permalink: /sentinel-1/radar_vegetation_index_code_dual_polarimetric/ nav_exclude: true +scripts: + - [Copernicus Browser, script.js] + - [Sentinel-1 Monthly Mosaics, sentinel_1_mosaics.js] examples: - zoom: '11' lat: '15.9973' diff --git a/sentinel-1/radar_vegetation_index_code_dual_polarimetric/script.js b/sentinel-1/radar_vegetation_index_code_dual_polarimetric/script.js index 6bce5b55..7d4f6f18 100644 --- a/sentinel-1/radar_vegetation_index_code_dual_polarimetric/script.js +++ b/sentinel-1/radar_vegetation_index_code_dual_polarimetric/script.js @@ -6,5 +6,22 @@ IIT Bombay This code is based on: 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. */ +/// updated to version 3 by András Zlinszky and GitHub Copilot -return [(4*VH)/(VV+VH)]; \ No newline at end of file +function setup() { + return { + input: ["VV", "VH"], + output: { bands: 3 } + }; +} + +function evaluatePixel(sample) { + let VV = sample.VV; + let VH = sample.VH; + + // Calculate RVI + let rvi = (4 * VH) / (VV + VH); + + // Return RVI as grayscale + return [rvi, rvi, rvi]; +} \ No newline at end of file diff --git a/sentinel-1/radar_vegetation_index_code_dual_polarimetric/sentinel_1_mosaics.js b/sentinel-1/radar_vegetation_index_code_dual_polarimetric/sentinel_1_mosaics.js new file mode 100644 index 00000000..88b3fac3 --- /dev/null +++ b/sentinel-1/radar_vegetation_index_code_dual_polarimetric/sentinel_1_mosaics.js @@ -0,0 +1,79 @@ +/* +Radar Vegetation index for Sentinel-1 +Subhadip Dey +IIT Bombay + +This code is based on: +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. +*/ +/// adapted by András Zlinszky for Sentinel-1 quarterly mosaics + +function setup() { + return { + input: ["VV", "VH", "dataMask"], + output: [ + { id: "default", bands: 4 }, + { id: "index", bands: 1, sampleType: "FLOAT32" }, + { id: "eobrowserStats", bands: 1, sampleType: "FLOAT32" }, + { id: "dataMask", bands: 1 } + ] + }; +} + +var water_threshold = 10; // Lower means more water +const rvi_min = -0.1; // Lower limit of the color ramp +const rvi_max = 1; // Upper limit of the color ramp +const num_steps = 9; // Number of steps in the ramp + +// Define the colors for the ramp from light sand brown to deep fir green +const colors = [ + [0.93, 0.91, 0.71], // Light sand brown + [0.87, 0.85, 0.61], // Sandy beige + [0.8, 0.78, 0.51], // Light tan + [0.74, 0.72, 0.42], // Golden brown + [0.69, 0.76, 0.38], // Olive green + [0.64, 0.8, 0.35], // Light moss green + [0.57, 0.75, 0.32], // Moss green + [0.5, 0.7, 0.28], // Forest green + [0.38, 0.59, 0.21] // Deep fir green +]; + +// Generate the ramp dynamically +const rvi_ramp = []; +const step_size = (rvi_max - rvi_min) / (num_steps - 1); + +for (let i = 0; i < num_steps; i++) { + const value = rvi_min + i * step_size; + rvi_ramp.push([value, colors[i]]); +} + +visualizer = new ColorRampVisualizer(rvi_ramp, rvi_min, rvi_max); + +function evaluatePixel(samples) { + let VV = samples.VV; + let VH = samples.VH; + let dataMask = samples.dataMask; + + // Calculate RVI + let rvi = (4 * VH) / (VV + VH); + rvi = Math.max(rvi_min, Math.min(rvi_max, rvi)); // Clamp to the range + + // Apply water threshold + if (VV / VH >= water_threshold) { + return { + default: [0.7, 0.8, 0.9, 1.0], // Water color (light greyish blue) + index: [rvi], + eobrowserStats: [rvi], + dataMask: [dataMask] + }; + } else { + // Get the color from the ramp + let color = visualizer.process(rvi); + return { + default: color.concat([dataMask]), + index: [rvi], + eobrowserStats: [rvi], + dataMask: [dataMask] + }; + } +} \ No newline at end of file