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
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 @Gruson2019_QuantitativeCharacterizationIridescent 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:
reflect_data <- lr_parse_procspec( system.file("testdata", "procspec_files", "OceanOptics_Linux.ProcSpec", package = "lightr") ) length(reflect_data)
The result contains 2 elements:
We import that white reference in the same way:
white_data <- lr_parse_procspec( 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:
reflect_data <- data.frame(reflect_data[]) white_data <- data.frame(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:
res <- (reflect_data$scope - reflect_data$dark) / (white_data$white - white_data$dark) head(res)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.