Skip to contents

Reads a CSV spectral data file and its companion JSON file with metadata as published by International Commission on Illumination (CIE) and then imports wavelengths and spectral values into one the classes for spectral data defined in package 'photobiology.

Usage

read_CIE_csv(file.name, label = NULL, simplify = FALSE)

Arguments

file.name

character string Name of CSV file.

label

character string. If NULL metadata read from the JSON file is used, and if NA the "what.measured" attribute is not set, and if a character string is passed, it is used to set the "what.measured" attribute.

simplify

logical If TRUE and the read file contained a single spectrum, extract the spectral object from the collection.

Value

Depending on the contents of the file, a source_mspct or source_spct object, a response_spct or response_spct object, or a chroma_spct object, containing both data and metadata. The whole metadata JSON converted into an R `list` is stored in attribute "header".

Details

The CSV file contains only numbers encoded as character strings, and the JSON file contains extensive metadata. The type of spectral data is encoded as part of the file name. If the original file name of the CSV file is passed as argument to parameter file, the function can retrieve all data and metadata, enough to return an R object of the correct class. The JSON file must be located in the same folder as the CSV file.

Examples


file.name <- 
  system.file("extdata", "CIE_illum_C.csv", 
              package = "photobiologyInOut", mustWork = TRUE)

CIE_illum_C.spct <- read_CIE_csv(file.name)
CIE_illum_C.spct
#> Object: source_mspct [1 x 1]
#> --- Member: CIE.illuminant.C ---
#> Object: source_spct [97 x 2]
#> Wavelength range 300-780 nm, step 5 nm 
#> Label: file: CIE_illum_C.csv  
#> CIE: Relative spectral power distributions of CIE illuminant C 
#> Rescaled to 'identity of s.e.irrad' = NA for wavelengths in 300-780 nm
#> Variables:
#>  w.length: Wavelength [nm]
#>  s.e.irrad: Spectral energy irradiance [scaled] 
#> --
#> # A tibble: 97 × 2
#>    w.length s.e.irrad
#>       <int>     <dbl>
#>  1      300      0   
#>  2      305      0   
#>  3      310      0   
#>  4      315      0   
#>  5      320      0.01
#>  6      325      0.2 
#>  7      330      0.4 
#>  8      335      1.55
#>  9      340      2.7 
#> 10      345      4.85
#> # ℹ 87 more rows
#> 
#> --- END ---
   
file.name <- 
  system.file("extdata", "CIE_sle_photopic.csv", 
              package = "photobiologyInOut", mustWork = TRUE)

CIE_sle_photopic.spct <- read_CIE_csv(file.name)
CIE_sle_photopic.spct
#> Object: response_mspct [1 x 1]
#> --- Member: V.lambda. ---
#> Object: response_spct [471 x 2]
#> Wavelength range 360-830 nm, step 1 nm 
#> Label: file: CIE_sle_photopic.csv  
#> CIE: CIE spectral luminous efficiency for photopic vision 
#> Rescaled to 'identity of s.e.response' = NA for wavelengths in 360-830 nm
#> Variables:
#>  w.length: Wavelength [nm]
#>  s.e.response: Spectral energy response [scaled] 
#> --
#> # A tibble: 471 × 2
#>    w.length s.e.response
#>       <int>        <dbl>
#>  1      360   0.00000392
#>  2      361   0.00000439
#>  3      362   0.00000493
#>  4      363   0.00000553
#>  5      364   0.00000621
#>  6      365   0.00000696
#>  7      366   0.00000781
#>  8      367   0.00000877
#>  9      368   0.00000984
#> 10      369   0.0000110 
#> # ℹ 461 more rows
#> 
#> --- END ---