nirs4all.operators.augmentation.spectral module

class nirs4all.operators.augmentation.spectral.BandMasking(n_bands_range: tuple[int, int] = (1, 3), bandwidth_range: tuple[int, int] = (5, 20), mode: str = 'interp', random_state=None)[source]

Bases: TransformerMixin, BaseEstimator

Masks out bands of the spectrum.

Optimized with pre-generated random parameters.

fit(X, y=None, **kwargs)[source]
transform(X, **kwargs)[source]
class nirs4all.operators.augmentation.spectral.BandPerturbation(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), random_state=None, variation_scope: str = 'sample')[source]

Bases: TransformerMixin, BaseEstimator

Perturbs specific bands of the spectrum.

Optimized with pre-generated random parameters.

fit(X, y=None, **kwargs)[source]
transform(X, **kwargs)[source]
class nirs4all.operators.augmentation.spectral.ChannelDropout(dropout_prob: float = 0.01, mode: str = 'interp', random_state=None)[source]

Bases: TransformerMixin, BaseEstimator

Drops individual wavelengths (sets to zero or interpolates).

Optimized with vectorized mask generation.

fit(X, y=None, **kwargs)[source]
transform(X, **kwargs)[source]
class nirs4all.operators.augmentation.spectral.GaussianAdditiveNoise(sigma: float = 0.01, smoothing_kernel_width: int = 1, random_state=None, variation_scope: str = 'sample')[source]

Bases: TransformerMixin, BaseEstimator

Adds Gaussian noise to the spectra. X_aug = X + noise

Vectorized implementation using batch convolution.

fit(X, y=None, **kwargs)[source]
transform(X, **kwargs)[source]
class nirs4all.operators.augmentation.spectral.GaussianSmoothingJitter(sigma_range: tuple[float, float] = (0.5, 2.0), kernel_width: int = 11, random_state=None)[source]

Bases: TransformerMixin, BaseEstimator

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.

fit(X, y=None, **kwargs)[source]
transform(X, **kwargs)[source]
class nirs4all.operators.augmentation.spectral.LinearBaselineDrift(offset_range: tuple[float, float] = (-0.1, 0.1), slope_range: tuple[float, float] = (-0.001, 0.001), random_state=None)[source]

Bases: SpectraTransformerMixin

Adds a linear baseline drift. X_aug = X + a + b * lambda

fit(X, y=None, **kwargs)[source]

Fit the transformer. Override in subclass if needed.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Training data.

  • y (array-like of shape (n_samples,) or None, default=None) – Target values (unused).

  • **kwargs (dict) – Additional fit parameters. May include ‘wavelengths’ for operators that need to fit using wavelength information.

Returns:

self – Returns self.

Return type:

object

class nirs4all.operators.augmentation.spectral.LocalClipping(n_regions: int = 1, width_range: tuple[int, int] = (5, 20), random_state=None)[source]

Bases: TransformerMixin, BaseEstimator

Clips values in a local region to simulate saturation.

Optimized with pre-generated random parameters.

fit(X, y=None, **kwargs)[source]
transform(X, **kwargs)[source]
class nirs4all.operators.augmentation.spectral.LocalMixupAugmenter(alpha: float = 0.2, k_neighbors: int = 5, random_state=None)[source]

Bases: TransformerMixin, BaseEstimator

Mixup with nearest neighbors.

fit(X, y=None, **kwargs)[source]
transform(X, **kwargs)[source]
class nirs4all.operators.augmentation.spectral.LocalWavelengthWarp(n_control_points: int = 5, max_shift: float = 1.0, random_state=None)[source]

Bases: SpectraTransformerMixin

Applies a non-linear warp to the wavelength axis.

Optimized implementation with pre-computed control points.

fit(X, y=None, **kwargs)[source]

Fit the transformer. Override in subclass if needed.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Training data.

  • y (array-like of shape (n_samples,) or None, default=None) – Target values (unused).

  • **kwargs (dict) – Additional fit parameters. May include ‘wavelengths’ for operators that need to fit using wavelength information.

Returns:

self – Returns self.

Return type:

object

class nirs4all.operators.augmentation.spectral.MixupAugmenter(alpha: float = 0.2, random_state=None)[source]

Bases: TransformerMixin, BaseEstimator

Mixup augmentation. Note: This modifies both X and y. Standard transform() only returns X.

fit(X, y=None, **kwargs)[source]
transform(X, **kwargs)[source]
class nirs4all.operators.augmentation.spectral.MultiplicativeNoise(sigma_gain: float = 0.05, per_wavelength: bool = False, random_state=None, variation_scope: str = 'sample')[source]

Bases: TransformerMixin, BaseEstimator

