Some use cases require more flexibility than the high-level user-friendly functions provides by
lightr. For this use case,
lightr also exports the low-level individual parsers, which allow the user to code its own custom workflow.
We don’t recommend the use of those functions unless you absolutely have to. Most users should use
Here, we take the example of the method presented in Gruson et al. (2019) where reflectance spectra need to be normalised in an unusual way.
Raw, un-normalised spectral data depends on both the spectrometer and the lamp as well as the conditions during the recording (including ambient light, temperature, etc.). To allow for comparison between studies, it is thus normalised by a white and a dark reference with the following formula:
For this example here, we need to normalise the raw data by a white reference contained in another file. This can’t be done with with
lr_get_spec() returns reflectance spectra that have already been normalised by the white reference contained in the same file.
We manually import the data using the appropriate low-level parser:
<- lr_parse_procspec( reflect_data system.file("testdata", "procspec_files", "OceanOptics_Linux.ProcSpec", package = "lightr") )length(reflect_data)
##  2
The result contains 2 elements:
## wl dark white scope processed ## 1 176.3604 32822.795 32822.795 32822.795 0.00000 ## 2 176.5816 32822.795 32822.795 32822.795 0.00000 ## 3 176.8027 32822.795 32822.795 32822.795 0.00000 ## 4 177.0238 1483.549 1517.545 1496.656 38.55422 ## 5 177.2449 1492.150 1506.486 1510.991 131.42857 ## 6 177.4660 1965.640 1934.102 1976.290 -33.76623
We import that white reference in the same way:
<- lr_parse_procspec( white_data system.file("testdata", "procspec_files", "whiteref.ProcSpec", package = "lightr") )
We can now normalise the reflectance spectrum with the equation stated at the beginning of this vignette:
But first, we verify that the integration times:
We can now get rid of the metadata part and focus on the data only:
<- data.frame(reflect_data[]) reflect_data <- data.frame(white_data[])white_data
As a last step before being able to normalise the data, we also need to check if the reflectance spectrum and the white reference are sampled with the same wavelengths:
##  TRUE
<- (reflect_data$scope - reflect_data$dark) / res $white - white_data$dark) (white_datahead(res)
##  NaN NaN NaN -5.3333333 46.0000000 0.6190476