Function that returns a subset of an R object with observations corresponding to spikes. Spikes are values in spectra that are unusually high compared to neighbors. They are usually individual values or very short runs of similar "unusual" values. Spikes caused by cosmic radiation are a frequent problem in Raman spectra. Another source of spikes are "hot pixels" in CCD and diode arrays.
Usage
spikes(x, z.threshold, max.spike.width, na.rm, ...)
# Default S3 method
spikes(x, z.threshold = NA, max.spike.width = 8, na.rm = FALSE, ...)
# S3 method for class 'numeric'
spikes(x, z.threshold = NA, max.spike.width = 8, na.rm = FALSE, ...)
# S3 method for class 'data.frame'
spikes(
x,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE,
...,
y.var.name = NULL,
var.name = y.var.name
)
# S3 method for class 'generic_spct'
spikes(
x,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE,
var.name = NULL,
...
)
# S3 method for class 'source_spct'
spikes(
x,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE,
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
...
)
# S3 method for class 'response_spct'
spikes(
x,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE,
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
...
)
# S3 method for class 'filter_spct'
spikes(
x,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE,
filter.qty = getOption("photobiology.filter.qty", default = "transmittance"),
...
)
# S3 method for class 'reflector_spct'
spikes(x, z.threshold = 9, max.spike.width = 8, na.rm = FALSE, ...)
# S3 method for class 'solute_spct'
spikes(x, z.threshold = 9, max.spike.width = 8, na.rm = FALSE, ...)
# S3 method for class 'cps_spct'
spikes(
x,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE,
var.name = "cps",
...
)
# S3 method for class 'raw_spct'
spikes(
x,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE,
var.name = "counts",
...
)
# S3 method for class 'generic_mspct'
spikes(
x,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE,
...,
var.name = NULL,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for class 'source_mspct'
spikes(
x,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE,
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for class 'response_mspct'
spikes(
x,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE,
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for class 'filter_mspct'
spikes(
x,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE,
filter.qty = getOption("photobiology.filter.qty", default = "transmittance"),
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for class 'reflector_mspct'
spikes(
x,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE,
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for class 'solute_mspct'
spikes(
x,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE,
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for class 'cps_mspct'
spikes(
x,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE,
...,
var.name = "cps",
.parallel = FALSE,
.paropts = NULL
)
# S3 method for class 'raw_mspct'
spikes(
x,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE,
...,
var.name = "counts",
.parallel = FALSE,
.paropts = NULL
)
Arguments
- x
an R object
- z.threshold
numeric Modified Z values larger than
z.threshold
are considered to correspond to spikes.- max.spike.width
integer Wider regions with high Z values are not detected as spikes.
- na.rm
logical indicating whether
NA
values should be stripped before searching for spikes.- ...
ignored
- var.name, y.var.name
character Name of column where to look for spikes.
- 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.
Details
Spikes are detected based on a modified Z score calculated from the
differenced spectrum. The Z threshold used should be adjusted to the
characteristics of the input and desired sensitivity. The lower the
threshold the more stringent the test becomes, resulting in most cases in
more spikes being detected. A modified version of the algorithm is used if
a value different from NULL
is passed as argument to
max.spike.width
. In such a case, an additional step filters out
broader spikes (or falsely detected steep slopes) from the returned values.
When the argument passed to x
contains multiple spectra, the spikes
are searched for in each spectrum independently of other spectra.
Methods (by class)
spikes(default)
: Default returning always NA.spikes(numeric)
: Default function usable on numeric vectors.spikes(data.frame)
: Method for "data.frame" objects.spikes(generic_spct)
: Method for "generic_spct" objects.spikes(source_spct)
: Method for "source_spct" objects.spikes(response_spct)
: Method for "response_spct" objects.spikes(filter_spct)
: Method for "filter_spct" objects.spikes(reflector_spct)
: Method for "reflector_spct" objects.spikes(solute_spct)
: Method for "solute_spct" objects.spikes(cps_spct)
: Method for "cps_spct" objects.spikes(raw_spct)
: Method for "raw_spct" objects.spikes(generic_mspct)
: Method for "generic_mspct" objects.spikes(source_mspct)
: Method for "source_mspct" objects.spikes(response_mspct)
: Method for "cps_mspct" objects.spikes(filter_mspct)
: Method for "filter_mspct" objects.spikes(reflector_mspct)
: Method for "reflector_mspct" objects.spikes(solute_mspct)
: Method for "solute_mspct" objects.spikes(cps_mspct)
: Method for "cps_mspct" objects.spikes(raw_mspct)
: Method for "raw_mspct" objects.
See also
See the documentation for find_spikes
for details of
the algorithm and implementation.
Other peaks and valleys functions:
find_peaks()
,
find_spikes()
,
get_peaks()
,
peaks()
,
replace_bad_pixs()
,
valleys()
,
wls_at_target()
Examples
spikes(sun.spct)
#> Object: source_spct [2 x 2]
#> Wavelength range 398-432 nm, step 34 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: 2 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 398 0.504
#> 2 432 0.646