toolsrtm.indices
~75 VNIR + ~18 SWIR spectral vegetation indices from a reflectance
spectrum. Direct port of ToolsRTM/R/getIndices.R.
Quick example
import numpy as np
from toolsrtm import prospect_d, foursail, get_indices
inputLUT = dict(N=1.5, Cab=40, Car=8, Anth=1, Cbrown=0, EWT=0.01, LMA=0.009, alpha=40,
LIDFa=-0.35, LIDFb=-0.15, TypeLidf=1,
LAI=3, hspot=0.01, tts=30, tto=0, psi=0)
sail = foursail(inputLUT, np.full(2101, 0.15), leaf_model="PROSPECT-D", spectrum_all=True)
wl = np.arange(400, 2501)
idx = get_indices(wl, sail.rsot, spectral_domain="VNIR")
print(idx["NDVI"], idx["MSAVI"])
Input get_indices() Output
--------------------------- ---------------------- ---------------------------
wl [n] wavelengths (nm) dict of ~75 VNIR (or ~18 SWIR)
refl [n] reflectance spectrum --------------------> index name -> value, e.g.
spectral_domain = "VNIR"/"SWIR"/ idx["NDVI"], idx["REP"], ...
"VNIR-SWIR"
Note
spectral_domain="VNIR" is required (strict match, not a substring
check) to get VNIR-only indices like NDVI – "VNIR-SWIR" alone
does not include them, matching the R original’s exact gating
(ToolsRTM/R/getIndices.R).
Spectral vegetation indices, direct port of ToolsRTM::getIndices.
The R function takes a dataframe with named reflectance columns
(R.400, R.670, …) and a regex pattern to find them; the Python
port instead takes wavelengths/reflectance arrays directly (the
numerically load-bearing part – linear interpolation onto an integer nm
grid, then per-index algebra on named wavelengths – is unchanged, only the
dataframe-column-parsing convenience layer is dropped, since it doesn’t
change any numbers).
A handful of formulas below are reproduced as literally written in the R
source, bugs included, rather than “fixed” – see the inline notes at
CIgreen and TCARI/OSAVI.1510, and the GnyLi/CI2 overwrite
sequences – so results match R exactly for anyone cross-checking against
the original package.
- toolsrtm.indices.get_indices(wavelengths, reflectance, spectral_domain='VNIR', factor=None)[source]
Common spectral vegetation indices from reflectance spectra.
Direct port of
ToolsRTM::getIndices(the reflectance-column parsing viapattern.rflis replaced by passingwavelengths/reflectancedirectly – see module docstring).- Parameters:
wavelengths (array_like, shape (nwl,)) – Wavelengths (nm) of the
reflectancecolumns.reflectance (array_like, shape (nwl,) or (nsamples, nwl)) – Reflectance spectra (0-1), one or more rows.
spectral_domain ({'VNIR', 'SWIR', 'VNIR-SWIR'}) – ‘VNIR’: indices using 400-850 nm bands. ‘SWIR’: indices using 800-2550 nm bands. ‘VNIR-SWIR’: both.
factor (float, optional) – Scaling factor applied to reflectance (e.g. 1/10000 for digital numbers). Default 1 (no scaling).
- Returns:
{index_name: numpy.ndarray of shape (nsamples,)}.- Return type:
dict