Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

wls_at_target

Find wavelengths values corresponding to a target spectral value


Description

Find wavelength values corresponding to a target spectral value in a spectrum. The name of the column of the spectral data to be used is inferred from the class of x and the argument passed to unit.out or filter.qty or their defaults that depend on R options set.

Usage

wls_at_target(
  x,
  target = NULL,
  interpolate = FALSE,
  idfactor = FALSE,
  na.rm = FALSE,
  ...
)

## Default S3 method:
wls_at_target(
  x,
  target = NULL,
  interpolate = FALSE,
  idfactor = FALSE,
  na.rm = FALSE,
  ...
)

## S3 method for class 'data.frame'
wls_at_target(
  x,
  target = "half.maximum",
  interpolate = FALSE,
  idfactor = FALSE,
  na.rm = FALSE,
  x.var.name = NULL,
  y.var.name = NULL,
  ...
)

## S3 method for class 'generic_spct'
wls_at_target(
  x,
  target = "half.maximum",
  interpolate = FALSE,
  idfactor = FALSE,
  na.rm = FALSE,
  col.name = NULL,
  y.var.name = col.name,
  ...
)

## S3 method for class 'source_spct'
wls_at_target(
  x,
  target = "half.maximum",
  interpolate = FALSE,
  idfactor = FALSE,
  na.rm = FALSE,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  ...
)

## S3 method for class 'response_spct'
wls_at_target(
  x,
  target = "half.maximum",
  interpolate = FALSE,
  idfactor = FALSE,
  na.rm = FALSE,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  ...
)

## S3 method for class 'filter_spct'
wls_at_target(
  x,
  target = "half.maximum",
  interpolate = FALSE,
  idfactor = FALSE,
  na.rm = FALSE,
  filter.qty = getOption("photobiology.filter.qty", default = "transmittance"),
  ...
)

## S3 method for class 'reflector_spct'
wls_at_target(
  x,
  target = "half.maximum",
  interpolate = FALSE,
  idfactor = FALSE,
  na.rm = FALSE,
  ...
)

## S3 method for class 'cps_spct'
wls_at_target(
  x,
  target = "half.maximum",
  interpolate = FALSE,
  idfactor = FALSE,
  na.rm = FALSE,
  ...
)

## S3 method for class 'generic_mspct'
wls_at_target(
  x,
  target = "half.maximum",
  interpolate = FALSE,
  idfactor = FALSE,
  na.rm = FALSE,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

x

data.frame or spectrum object.

target

numeric value indicating the spectral quantity value for which wavelengths are to be searched and interpolated if need. The character string "half.maximum" is also accepted as argument.

interpolate

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

idfactor

logical or character Generates an index column of factor type. If idfactor = TRUE then the column is auto named spct.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.

...

currently ignored.

x.var.name, y.var.name, col.name

character The name of the columns in which to search for the target value. Use of col.name is deprecated, and is a synonym for y.var.name.

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.

Value

A data.frame or 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 wavelengths for the target value is returned.

Methods (by class)

  • default: Default returning always an empty object of the same class as x.

  • data.frame: Method for "data.frame" objects.

  • generic_spct: Method for "generic_spct" objects.

  • source_spct: Method for "source_spct" objects.

  • response_spct: Method for "response_spct" objects.

  • filter_spct: Method for "filter_spct" objects.

  • reflector_spct: Method for "reflector_spct" objects.

  • cps_spct: Method for "cps_spct" objects.

  • generic_mspct: Method for "generic_mspct" objects.

Note

When interpolation is used, only column w.length and the column against which the target value was compared are included in the returned object, otherwise, all columns in x are returned. We implement support for data.frame to simplify the coding of 'ggplot2' stats using this function.

See Also

Other peaks and valleys functions: find_peaks(), find_spikes(), get_peaks(), peaks(), replace_bad_pixs(), spikes(), valleys()

Examples

wls_at_target(sun.spct, target = 0.1)
wls_at_target(sun.spct, target = 2e-6, unit.out = "photon")
wls_at_target(polyester.spct, target = "HM")
wls_at_target(polyester.spct, target = "HM", interpolate = TRUE)
wls_at_target(polyester.spct, target = "HM", idfactor = "target")
wls_at_target(polyester.spct, target = "HM", filter.qty = "absorbance")

photobiology

Photobiological Calculations

v0.10.10
GPL (>= 2)
Authors
Pedro J. Aphalo [aut, cre] (<https://orcid.org/0000-0003-3385-972X>), Titta K. Kotilainen [ctb] (<https://orcid.org/0000-0002-2822-9734>), Glenn Davis [ctb], Agnese Fazio [ctb]
Initial release
2022-03-24

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.