colorSpec (version 0.5-3)

resample: resample a colorSpec Object to new wavelengths

Description

interpolate or smooth to new wavelengths. Simple extrapolation is also performed.

Usage

## S3 method for class 'colorSpec':
resample( x, wavelength, method='auto', span=0.02 )

Arguments

x
a colorSpec object
wavelength
vector of new wavelengths, in nanometers
method
interpolation methods available are 'sprague', 'spline', and 'linear'. Also available is 'auto' which means to use 'sprague' if x is regular, and 'spline'<
span
smoothing argument passed to loess before interpolation, and not used by other methods. The default value span=0.02 is suitable for .scope s

Value

  • resample(x) returns a colorSpec object with the new wavelength. Other properties, e.g. organization, quantity, ..., are preserved. In case of ERROR, the function returns NULL.

Details

For method 'sprague' the quintic polynomial in De Kerf is used. Six weights are applied to nearby data values: 3 in front and 3 behind. The 'sprague' method is only supported when x is regular. For method 'spline' the function spline is called with method='natural'. Four weights are applied to nearby data values: 2 in front and 2 behind. The 'spline' method is supported even when x is irregular. For method 'linear' the function approx is called. For method 'loess' the function loess is called with the given span parameter. Smoothing is most useful for noisy data, e.g. raw data from a spectrometer. I have found that span=0.02 works well for .scope files, but this may be too small in other cases, when it triggers an error in loess(). For the non-linear methods, undershoot can sometimes create negative values, and some effort is made to clip these to 0, but only when appropriate.

References

De Kerf, Joseph L. F. The interpolation method of Sprague-Karup. Journal of Computational and Applied Mathematics. volume I, no 2, 1975. equation (S).

See Also

organization, quantity, wavelength, is.regular, spline, approx, loess

Examples

Run this code
path = system.file( "extdata/sources/pos1-20x.scope", package='colorSpec' )
y = readSpectra( path )
# plot noisy data in gray
plot( y, col='gray' )
# plot smoothed plot in black on top of the noisy one to check quality
plot( resample( y, 200:880, meth='loess', span=0.02 ), col='black', add=TRUE )

Run the code above in your browser using DataLab