nirs4all.utils.header_units module
Centralized header unit utilities for consistent handling across the codebase.
This module provides a single source of truth for: - Axis labels based on header unit type - X-values extraction from headers - Axis orientation (for wavenumber inversion)
All visualization code should use these utilities instead of inline logic.
- nirs4all.utils.header_units.parse_numeric_headers(headers: list[str] | None) ndarray | None[source]
Parse headers into a float array, tolerating a trailing unit suffix (e.g.
"852.78_nm").Accepts plain numbers and numbers with a known unit suffix (
nm/µm/cm-1), with an optional_/-/space separator. ReturnsNoneif any header is not such a value, so the caller can fall back to indices or raise — rather than silently mining a number out of arbitrary text like"feature_852.78_nm".
- nirs4all.utils.header_units.should_invert_x_axis(x_values: ndarray) bool[source]
Check if x-axis should be inverted (for wavenumber convention).
In spectroscopy, wavenumber (cm⁻¹) axes are often displayed in descending order (high to low) if the data is ordered that way.
- Parameters:
x_values – Array of x-axis values
- Returns:
True if x_values are in descending order and should be displayed as such