find_wls: Find wavelength values in a spectrum

View source: R/spct.peaks.r

find_wlsR Documentation

Find wavelength values in a spectrum

Description

Find wavelength values corresponding to a target y value in any spectrum. The name of the column of the spectral data to be used to match the target needs to be passed as argument unless the spectrum contains a single numerical variable in addition to "w.length".

Usage

find_wls(
  x,
  target = NULL,
  col.name.x = NULL,
  col.name = NULL,
  .fun = `<=`,
  interpolate = FALSE,
  idfactor = length(target) > 1,
  na.rm = FALSE
)

Arguments

x

an R object

target

numeric or character. A numeric value indicates the spectral quantity value for which wavelengths are to be searched. A character representing a number is converted to a number. A character value representing a number followed by a function name, will be also accepted and decoded, such that "0.1max" is interpreted as targetting one tenthof the maximum value in a column. The character strings "half.maximum" and "HM" are synonyms for "0.5max" while "half.range" and "HR" are synonyms for "0.5range". These synonyms are converted to the cannonical form before saving them to the returned value.

col.name.x

character The name of the column in which to the independent variable is stored. Defaults to "w.length" for objects of class "generic_spct" or derived.

col.name

character The name of the column in which to search for the target value.

.fun

function A binary comparison function or operator.

interpolate

logical Indicating whether the nearest wavelength value in x should be returned or a value calculated by linear interpolation between wavelength values stradling the target.

idfactor

logical or character Generates an index column of factor type. If idfactor = TRUE then the column is auto named target.idx. Alternatively the column name can be directly passed as argument to idfactor as a character string.

na.rm

logical indicating whether NA values should be stripped before searching for the target.

Value

A spectrum object of the same class as x with fewer rows, possibly even no rows. If FALSE is passed to interpolate a subset of x is returned, otherwise a new object of the same class containing interpolated wavelenths for the target value is returned.

Note

This function is used internally by method wls_at_target(), and these methods should be preferred in user code and scripts.

Examples

find_wls(white_led.source_spct)
find_wls(white_led.source_spct, target = "0.5max")
find_wls(white_led.source_spct, target = 0.4)
find_wls(white_led.source_spct, target = 0.4, interpolate = TRUE)
find_wls(white_led.source_spct, target = c(0.3, 0.4))
find_wls(white_led.source_spct, target = c(0.3, 0.4), idfactor = "target")
find_wls(white_led.source_spct, target = c(0.3, 0.4), idfactor = TRUE)
find_wls(white_led.source_spct, target = "0.5max")
find_wls(white_led.source_spct, target = "0.05max")
find_wls(white_led.source_spct, target = "0.5range")

led.df <- as.data.frame(white_led.source_spct)
find_wls(led.df)
find_wls(led.df, col.name = "s.e.irrad", col.name.x = "w.length")
find_wls(led.df, col.name = "s.e.irrad", col.name.x = "w.length",
         target = 0.4)
find_wls(led.df, col.name = "s.e.irrad", col.name.x = "w.length",
         target = c(0.3, 0.4))
find_wls(led.df, col.name = "s.e.irrad", col.name.x = "w.length",
         target = 0.4, idfactor = "target")


aphalo/photobiology documentation built on April 1, 2024, 6:48 p.m.