Multiplies spectra by a random gain factor. X_aug = (1 + epsilon) * X

fit(X, y=None, **kwargs)[source]
transform(X, **kwargs)[source]
class nirs4all.operators.augmentation.spectral.PolynomialBaselineDrift(degree: int = 3, coeff_ranges: list[tuple[float, float]] | None = None, random_state=None)[source]

Bases: SpectraTransformerMixin

Adds a polynomial baseline drift.

fit(X, y=None, **kwargs)[source]

Fit the transformer. Override in subclass if needed.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Training data.

  • y (array-like of shape (n_samples,) or None, default=None) – Target values (unused).

  • **kwargs (dict) – Additional fit parameters. May include ‘wavelengths’ for operators that need to fit using wavelength information.

Returns:

self – Returns self.

Return type:

object

class nirs4all.operators.augmentation.spectral.ScatterSimulationMSC(reference_mode: str = 'self', a_range: tuple[float, float] = (-0.1, 0.1), b_range: tuple[float, float] = (0.9, 1.1), random_state=None)[source]

Bases: SpectraTransformerMixin

Simulates scatter variation: x_aug = x + a + (b - 1) * reference.

With reference_mode=”self”, the reference is each input spectrum, giving a + b * x. With “global_mean”, the fitted training mean supplies the scatter direction; deviations from that reference remain unchanged.

fit(X, y=None, **kwargs)[source]

Fit the transformer. Override in subclass if needed.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Training data.

  • y (array-like of shape (n_samples,) or None, default=None) – Target values (unused).

  • **kwargs (dict) – Additional fit parameters. May include ‘wavelengths’ for operators that need to fit using wavelength information.

Returns:

self – Returns self.

Return type:

object

class nirs4all.operators.augmentation.spectral.SmoothMagnitudeWarp(n_control_points: int = 5, gain_range: tuple[float, float] = (0.9, 1.1), random_state=None)[source]

Bases: SpectraTransformerMixin

Multiplies the spectrum by a smooth curve.

Optimized implementation with pre-computed control points.

fit(X, y=None, **kwargs)[source]

Fit the transformer. Override in subclass if needed.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Training data.

  • y (array-like of shape (n_samples,) or None, default=None) – Target values (unused).

  • **kwargs (dict) – Additional fit parameters. May include ‘wavelengths’ for operators that need to fit using wavelength information.

Returns:

self – Returns self.

Return type:

object

class nirs4all.operators.augmentation.spectral.SpikeNoise(n_spikes_range: tuple[int, int] = (1, 3), amplitude_range: tuple[float, float] = (-0.5, 0.5), random_state=None, variation_scope: str = 'sample')[source]

Bases: TransformerMixin, BaseEstimator

Adds spikes to the spectrum.

Optimized with pre-generated random parameters.

fit(X, y=None, **kwargs)[source]
transform(X, **kwargs)[source]
class nirs4all.operators.augmentation.spectral.UnsharpSpectralMask(amount_range: tuple[float, float] = (0.1, 0.5), sigma: float = 1.0, kernel_width: int = 11, random_state=None)[source]

Bases: TransformerMixin, BaseEstimator

Applies unsharp masking (sharpening). X_aug = X + k * (X - smooth(X))

Vectorized implementation using batch convolution.

fit(X, y=None, **kwargs)[source]
transform(X, **kwargs)[source]
class nirs4all.operators.augmentation.spectral.WavelengthShift(shift_range: tuple[float, float] = (-2.0, 2.0), random_state=None)[source]

Bases: SpectraTransformerMixin

Shifts the wavelength axis.

Vectorized implementation using batch interpolation.

fit(X, y=None, **kwargs)[source]

Fit the transformer. Override in subclass if needed.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Training data.

  • y (array-like of shape (n_samples,) or None, default=None) – Target values (unused).

  • **kwargs (dict) – Additional fit parameters. May include ‘wavelengths’ for operators that need to fit using wavelength information.

Returns:

self – Returns self.

Return type:

object

class nirs4all.operators.augmentation.spectral.WavelengthStretch(stretch_range: tuple[float, float] = (0.99, 1.01), random_state=None)[source]

Bases: SpectraTransformerMixin

Stretches or compresses the wavelength axis.

Vectorized implementation using batch interpolation.

fit(X, y=None, **kwargs)[source]

Fit the transformer. Override in subclass if needed.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Training data.

  • y (array-like of shape (n_samples,) or None, default=None) – Target values (unused).

  • **kwargs (dict) – Additional fit parameters. May include ‘wavelengths’ for operators that need to fit using wavelength information.

Returns:

self – Returns self.

Return type:

object