Awesome Spectral Indices in Python - comprehensive library for computing spectral indices from remote sensing data
npx @tessl/cli install tessl/pypi-spyndex@0.7.0Awesome Spectral Indices in Python - a comprehensive library for computing spectral indices used in remote sensing applications. Spyndex implements over 200 standardized spectral indices from the Awesome Spectral Indices catalogue, providing expression evaluation capabilities compatible with multiple Python object classes including NumPy arrays, Pandas DataFrames, GeoPandas GeoDataFrames, Xarray DataArrays and Datasets, Earth Engine objects, and Planetary Computer assets.
pip install spyndexpip install 'spyndex[ee]'import spyndexCommon imports for accessing different components:
# Core functions
from spyndex import computeIndex, computeKernel
# Catalogue access
import spyndex.indices
import spyndex.bands
import spyndex.constants
# Plotting and datasets
import spyndex.plot
import spyndex.datasetsimport spyndex
import numpy as np
# Compute a single spectral index with numeric values
ndvi = spyndex.computeIndex(
index="NDVI",
params={
"N": 0.643, # Near-infrared
"R": 0.175 # Red
}
)
print(ndvi) # Output: 0.5721271393643031
# Compute multiple indices with numpy arrays
nir = np.random.normal(0.67, 0.12, 1000)
red = np.random.normal(0.12, 0.05, 1000)
green = np.random.normal(0.34, 0.07, 1000)
indices = spyndex.computeIndex(
index=["NDVI", "GNDVI", "SAVI"],
params={
"N": nir,
"R": red,
"G": green,
"L": 0.5 # SAVI soil adjustment factor
}
)
print(indices.shape) # Output: (3, 1000)
# Access spectral index catalogue
print(spyndex.indices.NDVI.long_name) # "Normalized Difference Vegetation Index"
print(spyndex.indices.NDVI.formula) # "((N-R)/(N+R))"
print(spyndex.indices.NDVI.bands) # ('N', 'R')
# Use constants from the catalogue
l_value = spyndex.constants.L.default # 1.0Spyndex is built around several key components:
Core functionality for computing single or multiple spectral indices from the standardized catalogue. Supports numeric values, NumPy arrays, Pandas DataFrames, Xarray DataArrays, Dask arrays, and Earth Engine objects.
def computeIndex(
index: Union[str, List[str]],
params: Optional[dict] = None,
online: bool = False,
returnOrigin: bool = True,
coordinate: str = "index",
**kwargs
) -> Any: ...
def computeKernel(
kernel: str,
params: Optional[dict] = None,
**kwargs
) -> Any: ...Interactive access to the complete spectral indices catalogue with metadata, formulas, band requirements, and platform compatibility information. Provides both bulk access and individual index exploration.
class SpectralIndices(Box):
def __repr__(self) -> str: ...
def __str__(self) -> str: ...
class SpectralIndex:
short_name: str
long_name: str
bands: tuple
application_domain: str
reference: str
formula: str
date_of_addition: str
contributor: str
platforms: list
def compute(self, params=None, **kwargs) -> Any: ...Comprehensive band definitions and platform-specific information for major satellite sensors. Includes wavelength ranges, bandwidths, and cross-platform compatibility mappings.
class Bands(Box):
def __repr__(self) -> str: ...
def __str__(self) -> str: ...
class Band:
short_name: str
long_name: str
common_name: str
min_wavelength: float
max_wavelength: float
standard: str
sentinel2a: PlatformBand
sentinel2b: PlatformBand
# ... other platforms
class PlatformBand:
platform: str
band: str
name: str
wavelength: float
bandwidth: floatStandardized constants used in spectral index calculations with default values and descriptions. Provides consistent parameter values across different applications and research contexts.
class Constants(Box):
def __repr__(self) -> str: ...
def __str__(self) -> str: ...
class Constant:
description: str
long_name: str
short_name: str
standard: str
default: float
value: floatBuilt-in visualization tools for exploring spectral index behavior and parameter sensitivity. Provides heatmap visualizations showing index values across parameter ranges.
def heatmap(
index: str,
x: str,
y: str,
params: Optional[dict] = None,
online: bool = False,
**kwargs
): ...Built-in sample datasets for testing, examples, and educational purposes. Includes both satellite imagery and spectral reflectance data in multiple formats.
def open(dataset: str) -> Any: ...spyndex.indices: SpectralIndices object containing all available spectral indicesspyndex.bands: Bands object containing all band definitionsspyndex.constants: Constants object containing all constants__version__: str = "0.7.1"
__author__: str = "David Montero Loaiza <dml.mont@gmail.com>"numpy.ndarray)pandas.Series, pandas.DataFrame)xarray.DataArray, xarray.Dataset)ee.Image, ee.Number) - requires optional dependenciesdask.array.Array, dask.dataframe.DataFrame)Exception if requested spectral index is not found in catalogueException if required bands/parameters are missing for index computationImportError with installation instructions if Earth Engine features are used without optional dependencies