nirs4all.operators.transforms.norris_williams module

class nirs4all.operators.transforms.norris_williams.NorrisWilliams(gap: int = 5, segment: int = 5, deriv: int = 1, delta: float = 1.0, *, copy: bool = True)[source]

Bases: TransformerMixin, BaseEstimator

Norris-Williams gap derivative transform.

Applies segment smoothing followed by gap differentiation, a standard preprocessing technique in NIR spectroscopy for computing smooth derivatives that are more robust to noise than simple finite differences.

Parameters:
  • gap (int, default=5) – Gap size in data points for the derivative computation.

  • segment (int, default=5) – Segment size for smoothing (must be odd, >= 1; 1 = no smoothing).

  • deriv (int, default=1) – Derivative order (1 or 2).

  • delta (float, default=1.0) – Sampling interval.

  • copy (bool, default=True) – Whether to copy input data.

References

Norris, K.H. and Williams, P.C. (1984). Optimization of mathematical treatments of raw near-infrared signal in the measurement of protein in hard red spring wheat. Cereal Chemistry, 61, 158-165.

fit(X, y=None)[source]

Validate input data.

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

  • y (None) – Ignored.

Raises:

ValueError – If the input X is a sparse matrix, or parameters are invalid.

Returns:

The fitted object.

Return type:

NorrisWilliams

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

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]

Apply Norris-Williams gap derivative to the data X.

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

  • copy (bool or None, optional) – Whether to copy the input data.

Returns:

The transformed data.

Return type:

numpy.ndarray

nirs4all.operators.transforms.norris_williams.norris_williams(spectra: ndarray, gap: int = 5, segment: int = 5, deriv: int = 1, delta: float = 1.0) → ndarray[source]

Norris-Williams gap derivative for spectral data.

Applies segment smoothing followed by gap differentiation, a standard preprocessing technique in NIR spectroscopy.

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

  • gap (int) – Gap size in data points.

  • segment (int) – Segment size for smoothing (must be odd, >= 1; 1 = no smoothing).

  • deriv (int) – Derivative order (1 or 2).

  • delta (float) – Sampling interval.

Returns:

Derivative spectra with same shape as input.

Return type:

numpy.ndarray

Raises:

ValueError – If deriv is not 1 or 2, or segment is not odd.