Author: Pedro J. Aphalo
Date: 2025-09-26

# User Guide: 1 Data and their use

### Package ‘photobiologyLEDs’ 0.5.3

#### Pedro J. Aphalo

#### 2025-09-26

## Introduction

This package, is a data only package, part of a suite, which has package ‘photobiology’ at its core. Please visit (https://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’.

As packages ‘photobiologyWavebands’ and ‘ggspectra’ are only suggested, in this vignette they are loaded and used conditionally on its availability.

    library(photobiology)
    library(photobiologyLEDs)
    # Are the packages used in examples installed?
    eval_bands <- requireNamespace("photobiologyWavebands", quietly = TRUE)
    if (eval_bands) library(photobiologyWavebands)
    eval_plots <- eval_bands && requireNamespace("ggspectra", quietly = TRUE)
    if (eval_plots) 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.

## The data

The spectral data have been acquired mostly with one instrument, an array spectrometer. However, some spectra have been measured with another spectrometer 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.

The spectral data in this package are stored in three R objects, each of them a collection of spectra of class `source_spct`. Most of the spectra are in data object `leds.mspct`. Data object `COB_reflectors.mspct` contains spectra for a single COB LED combined with different reflectors while data object `COB_dimming.mspct` contains a collection of spectra from the same LED when driven at different currents.

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 colour, from a given manufacturer or intended mainly for a specific use. 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

    ##  [1] "Agilent_HLMB_CB30"             "Agilent_HLMB_CD31"
    ##  [3] "Agilent_HLMP_CB31"             "Epileds_3W_495nm"
    ##  [5] "Epileds_3W_460nm"              "Epileds_3W_470nm"
    ##  [7] "HueyJann_HPR40E_48K30BG"       "HueyJann_HPR40E_48K30BI"
    ##  [9] "LedEngin_LZ1_10DB00_460nm"     "LedEngin_LZ7_N4M100_ch_C_Blue"
    ## [11] "LedEngin_LZ7_N4M100_ch_G_Cyan" "Norlux_NHXRGB090_B"
    ## [13] "Roithner_CB30"                 "Weili_3W.nominal.500nm"

    LedEngin_leds

    ##  [1] "LedEngin_LZ1_10DB00_460nm"
    ##  [2] "LedEngin_LZ1_10R302_740nm"
    ##  [3] "LedEngin_LZ1_10R602_850nm"
    ##  [4] "LedEngin_LZ1_10UB00_00U4_385nm"
    ##  [5] "LedEngin_LZ1_10UB00_00U8_405nm"
    ##  [6] "LedEngin_LZ1_10UV00_365nm"
    ##  [7] "LedEngin_LZ4_40R208_660nm"
    ##  [8] "LedEngin_LZ7_N4M100_ch_A_Green"
    ##  [9] "LedEngin_LZ7_N4M100_ch_B_Red"
    ## [10] "LedEngin_LZ7_N4M100_ch_C_Blue"
    ## [11] "LedEngin_LZ7_N4M100_ch_D_UV"
    ## [12] "LedEngin_LZ7_N4M100_ch_E_CW_Cool_white"
    ## [13] "LedEngin_LZ7_N4M100_ch_F_PC_Amber"
    ## [14] "LedEngin_LZ7_N4M100_ch_G_Cyan"

## 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(COB_reflectors.mspct)

    ## [1] "Rfl.15deg" "Rfl.25deg" "Rfl.35deg" "Rfl.None"

    names(COB_dimming.mspct)

    ## [1] "CC.350mA" "CC.344mA" "CC.266mA" "CC.140mA" "CC.070mA" "CC.035mA" "CC.017mA"
    ## [8] "CC.011mA"

    names(leds.mspct)

    ##  [1] "Agilent_HLMB_CB30"
    ##  [2] "Agilent_HLMB_CD31"
    ##  [3] "Agilent_HLMP_CB31"
    ##  [4] "Agilent_HLMP_CM30"
    ##  [5] "Agilent_HLMP_CM31"
    ##  [6] "Agilent_HLMP_DJ32"
    ##  [7] "Agilent_HLMP_DL32"
    ##  [8] "Bridgelux_3W_455nm"
    ##  [9] "Bridgelux_BXRE_50S2001_c_73"
    ## [10] "CREE_XPE_480nm"
    ## [11] "Epileds_3W_410nm"
    ## [12] "Epileds_3W_420nm"
    ## [13] "Epileds_3W_430nm"
    ## [14] "Epileds_3W_445nm"
    ## [15] "Epileds_3W_460nm"
    ## [16] "Epileds_3W_470nm"
    ## [17] "Epileds_3W_495nm"
    ## [18] "Epileds_3W_520nm"
    ## [19] "Epileds_3W_560nm"
    ## [20] "Epileds_3W_590nm"
    ## [21] "Epileds_3W_600nm"
    ## [22] "Epileds_3W_620nm"
    ## [23] "Epistar_3W_Plant_Grow_LED"
    ## [24] "HueyJann_HPR40E_48K30BG"
    ## [25] "HueyJann_HPR40E_48K30BI"
    ## [26] "LCFOCUS_LC_10FS504_G24"
    ## [27] "LCFOCUS_LC_10FSCOB1411_2700"
    ## [28] "LCFOCUS_LC_10FSCOB1411_6000"
    ## [29] "LCFOCUS_LC_10FSCOB1917_4000"
    ## [30] "LedEngin_LZ1_10DB00_460nm"
    ## [31] "LedEngin_LZ1_10R302_740nm"
    ## [32] "LedEngin_LZ1_10R602_850nm"
    ## [33] "LedEngin_LZ1_10UB00_00U4_385nm"
    ## [34] "LedEngin_LZ1_10UB00_00U8_405nm"
    ## [35] "LedEngin_LZ1_10UV00_365nm"
    ## [36] "LedEngin_LZ4_40R208_660nm"
    ## [37] "LedEngin_LZ7_N4M100_ch_A_Green"
    ## [38] "LedEngin_LZ7_N4M100_ch_B_Red"
    ## [39] "LedEngin_LZ7_N4M100_ch_C_Blue"
    ## [40] "LedEngin_LZ7_N4M100_ch_D_UV"
    ## [41] "LedEngin_LZ7_N4M100_ch_E_CW_Cool_white"
    ## [42] "LedEngin_LZ7_N4M100_ch_F_PC_Amber"
    ## [43] "LedEngin_LZ7_N4M100_ch_G_Cyan"
    ## [44] "Ledguhon_10WBVG14G24_Y6C_T4"
    ## [45] "Ledguhon_10WBVGIR14G24_Y6C_T4"
    ## [46] "Luminus_CXM_14_HS_12_36_AC30"
    ## [47] "Marktech_MTSM340UV_F5120_340nm"
    ## [48] "Nichia_NF2W757GT_F1_sm505_Rfc00"
    ## [49] "Nichia_NFCWL036B_V3_Rfcb0"
    ## [50] "Nichia_NFSL757GT_Rsp0a"
    ## [51] "Nichia_NFSW757G_Rsp0a"
    ## [52] "Nichia_NFSW757G_V3_Rs060"
    ## [53] "Nichia_NS6L183AT_H1_sw"
    ## [54] "Nichia_NVSU119C_U385"
    ## [55] "Nichia_NVSU233B_U365"
    ## [56] "Nichia_unknown_757"
    ## [57] "Norlux_NHXRGB090_B"
    ## [58] "Norlux_NHXRGB090_G"
    ## [59] "Norlux_NHXRGB090_R"
    ## [60] "Osram_GF_CSHPM2.24_2T4T_1"
    ## [61] "Osram_GW_CSSRM3.HW"
    ## [62] "Osram_LY5436"
    ## [63] "QuantumDevices_QDDH66002"
    ## [64] "QuantumDevices_QDDH68002"
    ## [65] "QuantumDevices_QDDH70002"
    ## [66] "QuantumDevices_QDDH73502"
    ## [67] "Roithner_BS436"
    ## [68] "Roithner_CB30"
    ## [69] "Roithner_DUV289_SD353EL"
    ## [70] "Roithner_DUV310_SD353EL"
    ## [71] "Roithner_DUV325_SD353EL"
    ## [72] "Roithner_DUV340_SD353EL"
    ## [73] "Roithner_LED405"
    ## [74] "Roithner_LED740"
    ## [75] "Roithner_SMB1N_BB450"
    ## [76] "Roithner_UV395"
    ## [77] "Roithner_UVMAX305"
    ## [78] "Roithner_UVMAX340"
    ## [79] "Roithner_XSL365"
    ## [80] "Roithner_XSL370"
    ## [81] "Roithner_XSL375"
    ## [82] "Samsung_SPHWHAHDND25YZT3D3"
    ## [83] "SeoulSemicon_S4SM_1564359736_0B500H3S_00001"
    ## [84] "SeoulSemicon_S4SM_1564509736_0B500H3S_00001"
    ## [85] "SeoulSemicon_STW9C2SB_S"
    ## [86] "TaoYuan_LED_310nm"
    ## [87] "Weili_3W.nominal.500nm"
    ## [88] "Weili_3W.nominal.525nm"
    ## [89] "Weili_3W.nominal.550nm"
    ## [90] "Weili_3W.nominal.555nm"

    names(led_arrays.mspct)

    ## [1] "LedEngin_LZ7_N4M100"            "Norlux_NHXRGB090"
    ## [3] "Weili_120W.array.12ch.custom.A" "Weili_120W.array.12ch.custom.B"

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

    leds.mspct$Roithner_UV395

    ## Object: source_spct [1,369 x 2]
    ## Wavelength range 250.05-899.78 nm, step 0.43-3.72 nm
    ## Label: LED type UV395 from Roithner-Laser
    ## Spectral data in s.e.irrad normalized to 1 at 391 nm (max in 250.05-899.78 nm)
    ## Variables:
    ##  w.length: Wavelength [nm]
    ##  s.e.irrad: Spectral energy irradiance [normalized]
    ## --
    ## # A tibble: 1,369 × 2
    ##    w.length s.e.irrad
    ##       <dbl>     <dbl>
    ##  1     250.         0
    ##  2     253.         0
    ##  3     254.         0
    ##  4     254.         0
    ##  5     255.         0
    ##  6     255.         0
    ##  7     256.         0
    ##  8     256.         0
    ##  9     257.         0
    ## 10     257.         0
    ## # ℹ 1,359 more rows

    leds.mspct[["Roithner_UV395"]]

    ## Object: source_spct [1,369 x 2]
    ## Wavelength range 250.05-899.78 nm, step 0.43-3.72 nm
    ## Label: LED type UV395 from Roithner-Laser
    ## Spectral data in s.e.irrad normalized to 1 at 391 nm (max in 250.05-899.78 nm)
    ## Variables:
    ##  w.length: Wavelength [nm]
    ##  s.e.irrad: Spectral energy irradiance [normalized]
    ## --
    ## # A tibble: 1,369 × 2
    ##    w.length s.e.irrad
    ##       <dbl>     <dbl>
    ##  1     250.         0
    ##  2     253.         0
    ##  3     254.         0
    ##  4     254.         0
    ##  5     255.         0
    ##  6     255.         0
    ##  7     256.         0
    ##  8     256.         0
    ##  9     257.         0
    ## 10     257.         0
    ## # ℹ 1,359 more rows

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["Roithner_UV395"]

    ## Object: source_mspct [1 x 1]
    ## --- Member: Roithner_UV395 ---
    ## Object: source_spct [1,369 x 2]
    ## Wavelength range 250.05-899.78 nm, step 0.43-3.72 nm
    ## Label: LED type UV395 from Roithner-Laser
    ## Spectral data in s.e.irrad normalized to 1 at 391 nm (max in 250.05-899.78 nm)
    ## Variables:
    ##  w.length: Wavelength [nm]
    ##  s.e.irrad: Spectral energy irradiance [normalized]
    ## --
    ## # A tibble: 1,369 × 2
    ##    w.length s.e.irrad
    ##       <dbl>     <dbl>
    ##  1     250.         0
    ##  2     253.         0
    ##  3     254.         0
    ##  4     254.         0
    ##  5     255.         0
    ##  6     255.         0
    ##  7     256.         0
    ##  8     256.         0
    ##  9     257.         0
    ## 10     257.         0
    ## # ℹ 1,359 more rows
    ##
    ## --- END ---

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_leds]

    ## Object: source_mspct [3 x 1]
    ## --- Member: Norlux_NHXRGB090_B ---
    ## Object: source_spct [1,188 x 2]
    ## Wavelength range 251.42-898.74 nm, step 0.43-3.69 nm
    ## Label: 90 die RGB LED array type NHXRGB0905005, blue channel, from Norlux, USA; ca. 1995
    ## Measured on 2011-07-12 12:39:20 UTC
    ## Spectral data in s.e.irrad normalized to 1 at 462.1 nm (max in 251.42-898.74 nm)
    ## Variables:
    ##  w.length: Wavelength [nm]
    ##  s.e.irrad: Spectral energy irradiance [normalized]
    ## --
    ## # A tibble: 1,188 × 2
    ##    w.length s.e.irrad
    ##       <dbl>     <dbl>
    ##  1     251.         0
    ##  2     255.         0
    ##  3     255.         0
    ##  4     256.         0
    ##  5     256.         0
    ##  6     257.         0
    ##  7     257.         0
    ##  8     258.         0
    ##  9     258          0
    ## 10     258.         0
    ## # ℹ 1,178 more rows
    ## --- Member: Norlux_NHXRGB090_G ---
    ## Object: source_spct [1,176 x 2]
    ## Wavelength range 251.42-898.74 nm, step 0.43-3.67 nm
    ## Label: 90 die RGB LED array type NHXRGB0905005, green channel, from Norlux, USA; ca. 1995
    ## Measured on 2011-07-12 12:42:07 UTC
    ## Spectral data in s.e.irrad normalized to 1 at 516.9 nm (max in 251.42-898.74 nm)
    ## Variables:
    ##  w.length: Wavelength [nm]
    ##  s.e.irrad: Spectral energy irradiance [normalized]
    ## --
    ## # A tibble: 1,176 × 2
    ##    w.length s.e.irrad
    ##       <dbl>     <dbl>
    ##  1     251.         0
    ##  2     255.         0
    ##  3     255.         0
    ##  4     256.         0
    ##  5     256.         0
    ##  6     257.         0
    ##  7     257.         0
    ##  8     258.         0
    ##  9     258          0
    ## 10     258.         0
    ## # ℹ 1,166 more rows
    ## --- Member: Norlux_NHXRGB090_R ---
    ## Object: source_spct [1,185 x 2]
    ## Wavelength range 251.42-898.74 nm, step 0.43-3.74 nm
    ## Label: 90 die RGB LED array type NHXRGB0905005, red channel, from Norlux, USA; ca. 1995
    ## Measured on 2011-07-12 12:35:34 UTC
    ## Spectral data in s.e.irrad normalized to 1 at 642.6 nm (max in 251.42-898.74 nm)
    ## Variables:
    ##  w.length: Wavelength [nm]
    ##  s.e.irrad: Spectral energy irradiance [normalized]
    ## --
    ## # A tibble: 1,185 × 2
    ##    w.length s.e.irrad
    ##       <dbl>     <dbl>
    ##  1     251.         0
    ##  2     255.         0
    ##  3     255.         0
    ##  4     256.         0
    ##  5     256.         0
    ##  6     257.         0
    ##  7     257.         0
    ##  8     258.         0
    ##  9     258          0
    ## 10     258.         0
    ## # ℹ 1,175 more rows
    ##
    ## --- END ---

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

    ## Object: source_mspct [4 x 1]
    ## --- Member: QuantumDevices_QDDH66002 ---
    ## Object: source_spct [1,320 x 2]
    ## Wavelength range 250.01-900 nm, step 0.43-3.6 nm
    ## Label: LED, type: QDDH66002 from Quantum Devices, USA; ca. 1995
    ## Measured on 2011-07-30 UTC
    ## Spectral data in s.e.irrad normalized to 1 at 652 nm (max in 250.01-900 nm)
    ## Variables:
    ##  w.length: Wavelength [nm]
    ##  s.e.irrad: Spectral energy irradiance [normalized]
    ## --
    ## # A tibble: 1,320 × 2
    ##    w.length s.e.irrad
    ##       <dbl>     <dbl>
    ##  1     250.         0
    ##  2     253.         0
    ##  3     254.         0
    ##  4     254.         0
    ##  5     255.         0
    ##  6     255.         0
    ##  7     256.         0
    ##  8     256.         0
    ##  9     257.         0
    ## 10     257.         0
    ## # ℹ 1,310 more rows
    ## --- Member: QuantumDevices_QDDH68002 ---
    ## Object: source_spct [1,332 x 2]
    ## Wavelength range 250.01-900 nm, step 0.43-3.6 nm
    ## Label: LED, type: QDDH68002 from Quantum Devices, USA; ca. 1995
    ## Measured on 2011-07-30 UTC
    ## Spectral data in s.e.irrad normalized to 1 at 673.4 nm (max in 250.01-900 nm)
    ## Variables:
    ##  w.length: Wavelength [nm]
    ##  s.e.irrad: Spectral energy irradiance [normalized]
    ## --
    ## # A tibble: 1,332 × 2
    ##    w.length s.e.irrad
    ##       <dbl>     <dbl>
    ##  1     250.         0
    ##  2     253.         0
    ##  3     254.         0
    ##  4     254.         0
    ##  5     255.         0
    ##  6     255.         0
    ##  7     256.         0
    ##  8     256.         0
    ##  9     257.         0
    ## 10     257.         0
    ## # ℹ 1,322 more rows
    ## --- Member: QuantumDevices_QDDH70002 ---
    ## Object: source_spct [1,317 x 2]
    ## Wavelength range 250.01-900 nm, step 0.43-3.59 nm
    ## Label: LED, type: QDDH70002 from Quantum Devices, USA; ca. 1995
    ## Measured on 2011-07-30 UTC
    ## Spectral data in s.e.irrad normalized to 1 at 707.1 nm (max in 250.01-900 nm)
    ## Variables:
    ##  w.length: Wavelength [nm]
    ##  s.e.irrad: Spectral energy irradiance [normalized]
    ## --
    ## # A tibble: 1,317 × 2
    ##    w.length s.e.irrad
    ##       <dbl>     <dbl>
    ##  1     250.         0
    ##  2     253.         0
    ##  3     254.         0
    ##  4     254.         0
    ##  5     255.         0
    ##  6     255.         0
    ##  7     256.         0
    ##  8     256.         0
    ##  9     257.         0
    ## 10     257.         0
    ## # ℹ 1,307 more rows
    ## --- Member: QuantumDevices_QDDH73502 ---
    ## Object: source_spct [1,306 x 2]
    ## Wavelength range 250.01-900 nm, step 0.43-3.57 nm
    ## Label: LED, type: QDDH73502 from Quantum Devices, USA; ca. 1995
    ## Measured on 2011-07-30 UTC
    ## Spectral data in s.e.irrad normalized to 1 at 746.4 nm (max in 250.01-900 nm)
    ## Variables:
    ##  w.length: Wavelength [nm]
    ##  s.e.irrad: Spectral energy irradiance [normalized]
    ## --
    ## # A tibble: 1,306 × 2
    ##    w.length s.e.irrad
    ##       <dbl>     <dbl>
    ##  1     250.         0
    ##  2     253.         0
    ##  3     254.         0
    ##  4     254.         0
    ##  5     255.         0
    ##  6     255.         0
    ##  7     256.         0
    ##  8     256.         0
    ##  9     257.         0
    ## 10     257.         0
    ## # ℹ 1,296 more rows
    ##
    ## --- END ---

