Resamples (interpolates) different spectra types with corresponding x-axis values that are both stored in list-columns of a spectra tibble. A spectra tibble hosts spectra, x-axis vectors, metadata, and further linked data with standardized naming conventions. Data input for resampling can for example be generated with simplerspec::gather_spc(). Resampling is a key harmonizing step to process and later model spectra measured at different resolutions and spectral ranges (i.e., different spectrometer devices and/or measurement settings).

resample_spc(
  spc_tbl,
  column_in = "spc",
  x_unit = c("wavenumber", "wavelength"),
  wn_lower = 500,
  wn_upper = 4000,
  wn_interval = 2,
  wl_lower = 350,
  wl_upper = 2500,
  wl_interval = 1,
  interpol_method = c("linear", "spline")
)

Arguments

spc_tbl

Spectra data embedded in a tibble object (classes "tbl_df", "tbl", "data.frame"). The spectra tibble needs to contain at least of one of the the spectra columns spc, spc_rs, spc_mean, spc_nocomp, sc_sm, sc_rf, or spc_pre (list-columns with spectral data.tables), and wavenumbers or wavelengths (list-column with vectors of x-axis values corresponding to each spectrum). The help section "Matching spectrum type and corresponding x-axis type" describes the spectra types and corresponding x-axis types.

column_in

Character vector of length 1L or symbol/name specifying the name of list-column that contains the spectra to be resampled.

x_unit

Character vector of length 1L specifying the measurement unit of the x-axis values (list-column) of the input spectra in spc_tbl. Possible values are "wavenumber" (default) or "wavelength". Wavenumber is a convenient unit of frequency in the mid-infrared spectral range, where wavelength is often used as spatial period for the visible and near-infrared range.

wn_lower

Numeric value of lowest wavenumber. This argument will only be used if x_unit = "wavenumber". The value serves as starting value for the new wavenumber sequence that the spectra will be resampled upon. Default value is 500 (i.e., in reciprocal centimeters).

wn_upper

Numeric value of highest wavenumber. This argument will only be used if x_unit = "wavenumber. The value will be used as last value of the new wavenumber sequence that the spectra will be resampled upon. Default value is 4000 (i.e., in reciprocal centimeters).

wn_interval

Numeric value of the wavenumber increment for the new wavenumber sequence that the spectra will be resampled upon. Default value is 2 (i.e., in reciprocal centimeters).

wl_lower

Numeric value of lowest wavelength. This argument will only be used if x_unit = "wavelength". The value serves as starting value of the new wavenumber sequence that the spectra will be resampled upon. Default value is 350 (i.e. in nanometers).

wl_upper

Numeric value of highest wavelength. This argument will only be used if x_unit = "wavelength". The value will be used as last value of the new wavenumber sequence that the spectra will be resampled upon. Default value is 2500 (i.e., in nanometers).

wl_interval

Numeric value of the wavelength increment for the new wavenumber sequence that the spectra will be resampled upon. This argument will only be used if x_unit = "wavelength". Default value is 1 (i.e., in nanometers).

interpol_method

Character of "linear" (default) or "spline" with the interpolation method. "spline" uses a cubic spline to interpolate the input spectra at given x-axis values to new equispaced x-axis intervals.

Value

A spectra tibble (spc_tbl) containing two added list-columns:

  • spc_rs: Resampled spectra as list of data.tables

  • wavenumbers_rs or wavelengths_rs: Resampled x-axis values as list of numeric vectors

Matching spectrum type and corresponding x-axis type

The combinations of input spectrum types (column_in) and corresponding x-axis types are generated from a simple lookup list. The following key-value(s) pairs can be matched at given key, which is the column name from column_in containing the spectra.

  • "spc" : "wavenumbers" or "wavelengths" (raw spectra)

  • "spc_rs" : "wavenumbers_rs" or "wavelengths_rs") (resampled spectra)

  • "spc_mean" : "wavenumbers_rs" or "wavelengths_rs" (mean spectra)

  • "spc_nocomp" "wavenumbers" or "wavelengths" (spectra prior atmospheric compensation)

  • "sc_sm" : c("wavenumbers_sc_sm", "wavelengths_sc_sm") (single channel sample spectra)

  • "sc_rf" : c("wavenumbers_sc_rf", "wavelengths_sc_rf") (single channel reference spectra)

  • "spc_pre" : "xvalues_pre" (preprocessed spectra)