CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-spyndex

Awesome Spectral Indices in Python - comprehensive library for computing spectral indices from remote sensing data

Overview
Eval results
Files

constants.mddocs/

Constants and Parameters

Standardized constants used in spectral index calculations with default values and descriptions. These constants provide consistent parameter values across different applications and research contexts, ensuring reproducible results when computing spectral indices.

Capabilities

Global Constants Catalogue

The global spyndex.constants object provides access to all standardized constants used in spectral index formulas.

class Constants(Box):
    """
    Container for all constants used in spectral index calculations.
    
    Provides dictionary-like access to individual Constant objects.
    """
    
    def __repr__(self) -> str:
        """Machine readable representation showing available constant names."""
        
    def __str__(self) -> str:
        """Human readable list of constant names."""

Usage Examples:

import spyndex

# Access the global constants catalogue
print(spyndex.constants)
# Output: Constants(['L', 'g', 'C1', 'C2', 'kNN', 'kNR', 'kNB', 'kNRE', ..., 'sigma', 'p', 'c'])

# Get list of all constant names
constant_names = list(spyndex.constants.keys())
print(f"Total constants available: {len(constant_names)}")

# Access specific constants
L = spyndex.constants.L      # Canopy background adjustment
g = spyndex.constants.g      # Gain factor
C1 = spyndex.constants.C1    # Aerosol resistance coefficient 1
C2 = spyndex.constants.C2    # Aerosol resistance coefficient 2

Individual Constant Objects

Each constant is represented as a Constant object containing description and default value information.

class Constant:
    """
    Individual constant with description and default value.
    """
    
    description: str    # Detailed description of the constant's purpose
    long_name: str      # Description (alias for description)
    short_name: str     # Standard constant abbreviation
    standard: str       # Standard abbreviation (alias for short_name)
    default: float      # Default value for the constant
    value: float        # Default value (alias for default)
    
    def __repr__(self) -> str:
        """Machine readable representation with name and default value."""
        
    def __str__(self) -> str:
        """Human readable description with default value."""

Usage Examples:

import spyndex

# Access individual constant
L_constant = spyndex.constants.L

# Explore constant properties
print(L_constant.short_name)    # "L"
print(L_constant.description)   # "Canopy background adjustment"
print(L_constant.default)       # 1.0
print(L_constant.value)         # 1.0 (alias for default)

# Display constant information
print(L_constant)
# Output: L: Canopy background adjustment
#         * Default value: 1.0

# Use constant in computations
savi_result = spyndex.computeIndex(
    "SAVI",
    params={
        "N": 0.67,
        "R": 0.12,
        "L": spyndex.constants.L.default
    }
)

Common Constants

Vegetation Index Constants

Constants commonly used in vegetation-related spectral indices:

import spyndex

# SAVI canopy background adjustment
L = spyndex.constants.L
print(f"L (Canopy background): {L.default}")  # 1.0

# EVI coefficients
C1 = spyndex.constants.C1  
C2 = spyndex.constants.C2
g = spyndex.constants.g
print(f"C1 (Aerosol resistance): {C1.default}")  # 6.0
print(f"C2 (Aerosol resistance): {C2.default}")  # 7.5  
print(f"g (Gain factor): {g.default}")           # 2.5

# Use in EVI computation
evi = spyndex.computeIndex(
    "EVI",
    params={
        "N": 0.67,
        "R": 0.12,
        "B": 0.08,
        "g": g.default,
        "C1": C1.default,
        "C2": C2.default,
        "L": L.default
    }
)

Kernel Constants

Constants used in kernel-based spectral indices:

import spyndex

# Kernel parameters
p = spyndex.constants.p      # Polynomial kernel degree
c = spyndex.constants.c      # Polynomial kernel trade-off
sigma = spyndex.constants.sigma  # RBF kernel length-scale

