Getting Started#

  1. Accept the spectral module HERE.

  2. Open a new script in the GEE JavaScript Code Editor and require the spectral module:

var spectral = require("users/dmlmont/spectral:spectral");
  1. 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()
  1. Scale the image:

var S2 = spectral.scale(S2, dataset);
  1. 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);
  1. Define your index or indices to use. Let’s use the NDVI.

  2. Check the required bands for the NDVI computation:

print(spectral.indices.NDVI.bands); // ["N","R"]
  1. Now, check the description of the required bands:

print(spectral.describeParameters); // Bands: { N: "Near Infrared band", R: "Red band" }
  1. Create a dictionary assigning the required bands:

var parameters = {
    "N": S2.select("B8"),
    "R": S2.select("B4"),
};
  1. Compute the index (it is added as a new band):

var S2 = spectral.computeIndex(S2, "NDVI", parameters);