Description Usage Arguments Details Value References See Also Examples
View source: R/colorSpec.ops.R
interpolate or smooth to new wavelengths. Simple extrapolation and clamping is also performed.
1 2  ## S3 method for class 'colorSpec'
resample( x, wavelength, method='auto', span=0.02, extrapolation='const', clamp='auto' )

x 
a colorSpec object 
wavelength 
vector of new wavelengths, in nanometers 
method 
interpolation methods available are

span 
smoothing argument passed to 
extrapolation 
extrapolation methods available are

clamp 
clamp methods available are

If method is 'sprague'
, the quintic polynomial in De Kerf is used.
Six weights are applied to nearby data values: 3 on each side.
The 'sprague'
method is only supported when x
is regular.
If method is 'spline'
, the function stats::spline()
is called with method='natural'
.
The 'spline'
method is supported even when x
is irregular.
If method is 'linear'
, the function stats::approx()
is called.
Two weights are applied to nearby data values: 1 on each side.
The 'linear'
method is supported even when x
is irregular.
If method is 'loess'
, the function stats::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 Ocean Optics .scope
files,
but this may be too small in other cases, which triggers an error in stats::loess()
.
The 'loess'
method is supported even when x
is irregular.
If extrapolation is 'const'
,
the extreme values at each end are simply extended.
If extrapolation is 'linear'
,
the line defined by the 2 extreme values at each end is used for extrapolation.
If the ultimate and penultimate wavelengths are equal,
then this line is undefined and the function reverts to 'const'
.
If clamp is 'auto'
,
output values are clamped to the physically realizable interval
appropriate for x
.
This is the interval [0,1] when
quantity(x)
is 'reflectance'
or 'transmittance'
,
and the interval [0,∞) otherwise.
Exception: If an input spectrum in x
violates a limit,
then clamping the output spectrum to this limit is NOT enforced.
This happens most frequenty for theoretical (or matrixed) cameras,
such as BT.709.RGB
.
If clamp is TRUE
, the result is the same as 'auto'
,
but with no exceptions.
If clamp is FALSE
, then no clamping is done.
If clamp is a numerical interval, then clamping is done to that interval,
with no exceptions.
The two standard intervals mentioned above can be expressed in R
as c(0,1)
and c(0,Inf)
respectively.
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
.
De Kerf, Joseph L. F. The interpolation method of SpragueKarup. Journal of Computational and Applied Mathematics. volume I, no 2, 1975. equation (S).
organization()
,
quantity()
,
wavelength()
,
is.regular()
,
theoreticalRGB
,
spline()
,
approx()
,
loess
1 2 3 4 5 6  path = system.file( "extdata/sources/pos120x.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 )

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.