get_peaks {photobiology} | R Documentation |
Get peaks and valleys from a spectrum
Description
These functions "get" (or extract) peaks (maxima) and valleys (minima) in two
vectors, usually a spectral quantity and wavelength, using a user selectable
span for window width and global and local (within moving window) size
thresholds. They also generate character
values for x
.
Usage
get_peaks(
x,
y,
global.threshold = 0,
span = 5,
strict = TRUE,
x_unit = "",
x_digits = 3,
na.rm = FALSE
)
get_valleys(
x,
y,
global.threshold = 0,
span = 5,
strict = TRUE,
x_unit = "",
x_digits = 3,
na.rm = FALSE
)
Arguments
x , y |
numeric |
global.threshold |
numeric A value belonging to class |
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 |
strict |
logical flag: if |
x_unit |
character Vector of texts to be pasted at end of labels built from x value at peaks. |
x_digits |
numeric Number of significant digits in wavelength label. |
na.rm |
logical indicating whether |
Details
Function find_peaks
is a wrapper built onto function
peaks
from splus2R, adds support for peak
height thresholds and handles span = NULL
and non-finite (including
NA) values differently than splus2R::peaks
. Instead of giving an
error when na.rm = FALSE
and x
contains NA
values,
NA
values are replaced with the smallest finite value in x
.
span = NULL
is treated as a special case and selects max(x)
.
Passing 'strict = TRUE' ensures that multiple global and within window
maxima are ignored, and can result in no peaks being returned.
Two tests make it possible to ignore irrelevant peaks. One test
(global.threshold
) is based on the absolute height of the peaks and
can be used in all cases to ignore globally low peaks. A second test
(local.threshold
) is available when the window defined by 'span'
does not include all observations and can be used to ignore peaks that are
not locally prominent. In this second approach the height of each peak is
compared to a summary computed from other values within the window of width
equal to span
where it was found. In this second case, the reference
value used within each window containing a peak is given by
local.reference
. Parameter threshold.range
determines how the
values passed as argument to global.threshold
and
local.threshold
are scaled. The default, NULL
uses the range
of x
. Thresholds for ignoring too small peaks are applied after
peaks are searched for, and threshold values can in some cases
result in no peaks being returned.
While functions find_peaks
and find_valleys()
accept as input
a numeric
vector and return a logical
vector, methods
peaks
and valleys
accept as input different R
objects, including spectra and collections of spectra and return a subset
of the object. These methods are implemented using calls to functions
find_peaks
and fit_peaks
.
Value
A data frame with variables w.length and s.irrad with their values at the peaks or valleys plus a character variable of labels.
Note
The use of these two functions is deprecated. They are retained for backwards compatibility and will be removed in the near future.
See Also
Other peaks and valleys functions:
find_peaks()
,
find_spikes()
,
peaks()
,
replace_bad_pixs()
,
spikes()
,
valleys()
,
wls_at_target()