read_wasatch_csv: Read File Saved by Wasatch's Enlighten.

View source: R/read-wasatch-csv.r

read_wasatch_csvR Documentation

Read File Saved by Wasatch's Enlighten.

Description

Read wavelength and spectral data from the data section of a file as output by Enlighten importing them into R. Parse the header of a file to extract the acquisition time, instrument name and serial number, as well additional metadata related to the instrument and its settings. Function read_wasatch_csv() only accepts "column oriented" CSV files.

Usage

read_wasatch_csv(
  file,
  date = NULL,
  geocode = NULL,
  label = NULL,
  tz = NULL,
  locale = readr::default_locale(),
  s.qty = NULL,
  extra.cols = "keep",
  scale.factor = 1,
  simplify = TRUE,
  ...
)

Arguments

file

character

date

a POSIXct object to use to set the "when.measured" attribute. If NULL, the default, the date and time are extracted from the file header.

geocode

A data frame with columns lon and lat used to set attribute "where.measured".

label

character string, but if NULL the value of file is used, and if NA the "what.measured" attribute is not set.

tz

character Time zone is by default that of the machine's locale.

locale

The locale controls defaults that vary from place to place. The default locale is US-centric (like R), but you can use locale to create your own locale that controls things like the default time zone, encoding, decimal mark, big mark, and day/month names.

s.qty

character, possibly named. The name of the quantity using the conventions accepted used in package 'photobiology' that is to be imported from column "Processed" from the file.

extra.cols

character What to do non-processed data columns if present in file. One of "keep", "drop.pixel", "drop" or "split".

scale.factor

numeric vector of length 1, or length equal to the number of rows (= detector pixels). Numeric multiplier applied to returned spectral values.

simplify

logical If TRUE, single spectra are returned as individual spectra instead of collections of length one.

...

additional arguments passed to the constructor of the spectrum object.

Details

Enlighten's column-wise CSV files contain at least two columns, Wavelength and Processed. In the header the Technique used is recorded. Additional data columns can be present. Column Pixel contains the pixel index in the array as integers. Columns Raw, Dark and Reference contain detector counts data. Technique is used to guess the type of spectrum stored in the column named Processed, which can be detector counts or derived values. By default the data are read into a single spectrum object and all columns retained, but only the data in Processed are interpreted as spectral data corresponding to the class of the object. If passed extra.cols = "drop", only Wavelength and Processed are copied to the returned object, while if passed extra.cols = "drop.pixel" only the contents of column Pixel are discarded. If passed extra.cols = "split" all columns containing spectral data are each read into a separate spectrum, these are collected and a "generic_mspct" object containing them returned. extra.cols can be a named vector of mappings, of length at least one but possibly longer. If longer a "generic_mspct" is returned, otherwise a spectrum object as inferred from the name each column is mapped to.

Value

An object of a class derived from generic_spct such as raw_spct or filter_spct. generic_spct is derived from tibble and data frame.

Acknowledgements

We thank Ruud Niesen from Photon Mission (https://photonmission.com/) for organizing the loan of the spectrometer used to produce the various files needed for the development of this function.

Note

Enlighten, the free software from Wasatch Photonics can save spectra in a variety of additional formats: different types of CSV files, plain text and JSON. Plain text files contain no metadata or even column headers and if the need arises can be read with R function read.table(). JSON files contain the most detailed metadata.

References

https://wasatchphotonics.com/ https://wasatchphotonics.com/product-category/software/

Examples


 file.name <- 
   system.file("extdata", "enlighten-wasatch-scope.csv",
               package = "photobiologyInOut", mustWork = TRUE)
              
 wasatch.raw.spct <- 
   read_wasatch_csv(file = file.name)
 summary(wasatch.raw.spct)

 wasatch.raw.spct <- 
   read_wasatch_csv(file = file.name, s.qty = "counts")
 summary(wasatch.raw.spct)

 wasatch.raw.spct <- 
   read_wasatch_csv(file = file.name, s.qty = c(Processed = "counts"))
 summary(wasatch.raw.spct)

 wasatch.raw.spct <- 
   read_wasatch_csv(file = file.name, extra.cols = "drop")
 summary(wasatch.raw.spct)


photobiologyInOut documentation built on July 26, 2023, 5:15 p.m.