Learn R Programming

colorSpec (version 0.5-2)

readSpectra: read colorSpec objects from files

Description

These functions read colorSpec objects from files. In case of ERROR, they return NULL. There are 5 different file formats supported; see Details.

Usage

readSpectra( pathvec, ... )

readSpectraXYY( path )
readSpectraSpreadsheet( path )
readSpectrumScope( path )readSpectraCGATS( path )
readSpectraControl( path )

Arguments

pathvec
a character vector to (possibly) multiple files. The file extension and a few lines from each file are read and a guess is made regarding the file format.
...
optional arguments passed on to resample. The most important is wavelength. If these are missing then resample is not called.
path
a path to a single file with the corresponding format: XYY, Spreadsheet, Scope, CGATS, or Control. See Details. If the function cannot recognize the format, it returns NULL.

Value

  • readSpectra returns a single colorSpec object or NULL in case of ERROR. If there are multiple files in pathvec and they cannot be combined using bind because their wavelengths are different, it is an ERROR. To avoid this ERROR, the wavelength argument can be used for resampling to a common wavelength. If there are multiple files, the organization of the returned object is "df.row" and the first column is the path from which the spectrum was read. The functions readSpectraXYY, readSpectraSpreadsheet, and readSpectraScope, return a single colorSpec object, or NULL in case of ERROR. The functions readSpectraCGATS and readSpectraControl are more complicated. These 2 file formats can contain multiple spectra with different wavelength vectors so both functions return a list of colorSpec objects. When readSpectra is called with a wavelength argument, these multiple spectra are resampled using resample and combined using bind into a single colorSpec object, which makes it much more convenient to read such files.

Details

The file formats are: XYY There is a column header line matching ^(wave|wl) (not case sensitive) followed by the the names of the spectra. All lines above this one are taken to be metadata. The separarator on this header line can be space, tab, or comma; the line is examined and the separator found there is used in the lines with data below. The organization of the returned object is 'df.col'. This is probably the most common file format; see the sample file ciexyz31_1.csv. Spreadsheet There is a line matching "^(ID|SAMPLE|Time)". This line and lines below must be tab-separated. Fields matching '^[A-Z]+([0-9.]+)nm$' are taken to be spectral data and other fields are taken to be extradata. All lines above this one are taken to be metadata. The organization of the returned object is 'df.row'. This is a good format for automated acquisition, using a spectrometer, of many spectra. See the sample file N130501.txt from Wolf Faust. Scope This is a file format used by Ocean Optics spectrometer software. There is a line >>>>>Begin Processed Spectral Data<<<<< followed by wavelength and power separated by a tab. There is only 1 spectrum per file. The organization of the returned object is 'vector'. See the sample file pos1-20x.scope. CGATS This is a complex format that is best understood by looking at some samples, such as extdata/filters/Rosco.txt; see also CGATS.17. The fields with spectral data match the pattern "^(nm|SPEC_|SPECTRAL_)[0-9.]+" and other fields are considered extradata. The organization of the returned object is 'df.row'. Control This is a personal format used for digitizing images of plots from manufacturer datasheets and academic papers. It is structured like a .INI file. There is a [Control] section establishing a simple linear map from pixels to the wavelength and spectrum quantities. Only 3 points are really necessary. It is OK for there to be a little rotation of the plot axes relative to the image. This is followed by a section for each spectrum, in XY pixel units only. Conversion to wavelength and spectral quantities happens on-the-fly. Extrapolation can be a problem, especially when the value is near 0. To force constant extrapolation, repeat the control point (knot) at the endpoint. See the sample file Lumencor-SpectraX.txt. The organization of the returned objects is 'vector'.

References

CGATS.17 Text File Format. http://www.colorwiki.com/wiki/CGATS.17_Text_File_Format.

See Also

wavelength, quantity, metadata, resample, bind

Examples

Run this code
#   read file with header declaring the quantity to be photons->neural
bird = readSpectra( system.file( "extdata/eyes/BirdEyes.txt", package='colorSpec' ) )
quantity(bird)   # [1] "photons->neural"

Run the code above in your browser using DataLab