photobiologyLEDs 0.4.2
User Guide

Pedro J. Aphalo

2016-10-22

knitr::opts_chunk$set(fig.width=8, fig.height=4)
library(photobiology)
library(photobiologyWavebands)
library(photobiologyLEDs)

Introduction

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

Accessing individual spectra

The source_spct member objects in leds.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(leds.mspct)
##  [1] "BS436"           "CB30"            "LED405"         
##  [4] "LED740"          "UV395"           "white"          
##  [7] "XSL365"          "XSL370"          "XSL375"         
## [10] "UVMAX340"        "UVMAX305"        "TY_UV310nm"     
## [13] "white"           "Q36_4000K"       "LZ1_10DB00"     
## [16] "LZ1_10UA00_00U8" "LZ1_10UA00_00U4" "LZ1_10UV00"     
## [19] "LZ1_10R302"      "G_P30R140A1_XT"  "weili430nm"     
## [22] "weili540nm"      "weili665nm"      "weili740nm"     
## [25] "HPR40E_48K30BG"  "NHXRGB090_R"     "NHXRGB090_G"    
## [28] "NHXRGB090_B"     "NHXRGB090"       "B5_436_30D"     
## [31] "FR_OLD"          "HLMB_CB30"       "HLMB_CD31_take2"
## [34] "HLMP_CB31"       "HLMP_CM30"       "HLMP_CM31"      
## [37] "HLMP_DJ32"       "HLMP_DL32"       "LED435_66_60"   
## [40] "LED740_01AV"     "LY5436"          "QDDH66002"      
## [43] "QDDH68002"       "QDDH70002"       "QDDH73502"

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

leds.mspct$UV395
## Object: source_spct [1,425 x 2]
## Wavelength range 250.05 to 899.78 nm, step 0.43 to 0.48 nm 
## Time unit 1s
## Spectral data normalized to 1 at 391.03 nm 
## 
## # A tibble: 1,425 × 2
##    w.length s.e.irrad
##       <dbl>     <dbl>
## 1    250.05         0
## 2    250.52         0
## 3    251.00         0
## 4    251.47         0
## 5    251.95         0
## 6    252.42         0
## 7    252.90         0
## 8    253.37         0
## 9    253.85         0
## 10   254.32         0
## # ... with 1,415 more rows
leds.mspct[["UV395"]]
## Object: source_spct [1,425 x 2]
## Wavelength range 250.05 to 899.78 nm, step 0.43 to 0.48 nm 
## Time unit 1s
## Spectral data normalized to 1 at 391.03 nm 
## 
## # A tibble: 1,425 × 2
##    w.length s.e.irrad
##       <dbl>     <dbl>
## 1    250.05         0
## 2    250.52         0
## 3    251.00         0
## 4    251.47         0
## 5    251.95         0
## 6    252.42         0
## 7    252.90         0
## 8    253.37         0
## 9    253.85         0
## 10   254.32         0
## # ... with 1,415 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.

leds.mspct["UV395"]
## Object: source_mspct [1 x 1]
## --- Member: UV395 ---
## Object: source_spct [1,425 x 2]
## Wavelength range 250.05 to 899.78 nm, step 0.43 to 0.48 nm 
## Time unit 1s
## Spectral data normalized to 1 at 391.03 nm 
## 
## # A tibble: 1,425 × 2
##    w.length s.e.irrad
##       <dbl>     <dbl>
## 1    250.05         0
## 2    250.52         0
## 3    251.00         0
## 4    251.47         0
## 5    251.95         0
## 6    252.42         0
## 7    252.90         0
## 8    253.37         0
## 9    253.85         0
## 10   254.32         0
## # ... with 1,415 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.

