nirs4all.data.signal_type module

Signal type management for spectroscopy data.

This module provides: - SignalType enum for absorbance, reflectance, transmittance - Autodetection heuristics based on value ranges and band directions - Conversion utilities between signal types

class nirs4all.data.signal_type.SignalType(value)[source]

Bases: str, Enum

Spectral signal types for NIRS/spectroscopy data.

Defines the measurement type of spectral data. String values ensure backward compatibility with config files.

ABSORBANCE = 'absorbance'
AUTO = 'auto'
KUBELKA_MUNK = 'kubelka_munk'
LOG_1_R = 'log_1_r'
LOG_1_T = 'log_1_t'
PREPROCESSED = 'preprocessed'
REFLECTANCE = 'reflectance'
REFLECTANCE_PERCENT = 'reflectance%'
TRANSMITTANCE = 'transmittance'
TRANSMITTANCE_PERCENT = 'transmittance%'
UNKNOWN = 'unknown'
classmethod from_string(value: str) SignalType[source]

Parse signal type from various string representations.

Parameters:

value – String representation (e.g., “A”, “R”, “%R”, “absorbance”, etc.)

Returns:

SignalType enum value

property is_absorbance_like: bool

Check if this is absorbance or pseudo-absorbance.

property is_determinable: bool

Check if this is a known, determinable signal type.

property is_fraction: bool

Check if this is a fractional [0, 1] signal type.

property is_percent: bool

Check if this is a percentage-based signal type.

property is_reflectance_based: bool

Check if this is any reflectance-based signal.

property is_transmittance_based: bool

Check if this is any transmittance-based signal.

class nirs4all.data.signal_type.SignalTypeDetector(wavelengths: ndarray | None = None, wavelength_unit: str = 'nm')[source]

Bases: object

Heuristic detector for spectral signal types.

Uses value ranges and optionally wavelength information to determine whether data is absorbance, reflectance, or transmittance.

WATER_BANDS_CM1 = [6897, 5155, 4000]
WATER_BANDS_NM = [1450, 1940, 2500]
detect(spectra: ndarray, confidence_threshold: float = 0.7) Tuple[SignalType, float, str][source]

Detect the signal type of spectral data.

Parameters:
  • spectra – Spectral data array of shape (n_samples, n_features)

  • confidence_threshold – Minimum confidence to return a definite type

Returns:

Tuple of (SignalType, confidence, reason_string)

nirs4all.data.signal_type.detect_signal_type(spectra: ndarray, wavelengths: ndarray | None = None, wavelength_unit: str = 'nm') Tuple[SignalType, float, str][source]

Convenience function to detect signal type.

Parameters:
  • spectra – Spectral data array (n_samples, n_features)

  • wavelengths – Optional wavelength values for band analysis

  • wavelength_unit – Unit of wavelengths (“nm” or “cm-1”)

Returns:

Tuple of (SignalType, confidence, reason)

Example

>>> spectra = np.random.rand(100, 500) * 0.8  # Values in [0, 0.8]
>>> signal_type, confidence, reason = detect_signal_type(spectra)
>>> print(f"Detected: {signal_type.value} ({confidence:.0%})")
nirs4all.data.signal_type.normalize_signal_type(signal_type: str | SignalType) SignalType[source]

Normalize a signal type input to SignalType enum.

Parameters:

signal_type – String or SignalType enum

Returns:

SignalType enum value