fix: add NDWI water mask to evalscripts (S2 + S3) to exclude land pixels

This commit is contained in:
Gwadaking
2026-04-01 23:21:19 -04:00
parent f0f28dca47
commit 438a1fc392

View File

@@ -145,7 +145,7 @@ class SentinelHubClient
//VERSION=3 //VERSION=3
function setup() { function setup() {
return { return {
input: [{ bands: ["B04", "B08", "B11", "CLP"], units: "REFLECTANCE" }], input: [{ bands: ["B03", "B04", "B08", "B11", "CLP"], units: "REFLECTANCE" }],
output: { bands: 1, sampleType: "UINT8" } output: { bands: 1, sampleType: "UINT8" }
}; };
} }
@@ -153,6 +153,10 @@ function setup() {
function evaluatePixel(sample) { function evaluatePixel(sample) {
if (sample.CLP > 0.4) { return [255]; } // nodata : nuage if (sample.CLP > 0.4) { return [255]; } // nodata : nuage
// Masque eau : NDWI = (Green - NIR) / (Green + NIR) — terre si <= 0
const ndwi = (sample.B03 - sample.B08) / (sample.B03 + sample.B08);
if (ndwi <= 0) { return [0]; }
const lambdaRed = 664.5; const lambdaRed = 664.5;
const lambdaNir = 832.8; const lambdaNir = 832.8;
const lambdaSwir = 1613.7; const lambdaSwir = 1613.7;
@@ -178,16 +182,19 @@ EVALSCRIPT;
//VERSION=3 //VERSION=3
function setup() { function setup() {
return { return {
input: [{ bands: ["B08", "B11", "B17"], units: "REFLECTANCE" }], input: [{ bands: ["B06", "B08", "B11", "B17"], units: "REFLECTANCE" }],
output: { bands: 1, sampleType: "UINT8" } output: { bands: 1, sampleType: "UINT8" }
}; };
} }
function evaluatePixel(sample) { function evaluatePixel(sample) {
// Masque eau : NDWI = (Green B06 560nm - NIR B17 865nm) / (Green + NIR)
const ndwi = (sample.B06 - sample.B17) / (sample.B06 + sample.B17);
if (ndwi <= 0) { return [0]; }
const lambdaRed = 665.0; const lambdaRed = 665.0;
const lambdaRedEdge = 708.75; const lambdaRedEdge = 708.75;
const lambdaNir = 865.0; const lambdaNir = 865.0;
const ratio = (lambdaNir - lambdaRed) / (lambdaRedEdge - lambdaRed);
// MCI : baseline interpolée entre Red et RedEdge // MCI : baseline interpolée entre Red et RedEdge
const baseline = sample.B08 + (sample.B11 - sample.B08) * (lambdaNir - lambdaRed) / (lambdaRedEdge - lambdaRed); const baseline = sample.B08 + (sample.B11 - sample.B08) * (lambdaNir - lambdaRed) / (lambdaRedEdge - lambdaRed);