Skip to contents

Function to calculate the mean, total, or other summary of absorbance for spectral data stored in a filter_spct or in an object_spct.

Usage

absorbance(spct, w.band, quantity, wb.trim, use.hinges, ...)

# Default S3 method
absorbance(spct, w.band, quantity, wb.trim, use.hinges, ...)

# S3 method for class 'filter_spct'
absorbance(
  spct,
  w.band = NULL,
  quantity = "average",
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.hinges = NULL,
  naming = "default",
  ...
)

# S3 method for class 'object_spct'
absorbance(
  spct,
  w.band = NULL,
  quantity = "average",
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.hinges = NULL,
  naming = "default",
  ...
)

# S3 method for class 'filter_mspct'
absorbance(
  spct,
  w.band = NULL,
  quantity = "average",
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.hinges = NULL,
  naming = "default",
  ...,
  attr2tb = NULL,
  idx = "spct.idx",
  .parallel = FALSE,
  .paropts = NULL
)

# S3 method for class 'object_mspct'
absorbance(
  spct,
  w.band = NULL,
  quantity = "average",
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.hinges = NULL,
  naming = "default",
  ...,
  attr2tb = NULL,
  idx = "spct.idx",
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

spct

an R object.

w.band

waveband or list of waveband objects or a numeric vector of length two. The waveband(s) determine the region(s) of the spectrum that are summarized. If a numeric range is supplied a waveband object is constructed on the fly from it.

quantity

character string One of "average" or "mean", "total", "contribution", "contribution.pc", "relative" or "relative.pc".

wb.trim

logical if TRUE wavebands crossing spectral data boundaries are trimmed, if FALSE, they are discarded.

use.hinges

logical Flag indicating whether to insert "hinges" into the spectral data before integration so as to reduce interpolation errors at the boundaries of the wavebands.

...

other arguments (possibly used by derived methods).

naming

character one of "long", "default", "short" or "none". Used to select the type of names to assign to returned value.

attr2tb

character vector, see add_attr2tb for the syntax for attr2tb passed as is to formal parameter col.names.

idx

character Name of the column with the names of the members of the collection of spectra.

.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 named numeric vector in the case of methods for individual spectra, with one value for each waveband passed to parameter w.band. A data.frame in the case of collections of spectra, containing one column for each waveband object, an index column with the names of the spectra, and optionally additional columns with metadata values retrieved from the attributes of the member spectra.

By default values are only integrated, but depending on the argument passed to parameter quantity they can be re-expressed as relative fractions or percentages. In the case of vector output, names attribute is set to the name of the corresponding waveband unless a named list is supplied in which case the names of the list members are used.

Methods (by class)

  • absorbance(default): Default for generic function

  • absorbance(filter_spct): Specialization for filter spectra

  • absorbance(object_spct): Specialization for object spectra

  • absorbance(filter_mspct): Calculates absorbance from a filter_mspct

  • absorbance(object_mspct): Calculates absorbance from a object_mspct

Note

The use.hinges parameter controls speed optimization. The defaults should be suitable in most cases. Only the range of wavelengths in the wavebands is used and all BSWFs are ignored.

Examples

absorbance(polyester.spct, new_waveband(400,700))
#> A(wl)_range.400.700 
#>           0.0361018 
#> attr(,"Tfr.type")
#> [1] "total"
#> attr(,"radiation.unit")
#> [1] "absorbance average"
absorbance(yellow_gel.spct, new_waveband(400,700))
#> A(wl)_range.400.700 
#>            1.155065 
#> attr(,"Tfr.type")
#> [1] "total"
#> attr(,"radiation.unit")
#> [1] "absorbance average"
absorbance(yellow_gel.spct, split_bands(c(400,700), length.out = 3))
#>  A(wl)_wb1  A(wl)_wb2  A(wl)_wb3 
#> 3.29089046 0.12744389 0.04686074 
#> attr(,"Tfr.type")
#> [1] "total"
#> attr(,"radiation.unit")
#> [1] "absorbance average"
absorbance(yellow_gel.spct, split_bands(c(400,700), length.out = 3),
        quantity = "average")
#>  A(wl)_wb1  A(wl)_wb2  A(wl)_wb3 
#> 3.29089046 0.12744389 0.04686074 
#> attr(,"Tfr.type")
#> [1] "total"
#> attr(,"radiation.unit")
#> [1] "absorbance average"
absorbance(yellow_gel.spct, split_bands(c(400,700), length.out = 3),
        quantity = "total")
#>      A_wb1      A_wb2      A_wb3 
#> 329.089046  12.744389   4.686074 
#> attr(,"Tfr.type")
#> [1] "total"
#> attr(,"radiation.unit")
#> [1] "absorbance total"
absorbance(yellow_gel.spct, split_bands(c(400,700), length.out = 3),
        quantity = "relative")
#> A/Asum_wb1 A/Asum_wb2 A/Asum_wb3 
#> 0.94969847 0.03677827 0.01352326 
#> attr(,"Tfr.type")
#> [1] "total"
#> attr(,"radiation.unit")
#> [1] "absorbance relative"
absorbance(yellow_gel.spct, split_bands(c(400,700), length.out = 3),
        quantity = "relative.pc")
#> A/Asum[%]_wb1 A/Asum[%]_wb2 A/Asum[%]_wb3 
#>     94.969847      3.677827      1.352326 
#> attr(,"Tfr.type")
#> [1] "total"
#> attr(,"radiation.unit")
#> [1] "absorbance relative.pc"
absorbance(yellow_gel.spct, split_bands(c(400,700), length.out = 3),
        quantity = "contribution")
#>  A/Atot_wb1  A/Atot_wb2  A/Atot_wb3 
#> 0.266833683 0.010333472 0.003799586 
#> attr(,"Tfr.type")
#> [1] "total"
#> attr(,"radiation.unit")
#> [1] "absorbance contribution"
absorbance(yellow_gel.spct, split_bands(c(400,700), length.out = 3),
        quantity = "contribution.pc")
#> A/Atot[%]_wb1 A/Atot[%]_wb2 A/Atot[%]_wb3 
#>    26.6833683     1.0333472     0.3799586 
#> attr(,"Tfr.type")
#> [1] "total"
#> attr(,"radiation.unit")
#> [1] "absorbance contribution.pc"