lib.vegetation

NDVI vegetation index computation and VNIR-based sunlight detection.

Vegetation index computation.

lib.vegetation.compute_ndvi(red, nir)[source]

Compute Normalized Difference Vegetation Index from radiance.

NDVI = (NIR - Red) / (NIR + Red)

Works with radiance because the ratio cancels solar irradiance to first order (same sun angle, same atmospheric path).

Parameters:
  • red (ndarray) – Red band radiance [W/m²/sr/μm], any shape.

  • nir (ndarray) – NIR band radiance [W/m²/sr/μm], same shape as red.

Returns:

NDVI array, range [-1, 1]. NaN where inputs are invalid or denominator is zero.

Return type:

ndarray

lib.vegetation.has_sunlight(red, nir, threshold=5.0)[source]

Check if VNIR bands have meaningful solar signal.

At night or under heavy cloud, reflected-solar bands (Red, NIR) read near zero. Checking actual radiance is more robust than Solar Zenith Angle because SZA only tells you if the sun is geometrically above the horizon — it can’t detect cloud blocking the signal.

Empirical MASTER NIR radiance ranges:

Daytime: median ~40, min ~7 W/m²/sr/μm Nighttime: median ~0.2, p95 ~0.5 W/m²/sr/μm (sensor noise)

Parameters:
  • red (ndarray) – Red band radiance [W/m²/sr/μm], any shape.

  • nir (ndarray) – NIR band radiance [W/m²/sr/μm], same shape.

  • threshold (float) – minimum median NIR radiance to consider “sunlit” [W/m²/sr/μm]. Default 5.0 sits between nighttime noise (~0.5) and daytime minimum (~7).

Returns:

True if the scene has usable solar illumination.

Return type:

bool

lib.vegetation.detect_vegetation_loss(baseline, current, threshold=0.15)[source]

Detect significant vegetation loss by comparing NDVI to baseline.

A drop of >= threshold from the first-observed NDVI indicates that vegetation has been consumed (e.g. by fire). Uses absolute drop, not percentage, because a 0.15 drop is physically meaningful regardless of the baseline magnitude.

Parameters:
  • baseline (ndarray) – NDVI baseline array (first valid daytime observation).

  • current (ndarray) – Current NDVI array (same shape as baseline).

  • threshold (float) – Minimum NDVI drop to flag as vegetation loss.

Returns:

Boolean mask, True where baseline - current >= threshold and both values are finite.

Return type:

ndarray