leds.mspct[norlux]
## Object: source_mspct [4 x 1]
## --- Member: NHXRGB090_R ---
## Object: source_spct [1,445 x 2]
## Wavelength range 250 to 900 nm, step 0.01 to 0.47 nm 
## Time unit 1s
## Spectral data normalized to 1 at 643.08 nm 
## 
## # A tibble: 1,445 × 2
##    w.length s.e.irrad
## *     <dbl>     <dbl>
## 1    250.00         0
## 2    250.01         0
## 3    250.48         0
## 4    250.95         0
## 5    251.42         0
## 6    251.89         0
## 7    252.36         0
## 8    252.83         0
## 9    253.30         0
## 10   253.77         0
## # ... with 1,435 more rows
## --- Member: NHXRGB090_G ---
## Object: source_spct [1,445 x 2]
## Wavelength range 250 to 900 nm, step 0.01 to 0.47 nm 
## Time unit 1s
## Spectral data normalized to 1 at 515.52 nm 
## 
## # A tibble: 1,445 × 2
##    w.length s.e.irrad
## *     <dbl>     <dbl>
## 1    250.00         0
## 2    250.01         0
## 3    250.48         0
## 4    250.95         0
## 5    251.42         0
## 6    251.89         0
## 7    252.36         0
## 8    252.83         0
## 9    253.30         0
## 10   253.77         0
## # ... with 1,435 more rows
## --- Member: NHXRGB090_B ---
## Object: source_spct [1,445 x 2]
## Wavelength range 250 to 900 nm, step 0.01 to 0.47 nm 
## Time unit 1s
## Spectral data normalized to 1 at 462.59 nm 
## 
## # A tibble: 1,445 × 2
##    w.length s.e.irrad
## *     <dbl>     <dbl>
## 1    250.00         0
## 2    250.01         0
## 3    250.48         0
## 4    250.95         0
## 5    251.42         0
## 6    251.89         0
## 7    252.36         0
## 8    252.83         0
## 9    253.30         0
## 10   253.77         0
## # ... with 1,435 more rows
## --- Member: NHXRGB090 ---
## Object: source_spct [4,335 x 3]
## containing 3 spectra in long form
## Wavelength range 250 to 900 nm, step 0.01 to 0.47 nm 
## Time unit 1s
## Spectral data normalized to 1 at TRUE 
## 
## # A tibble: 4,335 × 3
##    w.length s.e.irrad channel
##       <dbl>     <dbl>  <fctr>
## 1    250.00         0       R
## 2    250.01         0       R
## 3    250.48         0       R
## 4    250.95         0       R
## 5    251.42         0       R
## 6    251.89         0       R
## 7    252.36         0       R
## 8    252.83         0       R
## 9    253.30         0       R
## 10   253.77         0       R
## # ... with 4,325 more rows
## 
## --- END ---

And below we use a computed one. In this case we extract the member spectra with names containing the string “osram”.

