nirs4all.operators.augmentation.spectral module
- class nirs4all.operators.augmentation.spectral.BandMasking(apply_on='samples', random_state=None, *, copy=True, n_bands_range: Tuple[int, int] = (1, 3), bandwidth_range: Tuple[int, int] = (5, 20), mode: str = 'interp')[source]
Bases:
AugmenterMasks out bands of the spectrum.
Optimized with pre-generated random parameters.
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.BandPerturbation(apply_on='samples', random_state=None, *, copy=True, n_bands: int = 3, bandwidth_range: Tuple[int, int] = (5, 20), gain_range: Tuple[float, float] = (0.9, 1.1), offset_range: Tuple[float, float] = (-0.01, 0.01))[source]
Bases:
AugmenterPerturbs specific bands of the spectrum.
Optimized with pre-generated random parameters.
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.ChannelDropout(apply_on='samples', random_state=None, *, copy=True, dropout_prob: float = 0.01, mode: str = 'interp')[source]
Bases:
AugmenterDrops individual wavelengths (sets to zero or interpolates).
Optimized with vectorized mask generation.
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.GaussianAdditiveNoise(apply_on='samples', random_state=None, *, copy=True, sigma: float = 0.01, smoothing_kernel_width: int = 1)[source]
Bases:
AugmenterAdds Gaussian noise to the spectra. X_aug = X + noise
Vectorized implementation using batch convolution.
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.GaussianSmoothingJitter(apply_on='samples', random_state=None, *, copy=True, sigma_range: Tuple[float, float] = (0.5, 2.0), kernel_width: int = 11)[source]
Bases:
AugmenterApplies Gaussian smoothing with random sigma.
Optimized with pre-generated random parameters. Note: Due to per-sample kernel requirements, this still uses a loop but with pre-generated random values.
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.LinearBaselineDrift(apply_on='samples', random_state=None, *, copy=True, offset_range: Tuple[float, float] = (-0.1, 0.1), slope_range: Tuple[float, float] = (-0.001, 0.001), lambda_axis: ndarray | None = None)[source]
Bases:
AugmenterAdds a linear baseline drift. X_aug = X + a + b * lambda
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.LocalClipping(apply_on='samples', random_state=None, *, copy=True, n_regions: int = 1, width_range: Tuple[int, int] = (5, 20))[source]
Bases:
AugmenterClips values in a local region to simulate saturation.
Optimized with pre-generated random parameters.
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.LocalMixupAugmenter(apply_on='samples', random_state=None, *, copy=True, alpha: float = 0.2, k_neighbors: int = 5)[source]
Bases:
AugmenterMixup with nearest neighbors.
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.LocalWavelengthWarp(apply_on='samples', random_state=None, *, copy=True, n_control_points: int = 5, max_shift: float = 1.0, lambda_axis: ndarray | None = None)[source]
Bases:
AugmenterApplies a non-linear warp to the wavelength axis.
Optimized implementation with pre-computed control points.
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.MixupAugmenter(apply_on='samples', random_state=None, *, copy=True, alpha: float = 0.2)[source]
Bases:
AugmenterMixup augmentation. Note: This modifies both X and y. Standard transform() only returns X.
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.MultiplicativeNoise(apply_on='samples', random_state=None, *, copy=True, sigma_gain: float = 0.05, per_wavelength: bool = False)[source]
Bases:
AugmenterMultiplies spectra by a random gain factor. X_aug = (1 + epsilon) * X
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.PolynomialBaselineDrift(apply_on='samples', random_state=None, *, copy=True, degree: int = 3, coeff_ranges: List[Tuple[float, float]] | None = None, lambda_axis: ndarray | None = None)[source]
Bases:
AugmenterAdds a polynomial baseline drift.
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.ScatterSimulationMSC(apply_on='samples', random_state=None, *, copy=True, reference_mode: str = 'self', a_range: Tuple[float, float] = (-0.1, 0.1), b_range: Tuple[float, float] = (0.9, 1.1))[source]
Bases:
AugmenterSimulates scatter variation: x_aug = a + b * x
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.SmoothMagnitudeWarp(apply_on='samples', random_state=None, *, copy=True, n_control_points: int = 5, gain_range: Tuple[float, float] = (0.9, 1.1), lambda_axis: ndarray | None = None)[source]
Bases:
AugmenterMultiplies the spectrum by a smooth curve.
Optimized implementation with pre-computed control points.
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.SpikeNoise(apply_on='samples', random_state=None, *, copy=True, n_spikes_range: Tuple[int, int] = (1, 3), amplitude_range: Tuple[float, float] = (-0.5, 0.5))[source]
Bases:
AugmenterAdds spikes to the spectrum.
Optimized with pre-generated random parameters.
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.UnsharpSpectralMask(apply_on='samples', random_state=None, *, copy=True, amount_range: Tuple[float, float] = (0.1, 0.5), sigma: float = 1.0, kernel_width: int = 11)[source]
Bases:
AugmenterApplies unsharp masking (sharpening). X_aug = X + k * (X - smooth(X))
Vectorized implementation using batch convolution.
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.WavelengthShift(apply_on='samples', random_state=None, *, copy=True, shift_range: Tuple[float, float] = (-2.0, 2.0), lambda_axis: ndarray | None = None)[source]
Bases:
AugmenterShifts the wavelength axis.
Vectorized implementation using batch interpolation.
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like
- class nirs4all.operators.augmentation.spectral.WavelengthStretch(apply_on='samples', random_state=None, *, copy=True, stretch_range: Tuple[float, float] = (0.99, 1.01), lambda_axis: ndarray | None = None)[source]
Bases:
AugmenterStretches or compresses the wavelength axis.
Vectorized implementation using batch interpolation.
- augment(X, apply_on='samples')[source]
Perform data augmentation.
- Parameters:
X (array-like) – Input data to augment.
apply_on (str) – The level at which augmentation is applied. Can be one of ‘samples’, ‘features’, ‘subsets’, or ‘global’. Defaults to ‘samples’.
- Returns:
Augmented data.
- Return type:
array-like