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
.
get_peaks(
x,
y,
global.threshold = 0,
local.threshold = 0,
local.reference = "minimum",
threshold.range = NULL,
span = 5,
strict = TRUE,
x_unit = "",
x_digits = 3,
na.rm = FALSE
)get_valleys(
x,
y,
global.threshold = 0,
local.threshold = 0,
local.reference = "minimum",
threshold.range = NULL,
span = 5,
strict = TRUE,
x_unit = "",
x_digits = 3,
na.rm = FALSE
)
A data frame with variables w.length and s.irrad with their values at the peaks or valleys plus a character variable of labels.
numeric
numeric A value between 0.0 and 1.0,
relative to threshold.range
indicating the global height
(depth) threshold below which peaks (valleys) will be ignored, or a
negative value, between 0.0 and -1.0 indicating the global height
(depth) threshold above which peaks (valleys) will be ignored. If
threshold.range = 0
or the value passed as argument belongs to class
"AsIs"
the value is interpreted as an absolute value expressed in
data units.
numeric A value between 0.0 and 1.0, relative to
threshold.range
, indicating the
within-window height (depth) threshold below which peaks (valleys)
will be ignored. If threshold.range = 0
or the value passed
as argument belongs to class "AsIs"
the value is interpreted as an
absolute value expressed in data units.
character One of "minimum"
(eqv.
"maximum"
) or "median"
. The reference used to assess the
height of the peak, either the minimum (maximum) value within the window or
the median of all values in the window.
numeric vector of length 2 or a longer vector or list
on which a call to range()
returns a numeric vector of length 2. If
NULL
, the default, range(x)
is used.
odd integer A peak is defined as an element in a sequence which
is greater than all other elements within a moving window of width
span
centred at that element. The default value is 5, meaning that a
peak is taller than its four nearest neighbours. span = NULL
extends
the span to the whole length of x
.
logical flag: if TRUE, an element must be strictly greater than all other values in its window to be considered a peak. Default: TRUE.
character Vector of texts to be pasted at end of labels built from x value at peaks.
numeric Number of significant digits in wavelength label.
logical indicating whether NA
values should be stripped
before searching for peaks.
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)
.
Two tests are optional, one based on the absolute height of the peaks
(global.threshold
) and another based on the height of the peaks
compared to other values within the window of width equal to span
(local.threshold
). 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 negative threshold
values can in some cases result in no peaks being returned.
While function find_peaks
accepts as input a numeric
vector
and returns 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
.
Other peaks and valleys functions:
find_peaks()
,
find_spikes()
,
peaks()
,
replace_bad_pixs()
,
spikes()
,
valleys()
,
wls_at_target()