leds.mspct[grep("QDDH", names(leds.mspct))]
## Object: source_mspct [4 x 1]
## --- Member: QDDH66002 ---
## Object: source_spct [1,445 x 2]
## Wavelength range 250 to 900 nm, step 0.01 to 0.47 nm 
## Label: LED, type  QDDH66002
## Measured on 2016-07-05 10:00:00 UTC
## Time unit 1s
## Spectral data normalized to 1 at 652.01 nm 
## 
## # A tibble: 1,445 × 2
##    w.length   s.e.irrad
## *     <dbl>       <dbl>
## 1    250.00 0.000000000
## 2    250.01 0.000000000
## 3    250.48 0.002665560
## 4    250.95 0.001561842
## 5    251.42 0.000000000
## 6    251.89 0.000000000
## 7    252.36 0.010471852
## 8    252.83 0.000000000
## 9    253.30 0.000000000
## 10   253.77 0.000000000
## # ... with 1,435 more rows
## --- Member: QDDH68002 ---
## Object: source_spct [1,445 x 2]
## Wavelength range 250 to 900 nm, step 0.01 to 0.47 nm 
## Label: LED, type  QDDH68002
## Measured on 2016-07-05 10:00:00 UTC
## Time unit 1s
## Spectral data normalized to 1 at 673.4 nm 
## 
## # A tibble: 1,445 × 2
##    w.length   s.e.irrad
## *     <dbl>       <dbl>
## 1    250.00 0.000000000
## 2    250.01 0.000000000
## 3    250.48 0.000000000
## 4    250.95 0.006025027
## 5    251.42 0.000000000
## 6    251.89 0.000000000
## 7    252.36 0.003916701
## 8    252.83 0.000000000
## 9    253.30 0.000000000
## 10   253.77 0.000000000
## # ... with 1,435 more rows
## --- Member: QDDH70002 ---
## Object: source_spct [1,445 x 2]
## Wavelength range 250 to 900 nm, step 0.01 to 0.47 nm 
## Label: LED, type  QDDH70002
## Measured on 2016-07-05 10:00:00 UTC
## Time unit 1s
## Spectral data normalized to 1 at 707.13 nm 
## 
## # A tibble: 1,445 × 2
##    w.length s.e.irrad
## *     <dbl>     <dbl>
## 1    250.00         0
## 2    250.01         0
## 3    250.48         0
## 4    250.95         0
## 5    251.42         0
## 6    251.89         0
## 7    252.36         0
## 8    252.83         0
## 9    253.30         0
## 10   253.77         0
## # ... with 1,435 more rows
## --- Member: QDDH73502 ---
## Object: source_spct [1,445 x 2]
## Wavelength range 250 to 900 nm, step 0.01 to 0.47 nm 
## Label: LED, type  QDDH73502
## Measured on 2016-07-05 10:00:00 UTC
## Time unit 1s
## Spectral data normalized to 1 at 746.42 nm 
## 
## # A tibble: 1,445 × 2
##    w.length   s.e.irrad
## *     <dbl>       <dbl>
## 1    250.00 0.008072251
## 2    250.01 0.008247735
## 3    250.48 0.000000000
## 4    250.95 0.000000000
## 5    251.42 0.000000000
## 6    251.89 0.000000000
## 7    252.36 0.000000000
## 8    252.83 0.000000000
## 9    253.30 0.000000000
## 10   253.77 0.000000000
## # ... with 1,435 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 315 to 400 nm.

my.spct <- fscale(leds.mspct$UV395,
                  range = c(315, 400),
                  e_irrad,
                  target = 10
                  )
e_irrad(my.spct, waveband(c(315,400)))
## Warning in irrad_spct(spct, w.band = w.band, unit.out = "energy", quantity
## = quantity, : Summarized spectral data have been rescaled
##  range.315.400 
##             10 
## 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] 0.7190004
## 
## $f
## [1] "a user supplied R function"
## 
## $range
## [1] 315 400
## 
## $target
## [1] 10
setScaled(my.spct)
getScaled(my.spct)
## [1] FALSE

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.UV395 <- leds.mspct$UV395
setNormalized(my.UV395)
e_irrad(my.UV395)
##    Total 
## 16.10323 
## 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(leds.mspct$UV395, UVB(), UVA())
##  UVB.ISO: UVA.ISO(q:q) 
##                      0 
## attr(,"radiation.unit")
## [1] "q:q ratio"

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(leds.mspct$UV395))
##   w.length s.e.irrad
## 1   250.05         0
## 2   250.52         0
## 3   251.00         0
## 4   251.47         0
## 5   251.95         0
## 6   252.42         0

Of course attach and with also work as expected.

attach(leds.mspct)
q_ratio(UV395, UVB(), UVA())
##  UVB.ISO: UVA.ISO(q:q) 
##                      0 
## attr(,"radiation.unit")
## [1] "q:q ratio"
detach(leds.mspct)
attach(leds.mspct)
with(UV395, max(w.length))
## [1] 899.78
detach(leds.mspct)
with(leds.mspct, q_ratio(UV395, UVB(), UVA()))
##  UVB.ISO: UVA.ISO(q:q) 
##                      0 
## attr(,"radiation.unit")
## [1] "q:q ratio"