This method returns the result of interpolating spectral data from the original set of wavelengths to a new one.
Usage
interpolate_wl(x, w.length.out, fill, length.out, method, ...)
# Default S3 method
interpolate_wl(x, w.length.out, fill, length.out, method, ...)
# S3 method for class 'generic_spct'
interpolate_wl(
x,
w.length.out = NULL,
fill = NA,
length.out = NULL,
method = "approx",
...
)
# S3 method for class 'generic_mspct'
interpolate_wl(
x,
w.length.out = NULL,
fill = NA,
length.out = NULL,
method = "approx",
...,
.parallel = FALSE,
.paropts = NULL
)Arguments
- x
an R object
- w.length.out
numeric vector of wavelengths (nm).
- fill
a numeric value to be assigned to out of range wavelengths.
- length.out
integer Length of the wavelength vector in the returned value. Overrides
w.length.outis notNULL, respects its range but overrides the actual values.- method
character string One of
"auto","approx","spline","skip".- ...
additional arguments passed to
spline().- .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.
Value
A new spectral object or collection of spectral objects, of the same
class as argument x. Each spectrum returned with more or fewer rows
than in x, the requested new w.length values and new numeric
values for spectral quantities, obtained by interpolation.
Details
Depending on method natural spline interpolation or linear
interpolation are used. With method = spline a call to
spline with method = "natural" is
used and with method = "approx" a call to
approx is used. If method = "auto" or
method = NULL when 100 or fewer distinct wavelengths are available
as input and/or the maximum wavelength step size in w.length.in is
more than three times the minimum wavelength step size in
w.length.out "spline" is used and "approx" otherwise.
Finally, with method = "skip" the input is returned unchanged.
If w.length.out is a numeric vector and length.out = NULL, it
directly gives the target wavelengths for interpolation. If it is
NULL, and length.out is an integer value evenly spaced
wavelength values covering the same wavelength range as in the input are
generated. If w.length.out is a numeric vector and length.out
is an integer value, length.out evenly spaced wavelengths covering
the wavelength range of w.length.out are generated.
Extrapolation is not supported.
With default fill = NA if the output exceeds the wavelength range of
the input, extrapolated values are filled with NA values. With
fill = NULL wavelengths outside the wavelength range of input data
are discarded. A numerical value can be also be provided as fill. While
interpolate_spectrum supports interpolation of a single numeric
vector, interpolate_wl applies, one at a time, interpolation to all
numeric columns found in x.
Methods (by class)
interpolate_wl(default): Default for generic functioninterpolate_wl(generic_spct): Interpolate wavelength in an object of class "generic_spct" or derived.interpolate_wl(generic_mspct): Interpolate wavelength in an object of class "generic_mspct" or derived.
Examples
interpolate_wl(sun.spct, 400:500, NA)
#> Object: source_spct [101 x 3]
#> Wavelength range 400-500 nm, step 1 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]
#> s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1]
#> --
#> # A tibble: 101 × 3
#> w.length s.e.irrad s.q.irrad
#> <int> <dbl> <dbl>
#> 1 400 0.608 0.00000203
#> 2 401 0.626 0.00000210
#> 3 402 0.650 0.00000218
#> 4 403 0.621 0.00000209
#> 5 404 0.637 0.00000215
#> 6 405 0.626 0.00000212
#> 7 406 0.600 0.00000204
#> 8 407 0.595 0.00000202
#> 9 408 0.626 0.00000213
#> 10 409 0.662 0.00000226
#> # ℹ 91 more rows
interpolate_wl(sun.spct, 400:500, NULL)
#> Object: source_spct [101 x 3]
#> Wavelength range 400-500 nm, step 1 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]
#> s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1]
#> --
#> # A tibble: 101 × 3
#> w.length s.e.irrad s.q.irrad
#> <int> <dbl> <dbl>
#> 1 400 0.608 0.00000203
#> 2 401 0.626 0.00000210
#> 3 402 0.650 0.00000218
#> 4 403 0.621 0.00000209
#> 5 404 0.637 0.00000215
#> 6 405 0.626 0.00000212
#> 7 406 0.600 0.00000204
#> 8 407 0.595 0.00000202
#> 9 408 0.626 0.00000213
#> 10 409 0.662 0.00000226
#> # ℹ 91 more rows
interpolate_wl(sun.spct, seq(200, 1000, by=0.1), 0)
#> Object: source_spct [8,001 x 3]
#> Wavelength range 200-1000 nm, step 0.1 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]
#> s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1]
#> --
#> # A tibble: 8,001 × 3
#> w.length s.e.irrad s.q.irrad
#> <dbl> <dbl> <dbl>
#> 1 200 0 0
#> 2 200. 0 0
#> 3 200. 0 0
#> 4 200. 0 0
#> 5 200. 0 0
#> 6 200. 0 0
#> 7 201. 0 0
#> 8 201. 0 0
#> 9 201. 0 0
#> 10 201. 0 0
#> # ℹ 7,991 more rows
interpolate_wl(sun.spct, c(400,500), length.out=201)
#> Object: source_spct [201 x 3]
#> Wavelength range 400-500 nm, step 0.5 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]
#> s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1]
#> --
#> # A tibble: 201 × 3
#> w.length s.e.irrad s.q.irrad
#> <dbl> <dbl> <dbl>
#> 1 400 0.608 0.00000203
#> 2 400. 0.617 0.00000207
#> 3 401 0.626 0.00000210
#> 4 402. 0.638 0.00000214
#> 5 402 0.650 0.00000218
#> 6 402. 0.635 0.00000214
#> 7 403 0.621 0.00000209
#> 8 404. 0.629 0.00000212
#> 9 404 0.637 0.00000215
#> 10 404. 0.632 0.00000214
#> # ℹ 191 more rows