print(f"p (Kernel degree): {p.default}")        # 2.0
print(f"c (Kernel trade-off): {c.default}")     # 1.0
print(f"sigma (RBF length-scale): {sigma.default}")  # 0.5

# Use in kernel computation
poly_kernel = spyndex.computeKernel(
    "poly",
    params={
        "a": 0.67,
        "b": 0.12,
        "p": p.default,
        "c": c.default
    }
)

Platform-Specific Constants

Some constants are tailored for specific satellite platforms or atmospheric conditions:

import spyndex

# Explore all constants with their descriptions
for name, constant in spyndex.constants.items():
    print(f"{name}: {constant.description} (default: {constant.default})")

Usage in Spectral Index Computation

Constants are typically used in two ways:

Direct Value Usage

import spyndex

# Use default values directly
result = spyndex.computeIndex(
    "SAVI",
    params={
        "N": 0.67,
        "R": 0.12,
        "L": 0.5  # Custom value instead of default
    }
)

# Use constants object for defaults
result = spyndex.computeIndex(
    "SAVI", 
    params={
        "N": 0.67,
        "R": 0.12,
        "L": spyndex.constants.L.default
    }
)

Keyword Arguments

import spyndex

# Mix constants and data
result = spyndex.computeIndex(
    "EVI",
    N=0.67,
    R=0.12,
    B=0.08,
    g=spyndex.constants.g.default,
    C1=spyndex.constants.C1.default,
    C2=spyndex.constants.C2.default,
    L=spyndex.constants.L.default
)

Parameter Sensitivity Analysis

Using constants with their metadata for parameter sensitivity studies:

import spyndex
import numpy as np

# Test SAVI sensitivity to L parameter
nir = 0.67
red = 0.12

# Default L value
default_L = spyndex.constants.L.default
savi_default = spyndex.computeIndex("SAVI", N=nir, R=red, L=default_L)

# Test range of L values
L_values = np.linspace(0.0, 2.0, 21)
savi_values = []

for L_val in L_values:
    savi = spyndex.computeIndex("SAVI", N=nir, R=red, L=L_val)
    savi_values.append(savi)

print(f"SAVI with default L ({default_L}): {savi_default:.4f}")
print(f"SAVI range across L values: {min(savi_values):.4f} to {max(savi_values):.4f}")

Constant Validation

The constants catalogue ensures consistent parameter usage across different applications:

import spyndex

def validate_evi_params(N, R, B):
    """Compute EVI with validated standard constants."""
    return spyndex.computeIndex(
        "EVI",
        params={
            "N": N,
            "R": R, 
            "B": B,
            "g": spyndex.constants.g.default,      # 2.5
            "C1": spyndex.constants.C1.default,    # 6.0
            "C2": spyndex.constants.C2.default,    # 7.5
            "L": spyndex.constants.L.default       # 1.0
        }
    )

# Ensures reproducible EVI computation
evi_standard = validate_evi_params(0.67, 0.12, 0.08)

Custom Constants

While the catalogue provides standard defaults, custom values can be used when specific research contexts require different parameter values:

import spyndex

# Standard SAVI
savi_standard = spyndex.computeIndex(
    "SAVI",
    N=0.67,
    R=0.12,
    L=spyndex.constants.L.default  # 1.0
)

# Modified SAVI for sparse vegetation
savi_sparse = spyndex.computeIndex(
    "SAVI",
    N=0.67,
    R=0.12,
    L=0.25  # Lower L value for sparse canopies
)

print(f"Standard SAVI (L=1.0): {savi_standard:.4f}")
print(f"Sparse SAVI (L=0.25): {savi_sparse:.4f}")

The constants catalogue serves as both a reference for standard parameter values and a foundation for reproducible spectral index computation across different research applications and platforms.

Install with Tessl CLI

npx tessl i tessl/pypi-spyndex

docs

bands.md

catalogue.md

computation.md

constants.md

datasets.md

index.md

plotting.md

tile.json