Methods#

spectral.computeIndex#

spectral.computeIndex(img, index, params)#

Computes an index, or a list of indices, on an image and adds it as a new band.

Arguments:
  • img (ee.Image()) – Image to compute indices on.

  • index (string()) – Index or list of indices to compute.

  • params (object()) – Parameters to use for index computation.

Returns:

Image with indices added as new bands.

Examples

var spectral = require("users/dmlmont/spectral:spectral");

var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR").first();
var L8 = spectral.scale(L8,"LANDSAT/LC08/C01/T1_SR")

Computing one index:

var parameters = {
    "N": L8.select("B5"),
    "R": L8.select("B4"),
};

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

Computing multiple indices:

var parameters = {
    "N": L8.select("B5"),
    "R": L8.select("B4"),
    "G": L8.select("B3"),
    "B": L8.select("B2"),
};

var L8 = spectral.computeIndex(L8,["NDVI","GNDVI","BNDVI"], parameters);

Computing indices with additional parameters:

var parameters = {
    "N": L8.select("B5"),
    "R": L8.select("B4"),
    "L": 0.5
};

var L8 = spectral.computeIndex(L8, "SAVI", parameters);

spectral.computeKernel#

spectral.computeKernel(img, kernel, params)#

Computes a kernel image: k(a,b).

Arguments:
  • img (ee.Image()) – Image to compute the kernel on.

  • kernel (string()) – Kernel to use. One of ‘linear’, ‘poly’ or ‘RBF’.

  • params (object()) – Parameters to use for the kernel computation. For kernel = ‘linear’, the parameters ‘a’ (band A) and ‘b’ (band B) must be declared. For kernel = ‘RBF’, the parameters ‘a’ (band A), ‘b’ (band B) and ‘sigma’ (length-scale) must be declared. For kernel = ‘poly’, the parameters ‘a’ (band A), ‘b’ (band B), ‘p’ (kernel degree) and ‘c’ (trade-off) must be declared.

Returns:

Kernel image.

Examples

var spectral = require("users/dmlmont/spectral:spectral");

var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR").first();
var L8 = spectral.scale(L8,"LANDSAT/LC08/C01/T1_SR")

Computing the linear kernel:

var parameters = {
    "kNN": spectral.computeKernel(L8, "linear", {
        "a": L8.select("B5"),
        "b": L8.select("B5")
    }),
    "kNR": spectral.computeKernel(L8, "linear", {
        "a": L8.select("B5"),
        "b": L8.select("B4")
    })
};

var L8 = spectral.computeIndex(L8, "kNDVI", parameters);

Computing the RBF kernel:

var parameters = {
    "kNN": 1.0,
    "kNR": spectral.computeKernel(L8, "RBF", {
        "a": L8.select("B5"),
        "b": L8.select("B4"),
        "sigma": L8.select("B5").add(L8.select("B4")).divide(2.0)
    }),
};

var L8 = spectral.computeIndex(L8, "kNDVI", parameters);

Computing the polynomial kernel:

var parameters = {
    "kNN": spectral.computeKernel(L8, "poly", {
        "a": L8.select("B5"),
        "b": L8.select("B5"),
        "c": spectral.defaultParameters.c,
        "p": 3.0
    }),
    "kNR": spectral.computeKernel(L8, "poly", {
        "a": L8.select("B5"),
        "b": L8.select("B4"),
        "c": spectral.defaultParameters.c,
        "p": 3.0
    })
};

var L8 = spectral.computeIndex(L8, "kNDVI", parameters);

spectral.bands#

spectral.bands#

Returns the dictionary of bands in the Awesome Spectral Indices standard.

Returns:

Dictionary of bands.

Examples

var spectral = require("users/dmlmont/spectral:spectral");

print(spectral.bands);
print(spectral.bands.N);

spectral.constants#

spectral.describeParameters#

Returns the dictionary of constants (or parameters) in the Awesome Spectral Indices standard.

Returns:

Dictionary of parameters and their description.

Examples

var spectral = require("users/dmlmont/spectral:spectral");

print(spectral.constants);
print(spectral.constants.L);
print(spectral.constants.L.default);

spectral.indices#

spectral.indices#

Returns the dictionary of spectral indices.

Returns:

Dictionary of indices.

Examples

var spectral = require("users/dmlmont/spectral:spectral");

print(spectral.indices);
print(spectral.indices.NDVI);
print(spectral.indices.NDVI.reference);

spectral.offset#

spectral.offset#

Offsets an image using the offset parameters of the dataset. This method must be applied after image scaling.

Param ee.Image img:

Image to offset.

Param string dataset:

Dataset to get parameters from.

Returns:

Offset image.

Examples

var spectral = require("users/dmlmont/spectral:spectral");

var dataset = "LANDSAT/LC08/C01/T1_SR";

var L8 = ee.ImageCollection(dataset).first();
var L8 = spectral.scale(L8,dataset)
var L8 = spectral.offset(L8,dataset)

spectral.offsetParameters#

spectral.offsetParameters#

Returns the dictionary of offset parameters.

Returns:

Dictionary of offset parameters.

Examples

var spectral = require("users/dmlmont/spectral:spectral");

print(spectral.offsetParameters);
print(spectral.offsetParameters["COPERNICUS/S2_SR"]);

spectral.scale#

spectral.scale#

Scales an image using the scale parameters of the dataset.

Param ee.Image img:

Image to scale.

Param string dataset:

Dataset to get parameters from.

Returns:

Scaled image.

Examples

var spectral = require("users/dmlmont/spectral:spectral");

var dataset = "LANDSAT/LC08/C01/T1_SR";

var L8 = ee.ImageCollection(dataset).first();
var L8 = spectral.scale(L8,dataset)

spectral.scaleParameters#

spectral.scaleParameters#

Returns the dictionary of scale parameters.

Returns:

Dictionary of scale parameters.

Examples

var spectral = require("users/dmlmont/spectral:spectral");

print(spectral.scaleParameters);
print(spectral.scaleParameters["COPERNICUS/S2_SR"]);