Function that returns a subset of an R object with observations corresponding to local maxima.
valleys(
x,
span,
global.threshold,
local.threshold,
local.reference,
threshold.range,
strict,
...
)# S3 method for default
valleys(
x,
span,
global.threshold = NA,
local.threshold = NA,
local.reference = NA,
threshold.range = NA,
strict,
...
)
# S3 method for numeric
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "median",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
...
)
# S3 method for data.frame
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "median",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
x.var.name = NULL,
y.var.name = NULL,
var.name = y.var.name,
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for generic_spct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "median",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
var.name = NULL,
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for source_spct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "median",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for response_spct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "minimum",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for filter_spct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "minimum",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
filter.qty = getOption("photobiology.filter.qty", default = "transmittance"),
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for reflector_spct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "minimum",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for solute_spct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "minimum",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for cps_spct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "minimum",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
var.name = "cps",
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for raw_spct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "minimum",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
var.name = "counts",
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for generic_mspct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "minimum",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
var.name = NULL,
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for source_mspct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "minimum",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for response_mspct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "minimum",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for filter_mspct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "minimum",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
filter.qty = getOption("photobiology.filter.qty", default = "transmittance"),
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for reflector_mspct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "minimum",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for solute_mspct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "minimum",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for cps_mspct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "minimum",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
var.name = "cps",
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for raw_mspct
valleys(
x,
span = 5,
global.threshold = NULL,
local.threshold = NULL,
local.reference = "minimum",
threshold.range = NULL,
strict = FALSE,
na.rm = FALSE,
var.name = "counts",
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
A subset of x
with rows corresponding to local minima or
global minimum.
numeric vector. Hint: to find valleys, change the sign of the
argument with the unnary operator -
.
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 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
.
numeric A value belonging to class "AsIs"
is
interpreted as an absolute minimum height or depth expressed in data units.
A bare numeric
value (normally between 0.0 and 1.0), is interpreted
as relative to threshold.range
. In both cases it sets a
global height (depth) threshold below which peaks (valleys) are
ignored. A bare negative numeric
value indicates the global
height (depth) threshold below which peaks (valleys) are be ignored. If
global.threshold = NULL
, no threshold is applied and all peaks
returned.
numeric A value belonging to class "AsIs"
is
interpreted as an absolute minimum height (depth) expressed in data units
relative to a within-window computed reference value. A bare numeric
value (normally between 0.0 and 1.0), is interpreted as expressed in units
relative to threshold.range
. In both cases local.threshold
sets a local height (depth) threshold below which peaks (valleys)
are ignored. If local.threshold = NULL
or if span
spans the
whole of x
, no threshold is applied.
character One of "median"
or "farthest"
.
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 If of length 2 or a longer vector
range(threshold.range)
is used to scale both thresholds. With
NULL
, the default, range(x)
is used, and with a vector of
length one range(threshold.range, x)
is used, i.e., the range
is expanded.
logical flag: if TRUE
, an element must be strictly
greater than all other values in its window to be considered a peak.
Default: FALSE
(since version 0.13.1).
ignored
logical indicating whether NA
values should be stripped
before searching for peaks.
character Name of column where to look for valleys.
logical Flag indicating if valley location should be refined by fitting a function.
character String with the name of a method. Currently only spline interpolation is implemented.
character One of "energy" or "photon"
character One of "transmittance" or "absorbance"
if TRUE, apply function in parallel, using parallel backend provided by foreach
a list of additional options passed into the foreach function when parallel computation is enabled. This is important if (for example) your code relies on external data or packages: use the .export and .packages arguments to supply them so that all cluster nodes have the correct environment set up for computing.
valleys(default)
: Default returning always NA.
valleys(numeric)
: Default function usable on numeric vectors.
valleys(data.frame)
: Method for "data.frame" objects.
valleys(generic_spct)
: Method for "generic_spct" objects.
valleys(source_spct)
: Method for "source_spct" objects.
valleys(response_spct)
: Method for "response_spct" objects.
valleys(filter_spct)
: Method for "filter_spct" objects.
valleys(reflector_spct)
: Method for "reflector_spct".
valleys(solute_spct)
: Method for "solute_spct" objects.
valleys(cps_spct)
: Method for "cps_spct" objects.
valleys(raw_spct)
: Method for "raw_spct" objects.
valleys(generic_mspct)
: Method for "generic_mspct" objects.
valleys(source_mspct)
: Method for "source_mspct" objects.
valleys(response_mspct)
: Method for "cps_mspct" objects.
valleys(filter_mspct)
: Method for "filter_mspct" objects.
valleys(reflector_mspct)
: Method for "reflector_mspct" objects.
valleys(solute_mspct)
: Method for "solute_mspct" objects.
valleys(cps_mspct)
: Method for "cps_mspct" objects.
valleys(raw_mspct)
: Method for "raw_mspct" objects.
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
.
Other peaks and valleys functions:
find_peaks()
,
find_spikes()
,
get_peaks()
,
peaks()
,
replace_bad_pixs()
,
spikes()
,
wls_at_target()
# default span = 5
valleys(sun.spct)
# global minimum
valleys(sun.spct, span = NULL)
valleys(sun.spct, span = NULL, strict = FALSE)
# a wider window
valleys(sun.spct, span = 51)
# global threshold relative to the range of s.e.irrad values
valleys(sun.spct, global.threshold = -0.2)
# global threshold in actual s.e.irrad values
valleys(sun.spct, global.threshold = -0.2, threshold.range = c(0, 1))
# local threshold relative to the range of s.e.irrad values
valleys(sun.spct, local.threshold = 0.1)
# local threshold in actual s.e.irrad values
valleys(sun.spct, local.threshold = 0.1, threshold.range = c(0, 1))
# local threshold relative to the range of s.e.irrad values, using window
# median instead of window minimum
valleys(sun.spct, local.threshold = 0.1, local.reference = "median")
# minimum, the default.
valleys(sun.spct, local.threshold = 0.1, local.reference = "farthest")
valleys(sun.spct)
Run the code above in your browser using DataLab