## 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$LedEngin_LZ1_10R302_740nm

    ## Object: source_spct [972 x 2]
    ## Wavelength range 251.29-900 nm, step 1.023182e-12-3.8 nm
    ## Label: 3W SMD LED type LZ1-10R302 from LED Engin
    ## Measured on 2021-10-09 23:02:03.877887 UTC
    ## Spectral data in s.e.irrad normalized to 1 at 729.7 nm (max in 251.29-900 nm)
    ## Variables:
    ##  w.length: Wavelength [nm]
    ##  s.e.irrad: Spectral energy irradiance [normalized]
    ## --
    ## # A tibble: 972 × 2
    ##    w.length s.e.irrad
    ##       <dbl>     <dbl>
    ##  1     251.         0
    ##  2     252.         0
    ##  3     255.         0
    ##  4     256.         0
    ##  5     259.         0
    ##  6     263.         0
    ##  7     266.         0
    ##  8     270.         0
    ##  9     274.         0
    ## 10     277.         0
    ## # ℹ 962 more rows

    cat(getWhatMeasured(leds.mspct$LedEngin_LZ1_10R302_740nm))

    ## 3W SMD LED type LZ1-10R302 from LED Engin

    getWhenMeasured(leds.mspct$LedEngin_LZ1_10R302_740nm)

    ## [1] "2021-10-09 23:02:03 UTC"

    getInstrDesc(leds.mspct$LedEngin_LZ1_10R302_740nm)

    ## Data acquired with 'MayaPro2000' s.n. MAYP11278
    ## grating 'HC1', slit '010s'
    ## diffuser 'cosine'

    getInstrSettings(leds.mspct$LedEngin_LZ1_10R302_740nm)

    ## integ. time (s): 0.067, 0.67
    ## total time (s): 10.1, 10.1
    ## counts @ peak (% of max): 95.9

    is_normalized(leds.mspct$LedEngin_LZ1_10R302_740nm)

    ## [1] TRUE

    leds.mspct$Roithner_UVMAX305

    ## Object: source_spct [1,401 x 2]
    ## Wavelength range 250.14-899.77 nm, step 0.43-3.33 nm
    ## Label: LED type UVMAX305 from Roithner-Laser
    ## Measured on 2015-02-10 15:34:32 UTC
    ## Spectral data in s.e.irrad normalized to 1 at 313.1 nm (max in 250.14-899.77 nm)
    ## Variables:
    ##  w.length: Wavelength [nm]
    ##  s.e.irrad: Spectral energy irradiance [normalized]
    ## --
    ## # A tibble: 1,401 × 2
    ##    w.length s.e.irrad
    ##       <dbl>     <dbl>
    ##  1     250.         0
    ##  2     253.         0
    ##  3     254.         0
    ##  4     254.         0
    ##  5     255.         0
    ##  6     255.         0
    ##  7     256.         0
    ##  8     256.         0
    ##  9     257.         0
    ## 10     257.         0
    ## # ℹ 1,391 more rows

    is_normalized(leds.mspct$Roithner_UVMAX305)

    ## [1] TRUE

