Package: vegspec
vegspecA compilation of spectral vegetation indices and transformations in PythonThe goal of the vegspec package is to encapsulate computations of 1) more than 145 published spectral vegetation indices and 2) several published pretreatment transformations for vegetative spectral reflectance data.Scientific background material for the methods implemented in the vegspec package is givenhere.Source CodeThe spectral methodologies are contained in one Python module (i.e.,vegspec.py). The module defines a class (i.e.,VegSpec) to encapsulate all the computations for one vegetative reflectance spectrum. To analyze sets of multiple spectral measurements, users can develop a list of uniqueVegSpecinstances for each measurement. At minimum, eachVegSpecinstance requires inputting two 1-dimensional lists that specify the spectral reflecance factors and associated wavelengths.The source code is availablehere.Installpip install vegspecQuickstartImport the packageimport vegspec as vsInstantiate a VegSpec classspectrum = vs.VegSpec(wl,rf)where required inputs are defined as follows:wl : list, Wavelengths (nm) corresponding to the data in rfrf : list, Reflectance factors (0 to 1) for a single spectral scanOther optional arguments for theVegSpecconstructor are as follows:fs1 : int, optional, Filter size for Savitsky-Golay first derivatives, (default = 7)po1 : int, optional, Polynomial order for Savitsky-Golay first derivatives, (default = 2)fs2 : int, optional, Filter size for Savitsky-Golay second derivatives, (default = 15)po2 : int, optional, Polynomial order for Savitsky-Golay second derivatives, (default = 2)wlblu : float, optional, Primary wavelength of visible blue light (nm), (default = 480.)wlgrn : float, optional, Primary wavelength of visible green light (nm), (default = 550.)wlred : float, optional, Primary wavelength of visible red light (nm), (default = 670.)wlnir : float, optional, Primary wavelength of near-infrared light (nm), (default = 800.)solslp : float, optional, Slope of the soil line, (default = 1.166)solicpt : float, optional, Intercept of the soil line, (default = 0.042)getlirf : boolean, optional, If True, compute log inverse reflectance, (default = True)getcrrf : boolean, optional, If True, compute continuum removed spectra, (default = True)TheVegSpecclass constructor will automatically compute all spectral vegetation indices and spectral data pretreatment transformations unless optional arguments (i.e.,getlirfandgetcrrf) are changed toFalse. If increased computational efficiency is needed, consider changinggetcrrftoFalse.Access the resultsfor key in spectrum.indices.keys():
    print(key+',{:f}'.format(spectrum.indices[key]))print(spectrum.rfd1)The VegSpec class stores the computational results in the following attribute variables:rfd1 : numpy.ndarray, A 1D array of the Savitsky-Golay first derivative of rfrfd2 : numpy.ndarray, A 1D array of the Savitsky-Golay second derivative of rflirf : numpy.ndarray, A 1D array of the logarithm of inverse rf (log10(1/R))lirfd1 : numpy.ndarray, A 1D array of the Savitsky-Golay first derivative of lirflirfd2 : numpy.ndarry, A 1D array of the Savitsky-Golay second derivative of lirfcrrf : numpy.ndarray, A 1D array of the continuum removal of rfindices : dict, A dictionary of 145+ published spectral vegetation indicesFor further information on the keys of theindicesattribute, see the documentationhere.Further examplesFurther example scripts for using the vegspec package arehere.Further informationThe vegspec package is further described in the following article:Thorp, K. R., 2024. vegspec: A compilation of spectral vegetation indices and transformations in Python. SoftwareX. In prep.Also, the vegspec package was used to conduct the following research:Thorp, K. R., Thompson, A.L., 2024. Phenotyping cotton leaf chlorophyll via proximal hyperspectral reflectance sensing, spectral vegetation indices, and machine learning. Frontiers in Plant Science. In prep.