Skip to contents

Convert between objects of class rspec as used in package 'pavo' and similar objects returned by functions from package 'lightr' in objects of classes from 'photobiology'

Usage

rspec2mspct(
  x,
  member.class = "reflector_spct",
  spct.data.var = "Rpc",
  multiplier = 1,
  ...
)

rspec2spct(x, multiplier = 1, ...)

Arguments

x

rspec object

member.class

character One of the spectrum classes defined in package 'photobiology'. Examples are `reflector_spct`, `filter_spct`, `source_spct`, etc.

spct.data.var

character The name to be used for the 'spc' data when constructing the spectral objects. Examples are spectral reflectance as percent or as a fraction of one, `Rpc`, `Rfr`, spectral transmittance`Tpc`, `Tfr`, spectral energy irradiance in \(w m^{-2}\) `s.e.irrad`, spectral photon irradiance in \(mol m^{-2} s^{-1}\) `s.q.irrad`, etc.

multiplier

numeric A multiplier to be applied to spectral data in the 'rspc' object to do unit or scale conversion.

...

currently ignored.

Details

rspec objects contain data for multiple spectra in wide form, i.e., one column per spectrum. Function rscpt2mspct() converts them into a list-like collection of spectra (xxxx_mspct) with spectra stored as separate members. In contrast, rscpt2spct() stores the spectra in long form into a single data-frame-like object (xxxx_spct). The classes of the returned objects are defined in package 'photobiology' and derived from list and data.frame respectively.

Objects of class pavo::rspec do not contain metadata or class data from which the quantity measured and the units of expression could be retrieved. Thus, when using this function users need to use parameter multiplier to convert the data to the units and scaling that is expected by the object constructors defined in package 'photobiology' and use parameter spct.data.var to indicate the physical quantity.

@note pavo::rspec objects may use memory more efficiently than spectral objects of the classes for collections of spectra defined in package 'photobiology' as in 'pavo' wavelengths are assumed to be the same for all spectra stored in an object. So, wavelengths are always stored only once per object. In contrast, 'photobiology' avoids this assumption allowing heterogeneous collections containing member spectra with different wavelengths and lengths. This requires storing Wavelengths for each spectrum, but as spectral classes are derived from 'tbl_df' in many cases redundant copies of wavelength data are avoided by optimizations in 'tibble'.

Warning!

Always check the sanity of the imported or exported data values, as guessing is needed when matching the different classes, and the functions defined here are NOT guaranteed to return valid data without help from the user through optional function arguments.

Examples

# example run only if 'pavo' is available
if (requireNamespace("pavo", quietly = TRUE)) {
  library(pavo)
  data(sicalis, package = "pavo")
  sicalis.mspct <- rspec2mspct(sicalis)
  class(sicalis.mspct)

  data(teal, package = "pavo")
  teal.spct <- rspec2spct(teal)
  class(teal.spct)
  levels(teal.spct[["spct.idx"]])
  angles <- seq(from = 15, to = 75, by = 5) # from teal's documentation
  teal.spct[["angle"]] <- angles[as.numeric(teal.spct[["spct.idx"]])]
  teal.spct
}
#> Object: reflector_spct [4,812 x 4]
#> containing 12 spectra in long form
#> Wavelength range 300-700 nm, step 1 nm 
#> Variables:
#>  w.length: Wavelength [nm]
#>  Rfr: Total spectral reflectance [/1] 
#> --
#> # A tibble: 4,812 × 4
#>    w.length   Rfr spct.idx   angle
#>       <int> <dbl> <fct>      <dbl>
#>  1      300 0.223 Acrecca-01    15
#>  2      301 0.222 Acrecca-01    15
#>  3      302 0.210 Acrecca-01    15
#>  4      303 0.216 Acrecca-01    15
#>  5      304 0.213 Acrecca-01    15
#>  6      305 0.218 Acrecca-01    15
#>  7      306 0.201 Acrecca-01    15
#>  8      307 0.222 Acrecca-01    15
#>  9      308 0.212 Acrecca-01    15
#> 10      309 0.215 Acrecca-01    15
#> # ℹ 4,802 more rows