## Calculating summaries from the normalized data

The spectra in `leds.mspct` and `led_arrays.mspct` are normalized, and consequently, several summaries that are normally expressed in absolute units are undefined, and trigger errors. Summaries like waveband ratios and photon:energy 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).

It is important to keep in mind that normalization based on peak energy emission and based on peak photon emission in most cases differ. In some situations the normalization will be automatically updated when data are converted between these to bases of expression. One example are `autoplot()` methods from package ‘ggspectra’.

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$Roithner_UV395,
                      range = c(315, 400),
                      e_irrad,
                      target = 10
                      )
    e_irrad(my.spct, waveband(c(315,400)))

    ## E_range.315.400
    ##              10
    ## attr(,"time.unit")
    ## [1] "second"
    ## attr(,"radiation.unit")
    ## [1] "total energy irradiance"

The default of `fscale()` is to treat rescaled spectral data as if they were true readings unless `target = 1` is passed. In this last case, the metadata will be set to indicate that the data is in relative units and this will generate a warning during computation of irradiance. Other methods such as `integrate_spct()` will still function silently.

    my.spct <- fscale(leds.mspct$Roithner_UV395,
                      range = c(315, 400),
                      e_irrad,
                      target = 1
                      )
    integrate_spct(my.spct)

    ##  e.irrad
    ## 1.157742

