Skip to contents

Convert spectral objects (xxxx_spct, xxxx_mspct) as defined in package 'photobiology' into fda.usc::fdata objects, preserving as much information as possible. As fdata objects can contain other kinds of data, the reverse conversion is supported (experimentally) and mainly for 'fdata' objects returned by the functional data analysis methods from package fda.usc to spectral data previosuly exported in the opposite direction.

Usage

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

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

fdata2spct(x, multiplier = 1, member.class = NULL, drop.idx = FALSE, ...)

fdata2mspct(x, multiplier = 1, member.class = NULL, drop.idx = FALSE, ...)

Arguments

x

generic_mspct or generic_spct object or an object belonging to a derived class, or an object of class 'fdata' depending on the function.

spct.data.var

character The name of the column containing data to export. If NULL the first spectral data column found is used.

multiplier

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

...

possibly additional named arguments passed to object constructors.

member.class

character Name of the class of the spectrum or of the members of the collection of spectra.

drop.idx

logical Flag indicating whether to drop or keep idx.var in the collection members.

Warning!

When converting multiple spectra, all the spectra to be included in the fdata object must share the same wavelength values. Spectra that do not fulfil this condition will be skipped. The data variable needs also to be present in all individual spectra as no conversions are applied automatically by this function. If a different name, indicating a different quantity or a different base of expression is encountered, the affected spectrum is skipped with a warning.

Examples

if (requireNamespace("fda.usc", quietly = TRUE)) {
# from spectra to fdata
  sun.fdata <- spct2fdata(sun.spct)
  str(sun.fdata)
  polyester.fdata <- spct2fdata(polyester.spct)
  str(polyester.fdata)
# from fdata to spectra
  fdata2spct(sun.fdata)
  fdata2spct(sun.fdata, drop.idx = TRUE)
  fdata2spct(polyester.fdata, drop.idx = TRUE)
}
#> Class 'fdata'  hidden list of 4
#>  $ data    : num [1, 1:522] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr "spct_1"
#>   .. ..$ : NULL
#>  $ argvals : num [1:522] 280 281 282 283 284 ...
#>  $ rangeval: num [1:2] 280 800
#>  $ names   :List of 3
#>   ..$ main: chr ""
#>   ..$ xlab: chr "w.length"
#>   ..$ ylab: chr "s.e.irrad"
#>  - attr(*, "comment")= chr "Converted from object of class \"source_mspct\""
#> Class 'fdata'  hidden list of 4
#>  $ data    : num [1, 1:454] 0.00482 0.00464 0.00446 0.00414 0.004 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr "spct_1"
#>   .. ..$ : NULL
#>  $ argvals : int [1:454] 240 241 242 244 246 248 252 256 258 259 ...
#>  $ rangeval: int [1:2] 240 800
#>  $ names   :List of 3
#>   ..$ main: chr ""
#>   ..$ xlab: chr "w.length"
#>   ..$ ylab: chr "Tfr"
#>  - attr(*, "comment")= chr "Converted from object of class \"filter_mspct\""
#> Object: filter_spct [454 x 2]
#> Wavelength range 240-800 nm, step 1-4 nm 
#> Label:  
#> Rfr (/1): NA, thickness (mm): NA, attenuation mode: NA.
#> Variables:
#>  w.length: Wavelength [nm]
#>  Tfr: Total spectral transmittance [/1] 
#> --
#> # A tibble: 454 × 2
#>    w.length     Tfr
#>       <int>   <dbl>
#>  1      240 0.00482
#>  2      241 0.00464
#>  3      242 0.00446
#>  4      244 0.00414
#>  5      246 0.004  
#>  6      248 0.004  
#>  7      252 0.00386
#>  8      256 0.00329
#>  9      258 0.003  
#> 10      259 0.003  
#> # ℹ 444 more rows