Function that returns a subset of an R object with observations corresponding to local maxima.
Usage
peaks(x, span, ignore_threshold, strict, na.rm, ...)
# Default S3 method
peaks(x, span = NA, ignore_threshold = NA, strict = NA, na.rm = FALSE, ...)
# S3 method for class 'numeric'
peaks(x, span = 5, ignore_threshold = NA, strict = TRUE, na.rm = FALSE, ...)
# S3 method for class 'data.frame'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
x.var.name = NULL,
y.var.name = NULL,
var.name = y.var.name,
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for class 'generic_spct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
var.name = NULL,
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for class 'source_spct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for class 'response_spct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for class 'filter_spct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
filter.qty = getOption("photobiology.filter.qty", default = "transmittance"),
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for class 'reflector_spct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for class 'solute_spct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for class 'cps_spct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
var.name = "cps",
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for class 'raw_spct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
var.name = "counts",
refine.wl = FALSE,
method = "spline",
...
)
# S3 method for class 'generic_mspct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
var.name = NULL,
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for class 'source_mspct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for class 'response_mspct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for class 'filter_mspct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
filter.qty = getOption("photobiology.filter.qty", default = "transmittance"),
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for class 'reflector_mspct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for class 'solute_mspct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for class 'cps_mspct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
var.name = "cps",
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for class 'raw_mspct'
peaks(
x,
span = 5,
ignore_threshold = 0,
strict = TRUE,
na.rm = FALSE,
var.name = "counts",
refine.wl = FALSE,
method = "spline",
...,
.parallel = FALSE,
.paropts = NULL
)
Arguments
- x
an R object
- span
integer A peak is defined as an element in a sequence which is greater than all other elements within a window of width
span
centered at that element. UseNULL
for the global peak.- ignore_threshold
numeric Value between 0.0 and 1.0 indicating the relative size compared to tallest peak threshold below which peaks will be ignored. Negative values set a threshold so that the tallest peaks are ignored, instead of the shortest.
- strict
logical If
TRUE
, an element must be strictly greater than all other values in its window to be considered a peak.- na.rm
logical indicating whether
NA
values should be stripped before searching for peaks.- ...
ignored
- var.name, x.var.name, y.var.name
character Name of column where to look for peaks.
- refine.wl
logical Flag indicating if peak location should be refined by fitting a function.
- method
character String with the name of a method. Currently only spline interpolation is implemented.
- unit.out
character One of "energy" or "photon"
- filter.qty
character One of "transmittance" or "absorbance"
- .parallel
if TRUE, apply function in parallel, using parallel backend provided by foreach
- .paropts
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.
Methods (by class)
peaks(default)
: Default returning always NA.peaks(numeric)
: Default function usable on numeric vectors.peaks(data.frame)
: Method for "data.frame" objects.peaks(generic_spct)
: Method for "generic_spct" objects.peaks(source_spct)
: Method for "source_spct" objects.peaks(response_spct)
: Method for "response_spct" objects.peaks(filter_spct)
: Method for "filter_spct" objects.peaks(reflector_spct)
: Method for "reflector_spct" objects.peaks(solute_spct)
: Method for "solute_spct" objects.peaks(cps_spct)
: Method for "cps_spct" objects.peaks(raw_spct)
: Method for "raw_spct" objects.peaks(generic_mspct)
: Method for "generic_mspct" objects.peaks(source_mspct)
: Method for "source_mspct" objects.peaks(response_mspct)
: Method for "cps_mspct" objects.peaks(filter_mspct)
: Method for "filter_mspct" objects.peaks(reflector_mspct)
: Method for "reflector_mspct" objects.peaks(solute_mspct)
: Method for "solute_mspct" objects.peaks(cps_mspct)
: Method for "cps_mspct" objects.peaks(raw_mspct)
: Method for "raw_mspct" objects.
Note
Thresholds for ignoring peaks are applied after peaks are searched for, and negative threshold values can in some cases result in no peaks being returned.
See also
Other peaks and valleys functions:
find_peaks()
,
find_spikes()
,
get_peaks()
,
replace_bad_pixs()
,
spikes()
,
valleys()
,
wls_at_target()
Examples
peaks(sun.spct, span = 51)
#> Object: source_spct [3 x 2]
#> Wavelength range 451-747 nm, step 44-252 nm
#> Label: sunlight, simulated
#> Measured on 2010-06-22 09:51:00 UTC
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI
#> Variables:
#> w.length: Wavelength [nm]
#> s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#> --
#> # A tibble: 3 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 451 0.820
#> 2 495 0.790
#> 3 747 0.503
peaks(sun.spct, span = NULL)
#> Object: source_spct [1 x 2]
#> Wavelength range 451-451 nm, step NA nm
#> Label: sunlight, simulated
#> Measured on 2010-06-22 09:51:00 UTC
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI
#> Variables:
#> w.length: Wavelength [nm]
#> s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#> --
#> # A tibble: 1 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 451 0.820
peaks(sun.spct, span = 51, refine.wl = TRUE)
#> Object: source_spct [3 x 2]
#> Wavelength range 451.02686-747.52003 nm, step 44.07624-252.4169 nm
#> Label: sunlight, simulated
#> Measured on 2010-06-22 09:51:00 UTC
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI
#> Variables:
#> w.length: Wavelength [nm]
#> s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#> --
#> # A tibble: 3 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 451. 0.821
#> 2 495. 0.791
#> 3 748. 0.503
peaks(sun.spct)
#> Object: source_spct [76 x 2]
#> Wavelength range 321-798 nm, step 3-20 nm
#> Label: sunlight, simulated
#> Measured on 2010-06-22 09:51:00 UTC
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI
#> Variables:
#> w.length: Wavelength [nm]
#> s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#> --
#> # A tibble: 76 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 321 0.182
#> 2 330 0.330
#> 3 335 0.313
#> 4 340 0.335
#> 5 343 0.338
#> 6 347 0.321
#> 7 350 0.345
#> 8 354 0.376
#> 9 360 0.371
#> 10 366 0.449
#> # ℹ 66 more rows