User Guide"

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

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.

The data

The spectral data have been acquired mostly with one instrument, an array spectrometer. However, some spectra haver been measured with another spectrometers that has lower wavelength resolution. This difference in resolution and slit function can give, for the same LED, measured peaks of slightly different width. This is an inevitable artefact of spectral measurements, but as LEDs have relatively wide peaks the distortion is small. With well calibrated spectrometers, the area under a peak should not be affected by the difference in wavelength resolution.

All the spectral data in this package are stored in a single R object, a collection of spectra of class source_spct. Individual or subsets of spectra can be retrieved by name. The package includes also several character vectors of names, each one containing names for LEDs of a given color or from a given manufacturer. These are listed in the help index for the package. The names used are in most cases the codes used by the manufacturers for the given type. Any dashes in these codes have been replaced by underscores.

blue_leds
led_engin

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)

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

leds.mspct$UV395
leds.mspct[["UV395"]]

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

leds.mspct["UV395"]

Of course, with this syntax it is possible to use a vector of member names.

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]

And below we use a computed one. In this case we extract the member spectra with names containing the string "QDDH".

leds.mspct[grep("QDDH", names(leds.mspct))]

Querying metadata

If package 'photobiology' is loaded then the specialised print() method will be used and a summary of the metadata will be included in the header of the printout.

leds.mspct$LZ1_10R302
getWhatMeasured(leds.mspct$LZ1_10R302)
getWhenMeasured(leds.mspct$LZ1_10R302)
getInstrDesc(leds.mspct$LZ1_10R302)
getInstrSettings(leds.mspct$LZ1_10R302)
is_normalized(leds.mspct$LZ1_10R302)
leds.mspct$UVMAX305
is_normalized(leds.mspct$UVMAX305)

Calculating summaries from the normalized data

Many of 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 when the measuring conditions used are not well known, and in many cases not well characterized (e.g. distance from LED to cosine diffuser or exact alignment of the spectrometer input optics with respect to light source was not recorded or attempted at the time of measurement).

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 10 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)))

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 spectrum has been scaled.

getScaled(my.spct)
setScaled(my.spct)
getScaled(my.spct)

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)

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

q_ratio(leds.mspct$UV395, UVB(), UVA())

Plotting

Spectra can be plotted in the same ways as other data stored in data frames, using base R graphics, package 'lattice' or 'ggplot2'. However, another package in our suite, 'ggspectra', built as an extension to 'ggplot2' makes plotting spectra even easier.

plot() methods use the metadata in the objects to set labels and decorations, as well as automatically setting the mapping of the x and y aesthetics.

plot(leds.mspct$LZ1_10R302)

Package 'ggspectra' also defines specializations of method ggplot() for spectra.

ggplot(leds.mspct$LZ1_10R302) +
  geom_line()

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 rather compatible reimplementation of data.frame the data can be used very easily with any R function.

head(as.data.frame(leds.mspct$UV395))

Of course attach and with also work as expected.

attach(leds.mspct)
q_ratio(UV395, UVB(), UVA())
detach(leds.mspct)
attach(leds.mspct)
with(UV395, max(w.length))
detach(leds.mspct)
with(leds.mspct, q_ratio(UV395, UVB(), UVA()))

The R4Photobiology suite

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'.



Try the photobiologyLEDs package in your browser

Any scripts or data that you put into this service are public.

photobiologyLEDs documentation built on May 2, 2019, 2:06 a.m.