Skip to contents

Convert spectral objects (xxxx_spct, xxxx_mspct) as defined in package 'photobiology' into colorSpec objects preserving as much information as possible.

Usage

mspct2colorSpec(x, spct.data.var = NULL, multiplier = 1, ...)

spct2colorSpec(x, spct.data.var = NULL, multiplier = 1, ...)

chroma_spct2colorSpec(x, spct.data.var = NULL, multiplier = 1, ...)

# S3 method for class 'generic_mspct'
as.colorSpec(x, spct.data.var = NULL, multiplier = 1, ...)

# S3 method for class 'generic_spct'
as.colorSpec(x, spct.data.var = NULL, multiplier = 1, ...)

# S3 method for class 'chroma_spct'
as.colorSpec(x, spct.data.var = NULL, multiplier = 1, ...)

Arguments

x

R object

spct.data.var

character The name of the variable to read spectral data from.

multiplier

numeric A multiplier to be applied to the 'spc' data to do unit or scale conversion.

...

currently ignored.

Methods (by class)

  • as.colorSpec(generic_spct):

  • as.colorSpec(chroma_spct):

Note

Objects of class colorSpec::colorSpec do not contain metadata or class data from which the units of expression could be obtained. When using this function the user needs to use parameter multiplier to convert the data to what is expected by the object constructors defined in package 'photobiology' but should only rarely need to use parameter spct.data.var to select the quantity.

colorSpec::colorSpec objects may use memory more efficiently than spectral objects of the classes for collections of spectra defined in package 'photobiology' as wavelengths are assumed to be the same for all member spectra, and stored only once while this assumption is not made for collections of spectra, allowing different wavelengths and lengths for the component spectra. Wavelengths are stored for each spectrum, but as spectral classes are derived from 'tbl_df' in many cases no redundant copies of wavelength data will be made in memory in spite of the more flexible semantics of the objects.

Warning!

Always check the sanity of the returned 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


if (requireNamespace("colorSpec", quietly = TRUE)) {
  library(colorSpec)
  as.colorSpec(polyester.spct)
  as.colorSpec(sun.spct)
  as.colorSpec(filter_mspct(list(polyester.spct, yellow_gel.spct)))
}
#> Attaching colorSpec.  Version: 1.8-0.  Author: Glenn Davis [aut, cre].  Built: R 4.5.0; ; 2025-06-10 23:50:49 UTC; windows
#> 
#> Attaching package: 'colorSpec'
#> The following object is masked from 'package:photobiology':
#> 
#>     normalize
#> Spectra interpolated and trimmed as wavelengths differed.
#> 
#> colorSpec object.   The organization is 'matrix'.  Object size is 29128 bytes.
#> the object describes 2 transparent materials, and the quantity is 'transmittance'.
#> Wavelength range: 240 to 800 nm.  Step size is 0.5 nm.
#> 
#> 2 spectra
#> 1121 data points / spectrum
#> 
#>   Material   Min       Max LambdaMax Integral
#> 1   spct_1 3e-03 0.9254286     474.5 434.3524
#> 2   spct_2 1e-05 0.9017857     768.0 260.0849