Check the spread of wavelength step sizes in an ordered numeric
vector, or in the "w.length" column of a spectral object containing
a single spectrum.
Arguments
- x
numeric vector.
- span
odd positive integer A peak is defined as an element in a sequence which is greater than all other elements within a moving window of width
spancentred at that element. The default value is 5, meaning that a peak is taller than its four nearest neighbours.span = NULLextends the span to the whole length ofx.- na.rm
logical indicating whether
NAvalues should be stripped before searching for peaks.- min.stepsize
numeric The minimum wavelength step size in nanometres to use for comparison to the longest one.
Value
A logical TRUE is returned invisibly if check is passed and
otherwise FALSE with a warning. A warning is issued on failure as
a side effect.
Details
As the search for peaks uses a window based on a fixed number of
observations at neighbouring wavelengths, if the wavelength step between
observations varies drastically, the window expressed in nanometres of
wavelength becomes very irregular. With the default span = 5 in
peaks(), valleys(), and wls_at_target() the
search in most cases still works for "thinned" spectra, and the check is
skipped. With spikes() and despike() methods the check is
always done as these methods do not override span = Inf.
The typical case when the step can vary strongly are spectra returned by
thin_wl(). As when using default arguments, including
span = 21, thin_wl() retains the original local maxima and
global maximum, and a reasonably narrow wavelength maximum step a call
to peaks with span = NULL or span = 5 tends
to discover the original peaks missing at most a few.
Examples
check_wl_stepsize(sun.spct)
check_wl_stepsize(c(1:20, 25), span = 30)
#> 'eval()' assumes consistent w.length steps! max step / min step = 5
check_wl_stepsize(1:20, span = 30, min.stepsize = 4)
