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: Augmenter

Masks 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: Augmenter

Perturbs 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: Augmenter

Drops 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: Augmenter

Adds 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: Augmenter

Applies 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: Augmenter

Adds 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: Augmenter

Clips 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: Augmenter

Mixup 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

fit(X, y=None)[source]

Fit to data.

Parameters:
  • X (array-like) – Input data to fit.

  • y (array-like or None) – Target variable (unused).

Returns:

self – Returns the instance itself.

Return type:

object

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: Augmenter

Applies 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: Augmenter

Mixup 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: Augmenter

Multiplies 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: Augmenter

Adds 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: Augmenter

Simulates 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

fit(X, y=None)[source]

Fit to data.

Parameters:
  • X (array-like) – Input data to fit.

  • y (array-like or None) – Target variable (unused).

Returns:

self – Returns the instance itself.

Return type:

object

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: Augmenter

Multiplies 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: Augmenter

Adds 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: Augmenter

Applies 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: Augmenter

Shifts 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: Augmenter

Stretches 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