We can reset the attribute with method `setScaled()`. With method `getScaled()` we can test if a spectrum has been scaled.

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

    ## [1] FALSE

    e_irrad(my.spct, waveband(c(315,400)))

    ## E_range.315.400
    ##               1
    ## attr(,"time.unit")
    ## [1] "second"
    ## attr(,"radiation.unit")
    ## [1] "total energy irradiance"

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 bad idea!

    my.UV395 <- leds.mspct$Roithner_UV395
    setNormalized(my.UV395)
    e_irrad(my.UV395)

    ##  E_Total
    ## 16.10434
    ## attr(,"time.unit")
    ## [1] "second"
    ## attr(,"radiation.unit")
    ## [1] "total energy irradiance"

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

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

    ## UVB:UVA[q:q]
    ##            0
    ## attr(,"radiation.unit")
    ## [1] "q:q ratio"

## 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 this suite, ‘ggspectra’, built as an extension to ‘ggplot2’ makes plotting spectra even easier.

`autoplot()` 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.

    autoplot(leds.mspct$LedEngin_LZ1_10R302_740nm, annotations = c("+", "wls"))

Multiple LEDs can be plotted together.

    autoplot(leds.mspct[Osram_leds]) +
      theme(legend.position = "bottom")

They can alternatively be plotted in separate panels.

    autoplot(leds.mspct[Osram_leds], facets = 1) # 1 column

Package ‘ggspectra’ also defines specializations of method `ggplot()` for spectra, that by default set the aesthetic mapping automatically.

    ggplot(leds.mspct$LedEngin_LZ1_10R302_740nm) +
      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$LedEngin_LZ1_10R302_740nm))

    ##   w.length s.e.irrad
    ## 1   251.29         0
    ## 2   251.76         0
    ## 3   255.09         0
    ## 4   255.56         0
    ## 5   258.88         0
    ## 6   262.68         0

Of course `attach` and `with` also work as expected.

    attach(leds.mspct)
    q_ratio(Roithner_UV395, UVB(), UVA())

    ## UVB:UVA[q:q]
    ##            0
    ## attr(,"radiation.unit")
    ## [1] "q:q ratio"

    detach(leds.mspct)

    attach(leds.mspct)
    with(Roithner_UV395, max(w.length))

    ## [1] 899.78

    detach(leds.mspct)

    with(leds.mspct, q_ratio(Roithner_UV395, UVB(), UVA()))

    ## UVB:UVA[q:q]
    ##            0
    ## attr(,"radiation.unit")
    ## [1] "q:q ratio"