Getting Started#
Accept the spectral module HERE.
Open a new script in the GEE JavaScript Code Editor and require the spectral module:
var spectral = require("users/dmlmont/spectral:spectral");
Define the dataset and image to use. Let’s use the first image of the Sentinel-2 SR Product:
var dataset = "COPERNICUS/S2_SR";
var S2 = ee.ImageCollection(dataset).first()
Scale the image:
var S2 = spectral.scale(S2, dataset);
If required, offset the image (Note: it is not required to offset the Sentinel-2 SR Product, but here it is shown as an example):
var S2 = spectral.offset(S2, dataset);
Define your index or indices to use. Let’s use the NDVI.
Check the required bands for the NDVI computation:
print(spectral.indices.NDVI.bands); // ["N","R"]
Now, check the description of the required bands:
print(spectral.describeParameters); // Bands: { N: "Near Infrared band", R: "Red band" }
Create a dictionary assigning the required bands:
var parameters = {
"N": S2.select("B8"),
"R": S2.select("B4"),
};
Compute the index (it is added as a new band):
var S2 = spectral.computeIndex(S2, "NDVI", parameters);