Learn R Programming

photobiology (version 0.13.2)

interpolate_wl: Map spectra to new wavelength values.

Description

This function 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, ...)

# S3 method for default interpolate_wl(x, w.length.out, fill, length.out, ...)

# S3 method for generic_spct interpolate_wl(x, w.length.out = NULL, fill = NA, length.out = NULL, ...)

# S3 method for generic_mspct interpolate_wl( x, w.length.out = NULL, fill = NA, length.out = NULL, ..., .parallel = FALSE, .paropts = NULL )

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.

Arguments

x

an R object

w.length.out

numeric vector of wavelengths (nm)

fill

a value to be assigned to out of range wavelengths

length.out

numeric value

...

not used

.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)

  • interpolate_wl(default): Default for generic function

  • interpolate_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.

Details

Depending on the extent of the data natural spline interpolation or linear interpolation are used. In the first case a call to spline with method = "natural" is used when 25 or fewer distinct wavelengths are available as input, or if the wavelengths in the output are more than three times those in the input. In the second case, a call to approx is used.

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.

Examples

Run this code
interpolate_wl(sun.spct, 400:500, NA)
interpolate_wl(sun.spct, 400:500, NULL)
interpolate_wl(sun.spct, seq(200, 1000, by=0.1), 0)
interpolate_wl(sun.spct, c(400,500), length.out=201)

Run the code above in your browser using DataLab