prep_wav_trim: Wavelength or wavenumber trimming constructor for spectral...

View source: R/prep_wav_trim.R

prep_wav_trimR Documentation

Wavelength or wavenumber trimming constructor for spectral preprocessing

Description

\loadmathjax

Creates a preprocessing constructor for trimming spectral data to a specified wavelength/wavenumber band. The constructor is intended to be passed to preprocess_recipe and executed via process.

Usage

prep_wav_trim(
  band,
  trim_constant_edges = FALSE
)

Arguments

band

A numeric vector of length 2 giving the minimum and maximum wavenumber/wavelength to retain. Columns of X outside this range are dropped. Pass c() (empty vector) to skip band trimming and only apply trim_constant_edges.

trim_constant_edges

A logical. If TRUE, constant or zero-valued columns at the left and right edges are removed after band trimming. Default is FALSE.

Details

Band trimming retains only those columns whose names (coerced to numeric) fall within [min(band), max(band)]. If no columns fall within the band the original matrix is returned with a warning.

Constant edge trimming scans inward from each edge and drops columns that are identical to their immediate neighbour or are all zero. If trimming would leave fewer than two columns the step is skipped with a warning.

Because constant edge trimming depends on the data values, it is resolved to the exact set of wavelengths/wavenumbers retained on the training data when the step is used in calibrate, so that predictions trim newdata to exactly the same columns.

Value

An object of class preprocessing to be used in preprocess_recipe and executed by process.

Author(s)

Claudio Orellano and Leonardo Ramirez-Lopez

See Also

preprocess_recipe, process

Examples

data("proximateCannabis")
X <- proximateCannabis$spc

tr <- prep_wav_trim(band = c(1000, 1800))
recipe <- preprocess_recipe(tr, device = "proxiscout")
X_trim <- process(X, recipe)


proximetricsR documentation built on Sept. 4, 2026, 5:08 p.m.