User Guide

Package ‘photobiologyLamps’ 0.4.3

Pedro J. Aphalo

2019-06-14

Introduction

This package, is a data only package, part of a suite, which has package ‘photobiology’ at its core. Please visit (http://www.r4photobiology.info/) for more details. For more details on plotting spectra, please consult the documentation for package ‘ggspectra’, and for information on the calculation of summaries and maths operations between spectra, please, consult the documentation for package ‘photobiology’.

library(photobiology)
library(photobiologyWavebands)
library(photobiologyLamps)
library(ggplot2)
library(ggspectra)

In this brief User Guide we describe how to re-scale the normalized spectra, and how to access individual spectra or subsets of spectra.

Spectra in the package are contained in three collections: lamps.mspct contains spectral data for various types of lamps emiiting a fixed color of light; ledsavers.mspct contains spectral data for a LED bulb with four color channels allowing it to output 16 different colors of light; qp_uvb313_temp.mspct contains spectral data for UV lamps under seven different temperatures. In addition qp_uvb313_temp.spct contains the same data in a single spectral object.

In addtion to the objects containing the data itself, several character vectors of names of spectra are provide to facilitate the retrieval of subsets of spectra.

Accessing individual spectra

The source_spct member objects in lamps.mspct can be accessed through their names or through a numeric index. As the numeric indexes are likely to change with updates to the package, their use is discouraged. Names as character strings should be used instead. The names are listed in the documentation and also available through the “Data Catalogue” vignette. They can also be listed with method names().

names(lamps.mspct)
##  [1] "incandescent.60w"                "osram.36w.25"                   
##  [3] "osram.hqit.400w"                 "osram.super.vialox"             
##  [5] "philips.pls11w.827"              "philips.tld36w.15"              
##  [7] "philips.tld36w.18"               "philips.tld36w.83"              
##  [9] "philips.tld36w.865"              "philips.tld36w.89"              
## [11] "philips.tld36w.92"               "philips.tll36w.950"             
## [13] "sylvania.215w.vho"               "qpanel.uvb313"                  
## [15] "qpanel.uva340"                   "philips.tl12.mc"                
## [17] "philips.tl01"                    "philips.tl12"                   
## [19] "airam.cf.15w.2700k"              "airam.led.11w.4000k"            
## [21] "airam.led.oiva.9w.3000k"         "airam.spiraali"                 
## [23] "amaran.al.m9"                    "convoy.uv.flashlight"           
## [25] "cree.uv.flashlight"              "germicidal"                     
## [27] "godox.ad200.h200"                "godox.ad200.h200j.adft200"      
## [29] "godox.ad200.h200j.adft200.ir"    "godox.ad200.h200j.ftsts40w"     
## [31] "godox.ad200.h200r"               "osram.classic.20w"              
## [33] "osram.conc.spot.60w"             "osram.l36w.840"                 
## [35] "osram.led.10w.2700k.classicstar" "osram.led.8w.2700k"             
## [37] "philips.led.t8.10w.840"          "philips.tl5.35w.830he"          
## [39] "philips.tld.36w.18"              "pirkka.halogen.53w"             
## [41] "sunwayfoto.fl96.3000k"           "sunwayfoto.fl96.5500k"          
## [43] "toshiba.led.9.5w.2700k"          "v.light.led.2w.6000k"           
## [45] "valoya.b50.ap67"                 "fluence.AnthoSpec"              
## [47] "fluence.PhysioSpecGreenhouse"

We can use a character string as index to extract an individual source_spct object.

lamps.mspct$incandescent.60w
## Object: source_spct [601 x 2]
## Wavelength range 300 to 900 nm, step 1 nm 
## Label: File: Incandescent.60W.PRN 
## Measured on 0000-08-18 13:47:11 UTC 
## Time unit 1s
## Spectral data normalized to 1 at 900 nm 
## 
## # A tibble: 601 x 2
##    w.length s.e.irrad
##       <dbl>     <dbl>
##  1      300  0.000665
##  2      301  0.000325
##  3      302  0.000956
##  4      303  0.000702
##  5      304  0.000306
##  6      305  0.000825
##  7      306  0.00103 
##  8      307  0.000361
##  9      308  0.000497
## 10      309  0.000627
## # ... with 591 more rows
lamps.mspct[["incandescent.60w"]]
## Object: source_spct [601 x 2]
## Wavelength range 300 to 900 nm, step 1 nm 
## Label: File: Incandescent.60W.PRN 
## Measured on 0000-08-18 13:47:11 UTC 
## Time unit 1s
## Spectral data normalized to 1 at 900 nm 
## 
## # A tibble: 601 x 2
##    w.length s.e.irrad
##       <dbl>     <dbl>
##  1      300  0.000665
##  2      301  0.000325
##  3      302  0.000956
##  4      303  0.000702
##  5      304  0.000306
##  6      305  0.000825
##  7      306  0.00103 
##  8      307  0.000361
##  9      308  0.000497
## 10      309  0.000627
## # ... with 591 more rows

Be aware that according to R’s rules, using single square brackets will return a source_mspct object possibly of length one. This statement is not equivalent to the one in the chunk immediately above.

lamps.mspct["incandescent.60w"]
## Object: source_mspct [1 x 1]
## --- Member: incandescent.60w ---
## Object: source_spct [601 x 2]
## Wavelength range 300 to 900 nm, step 1 nm 
## Label: File: Incandescent.60W.PRN 
## Measured on 0000-08-18 13:47:11 UTC 
## Time unit 1s
## Spectral data normalized to 1 at 900 nm 
## 
## # A tibble: 601 x 2
##    w.length s.e.irrad
##       <dbl>     <dbl>
##  1      300  0.000665
##  2      301  0.000325
##  3      302  0.000956
##  4      303  0.000702
##  5      304  0.000306
##  6      305  0.000825
##  7      306  0.00103 
##  8      307  0.000361
##  9      308  0.000497
## 10      309  0.000627
## # ... with 591 more rows
## 
## --- END ---

Accessing subsets of spectra

We can subset the source_mspct object by indexing with vectors of character strings. The package provides some predefined ones, and users can easily define their own, either as constants or through computation. Here we use a vector defined by the package.

lamps.mspct[toshiba_lamps]
## Object: source_mspct [1 x 1]
## --- Member: toshiba.led.9.5w.2700k ---
## Object: source_spct [1,421 x 2]
## Wavelength range 251.16 to 898.81 nm, step 0.43 to 0.48 nm 
## Label: Toshiba 9.5W 2700K 806 lm E27 
## Measured on 2018-02-12 09:08:23 UTC 
## Time unit 1s
## Spectral data normalized to 1 at 607.26 nm 
## 
## # A tibble: 1,421 x 2
##    w.length s.e.irrad
##  *    <dbl>     <dbl>
##  1     251. 0        
##  2     252. 0.000143 
##  3     252. 0.0000905
##  4     253. 0.000843 
##  5     253. 0.000690 
##  6     254. 0.00103  
##  7     254  0.000695 
##  8     254. 0.000367 
##  9     255. 0.000765 
## 10     255. 0.000892 
## # ... with 1,411 more rows
## 
## --- END ---

And below we use a computed one. In this case we extract the member spectra with names containing the string “toshiba”. More generaly one can search for matching names within the collection of spectra.

lamps.mspct[grep("toshiba", names(lamps.mspct))]
## Object: source_mspct [1 x 1]
## --- Member: toshiba.led.9.5w.2700k ---
## Object: source_spct [1,421 x 2]
## Wavelength range 251.16 to 898.81 nm, step 0.43 to 0.48 nm 
## Label: Toshiba 9.5W 2700K 806 lm E27 
## Measured on 2018-02-12 09:08:23 UTC 
## Time unit 1s
## Spectral data normalized to 1 at 607.26 nm 
## 
## # A tibble: 1,421 x 2
##    w.length s.e.irrad
##  *    <dbl>     <dbl>
##  1     251. 0        
##  2     252. 0.000143 
##  3     252. 0.0000905
##  4     253. 0.000843 
##  5     253. 0.000690 
##  6     254. 0.00103  
##  7     254  0.000695 
##  8     254. 0.000367 
##  9     255. 0.000765 
## 10     255. 0.000892 
## # ... with 1,411 more rows
## 
## --- END ---

Set algebra operations can be used with the indexing vectors as each vector describes a single property: color, brand, type, etc.

lamps.mspct[intersect(philips_lamps, red_lamps)]
## Object: source_mspct [1 x 1]
## --- Member: philips.tld36w.15 ---
## Object: source_spct [601 x 2]
## Wavelength range 300 to 900 nm, step 1 nm 
## Label: File: Philips.TLD36W.15.PRN 
## Measured on 0000-08-23 10:16:11 UTC 
## Time unit 1s
## Spectral data normalized to 1 at 660 nm 
## 
## # A tibble: 601 x 2
##    w.length s.e.irrad
##       <dbl>     <dbl>
##  1      300  0.000196
##  2      301  0.000959
##  3      302  0.000752
##  4      303  0.00110 
##  5      304  0.00126 
##  6      305  0.000885
##  7      306  0.000521
##  8      307  0.00153 
##  9      308  0.000167
## 10      309  0.000493
## # ... with 591 more rows
## 
## --- END ---

Calculating summaries from the normalized data

The spectra are normalized, and consequently, several summaries expressed in absolute units are undefined, and trigger errors. Summaries like ratios which are not affected by normalization are allowed and valid. The data have been normalized as the measuring conditions used are not all the same, and in many cases not well characterized (e.g. distance to nearby reflecting walls, or exact alignment of the spectrometer input optics with respect to light sources).

What we will do in this section is to rescale the spectral data so that after conversion a given target value for a summary quantity will be true. As an example, we will rescale one spectrum so that it yields an energy irradiance of 100 W m-2 for the range 400 to 700 nm.

my.spct <- fscale(lamps.mspct$incandescent.60w,
                  range = c(400, 700),
                  e_irrad,
                  target = 100
                  )
e_irrad(my.spct, waveband(c(400,700)))
## Warning in irrad_spct(spct, w.band = w.band, unit.out = "energy",
## scale.factor = scale.factor, : Summarized spectral data have been rescaled
##  range.400.700 
##            100 
## attr(,"time.unit")
## [1] "second"
## attr(,"radiation.unit")
## [1] "energy irradiance total"

If we want to treat the rescaled spectral data, as if they were true readings with no scaling we can reset the attribute with method setScaled(). With method getScaled() we can test if a spectrun has been scaled.

getScaled(my.spct)
## $multiplier
## [1] 1.293194
## 
## $f
## [1] "a user supplied R function"
## 
## $range
## [1] 400 700
## 
## $target
## [1] 100

If for some obscure reason we want to simply “pretend” that the spectral data have not been normalized, we can permanently override the attribute on a copy of the data. Most of the time this is a very bad idea!

my.lamp <- lamps.mspct$incandescent.60w
setNormalized(my.lamp)
e_irrad(my.lamp)
##    Total 
## 247.1079 
## attr(,"time.unit")
## [1] "second"
## attr(,"radiation.unit")
## [1] "energy irradiance total"

As mentioned above, ratios can be calculated directly as they are not affected by normalization.

q_ratio(lamps.mspct$incandescent.60w, Red("Smith10"), Far_red("Smith10"))
##  Red.Smith10: FarRed.Smith10(q:q) 
##                         0.6606633 
## attr(,"radiation.unit")
## [1] "q:q ratio"

Plotting the spectra

Using plot() methods for spectra defined in package ‘ggspectra’ annotated plotting is automatic. The defaults can be easily changed, please see the documentation in package ‘ggspectra’.

plot(lamps.mspct$osram.led.8w.2700k)

plot(ledsavers.mspct$purple)

Using the ggplot() method for spectra from package ‘ggspectra’ plus geometries and statistics from package ‘ggplot2’ we gain additional control on the design.

ggplot(ledsavers.mspct$purple) +
  geom_line(linetype = "dashed") +
  theme_classic()

Using the data in other contexts

As source_spct is a class derived from list, and source_spct is derived from tibble::tible which is a compatible reimplementation of data.frame the data can be used very easily with any R function.

head(as.data.frame(lamps.mspct$incandescent.60w))
##   w.length    s.e.irrad
## 1      300 0.0006650365
## 2      301 0.0003254116
## 3      302 0.0009560352
## 4      303 0.0007024644
## 5      304 0.0003059931
## 6      305 0.0008253680

Of course attach and with also work as expected.

attach(lamps.mspct)
q_ratio(incandescent.60w, Blue(), Red())
##  Blue.ISO: Red.ISO(q:q) 
##              0.03251342 
## attr(,"radiation.unit")
## [1] "q:q ratio"
detach(lamps.mspct)
attach(lamps.mspct)
with(incandescent.60w, max(w.length))
## [1] 900
detach(lamps.mspct)
with(lamps.mspct, q_ratio(incandescent.60w, Blue(), Red()))
##  Blue.ISO: Red.ISO(q:q) 
##              0.03251342 
## attr(,"radiation.unit")
## [1] "q:q ratio"