nirs4all.operators.transforms.signal module

class nirs4all.operators.transforms.signal.Baseline(*, copy=True)[source]

Bases: TransformerMixin, BaseEstimator

Removes baseline (mean) from each spectrum.

Parameters:

copy (bool, optional) – Flag to indicate whether to make a copy of the object, by default True.

fit(X, y=None)[source]

Compute the minimum and maximum to be used for later scaling.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – The data used to compute the per-feature minimum and maximum used for later scaling along the features axis.

  • y (None) – Ignored.

Returns:

self – Fitted Baseline object.

Return type:

object

inverse_transform(X, y=None)[source]
partial_fit(X, y=None)[source]
transform(X, y=None)[source]
class nirs4all.operators.transforms.signal.Detrend(bp=0, *, copy=True)[source]

Bases: TransformerMixin, BaseEstimator

Perform spectral detrending to remove linear trend from data.

Parameters:
  • bp (int, optional) – Breakpoints for piecewise linear detrending. Default is 0.

  • copy (bool, optional) – Whether to make a copy of the input data. Default is True.

fit(X, y=None)[source]

Fit the transformer to the data.

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

  • y (None) – Ignored.

Returns:

self – Returns self.

Return type:

object

set_transform_request(*, copy: bool | None | str = '$UNCHANGED$') Detrend

Configure whether metadata should be requested to be passed to the transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

copy (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for copy parameter in transform.

Returns:

self – The updated object.

Return type:

object

transform(X, copy=None)[source]

Transform the data by removing linear trend.

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

  • copy (bool or None, optional) – Whether to make a copy of the input data. If None, self.copy is used. Default is None.

Returns:

The transformed data.

Return type:

numpy.ndarray

class nirs4all.operators.transforms.signal.Gaussian(order=2, sigma=1, *, copy=True)[source]

Bases: TransformerMixin, BaseEstimator

fit(X, y=None)[source]

Fit the Gaussian filter.

Parameters:
Returns:

self – Returns the instance itself.

Return type:

object

set_transform_request(*, copy: bool | None | str = '$UNCHANGED$') Gaussian

Configure whether metadata should be requested to be passed to the transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

copy (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for copy parameter in transform.

Returns:

self – The updated object.

Return type:

object

transform(X, copy=None)[source]

Transform the input data using the Gaussian filter.

Parameters:
  • X (numpy.ndarray) – Input data.

  • copy (bool, default=None) – Whether to make a copy of the input data.

Returns:

Transformed data.

Return type:

numpy.ndarray

nirs4all.operators.transforms.signal.baseline(spectra)[source]

Removes baseline (mean) from each spectrum.

Parameters:

spectra (numpy.ndarray) – NIRS data matrix.

Returns:

Mean-centered NIRS data matrix.

Return type:

numpy.ndarray

nirs4all.operators.transforms.signal.detrend(spectra, bp=0)[source]

Perform spectral detrending to remove linear trend from data.

Parameters:
  • spectra (numpy.ndarray) – NIRS data matrix.

  • bp (list, optional) – A sequence of break points. If given, an individual linear fit is performed for each part of data between two break points. Break points are specified as indices into data. Default is 0.

Returns:

Detrended NIR spectra.

Return type:

numpy.ndarray

nirs4all.operators.transforms.signal.gaussian(spectra, order=2, sigma=1)[source]

Computes 1D gaussian filter using scipy.ndimage gaussian 1d filter.

Parameters:
  • spectra (numpy.ndarray) – NIRS data matrix.

  • order (float, optional) – Order of the derivation.

  • sigma (int, optional) – Sigma of the gaussian.

Returns:

Gaussian NIR spectra.

Return type:

numpy.ndarray