Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Sentinel-2 L2A Quarterly Cloudless Mosaic - NDWI

//VERSION=3

function setup() {
    return {
        input: ["B03", "B08", "dataMask"],
        output: { bands: 4 }
    };
}


const colorRamp1 = [
    [0, 0xFFFFFF],
    [1, 0x008000]
];
const colorRamp2 = [
    [0, 0xFFFFFF],
    [1, 0x0000CC]
];

const viz1 = new ColorRampVisualizer(colorRamp1);
const viz2 = new ColorRampVisualizer(colorRamp2);

function evaluatePixel(samples) {
    let val = index(samples.B03, samples.B08);
    if (val < 0) {
        imgVals = viz1.process(-val)
    } else {
        imgVals = viz2.process(Math.sqrt(Math.sqrt(val)))
    }
    return imgVals.concat(samples.dataMask);
}
//VERSION=3

function setup() {
    return {
        input: ["B03", "B08", "dataMask"],
        output: [
            { id: "default", bands: 4 },
            { id: "index", bands: 1, sampleType: "FLOAT32" },
            { id: "eobrowserStats", bands: 1, sampleType: "FLOAT32" },
            { id: "dataMask", bands: 1 }
        ]
    };
}

const colorRamp1 = [
    [0, 0xFFFFFF],
    [1, 0x008000]
];
const colorRamp2 = [
    [0, 0xFFFFFF],
    [1, 0x0000CC]
];

const viz1 = new ColorRampVisualizer(colorRamp1);
const viz2 = new ColorRampVisualizer(colorRamp2);

function evaluatePixel(samples) {
    let val = index(samples.B03, samples.B08);
    if (val < 0) {
        imgVals = viz1.process(-val)
    } else {
        imgVals = viz2.process(Math.sqrt(Math.sqrt(val)))
    }
    // The library for tiffs works well only if there is only one channel returned.
    // So we encode the "no data" as NaN here and ignore NaNs on frontend.
    const indexVal = samples.dataMask === 1 ? val : NaN;

    return {
        default: imgVals.concat(samples.dataMask),
        index: [indexVal],
        eobrowserStats: [val],
        dataMask: [samples.dataMask]
    };
}
//VERSION=3

function setup() {
    return {
        input: ["B03", "B08"],
        output: {
            bands: 1,
            sampleType: "FLOAT32"
        }
    };
}

function evaluatePixel(samples) {
    return [index(samples.B03, samples.B08)]
}

Evaluate and Visualize

Collection Access

Sentinel-2 L2A Quarterly Cloudless Mosaic is one of the Sentinel-2 products, that is offered in Copernicus Data Space Ecosystem. The data is accessible via Copernicus Browser. To access the data, you need a Copernicus Data Space Ecosystem account, and then either create a Sentinel Hub Process API request to the collection or to visualise the data via Copernicus Browser. The collection ID is 5460de54-082e-473a-b6ea-d5cbe3c17cca, and the collection type is byoc-5460de54-082e-473a-b6ea-d5cbe3c17cca.

General description

The NDWI is used to monitor changes related to water content in water bodies. As water bodies strongly absorb light in visible to infrared electromagnetic spectrum, NDWI uses green and near infrared bands to highlight water bodies. It is sensitive to built-up land and can result in over-estimation of water bodies.

NDWI = (GREEN - NIR) / (GREEN + NIR)

For Sentinel-2, the index calculates as:

NDWI = (B03 - B08) / (B03 + B08)

See also this page.

Description of representative images

NDWI of Iceland, 01.10.2023.

Quarterly Cloudless Mosaic NDWI