Title: | Read Spectrometric Data and Metadata |
---|---|
Description: | Parse various reflectance/transmittance/absorbance spectra file formats to extract spectral data and metadata, as described in Gruson, White & Maia (2019) <doi:10.21105/joss.01857>. Among other formats, it can import files from 'Avantes' <https://www.avantes.com/>, 'CRAIC' <https://www.microspectra.com/>, and 'OceanInsight' (formerly 'OceanOptics') <https://www.oceaninsight.com/> brands. |
Authors: | Hugo Gruson [cre, aut, cph] , Rafael Maia [aut, cph] , Thomas White [aut, cph] , Kotya Karapetyan [ctb, cph] (Author of the MATLAB script to read AvaSoft7 binary files (CC-BY)) |
Maintainer: | Hugo Gruson <[email protected]> |
License: | GPL (>=2) |
Version: | 1.7.1.9000 |
Built: | 2024-11-08 04:59:28 UTC |
Source: | https://github.com/ropensci/lightr |
Convert spectral data files to csv files
lr_convert_tocsv( where = NULL, ext = "txt", decimal = ".", sep = NULL, subdir = FALSE, ignore.case = TRUE, overwrite = FALSE, metadata = TRUE )
lr_convert_tocsv( where = NULL, ext = "txt", decimal = ".", sep = NULL, subdir = FALSE, ignore.case = TRUE, overwrite = FALSE, metadata = TRUE )
where |
Folder in which files are located (defaults to current working directory). |
ext |
File extension to be searched for, without the "." (defaults to
|
decimal |
Character to be used to identify decimal plates
(defaults to |
sep |
Column delimiting characters to be considered in addition to the default (which are: tab, space, and ";") |
subdir |
Should subdirectories within the |
ignore.case |
Should the extension search be case insensitive? (defaults
to |
overwrite |
logical. Should the function overwrite existing files with
the same name? (defaults to |
metadata |
logical (defaults to |
You can customise the type of parallel processing used by this function with
the future::plan()
function. This works on all operating systems, as well
as high performance computing (HPC) environment. Similarly, you can customise
the way progress is shown with the progressr::handlers()
functions
(progress bar, acoustic feedback, nothing, etc.)
Convert input files to csv and invisibly return the list of created file paths
When metadata = TRUE
, if either the data or metadata export fails,
nothing will be returned for this file.
Finds and imports metadata from spectra files in a given location.
lr_get_metadata( where = getwd(), ext = "ProcSpec", sep = NULL, subdir = FALSE, subdir.names = FALSE, ignore.case = TRUE )
lr_get_metadata( where = getwd(), ext = "ProcSpec", sep = NULL, subdir = FALSE, subdir.names = FALSE, ignore.case = TRUE )
where |
Folder in which files are located (defaults to current working directory). |
ext |
File extension to be searched for, without the "." (defaults to
|
sep |
Column delimiting characters to be considered in addition to the default (which are: tab, space, and ";") |
subdir |
Should subdirectories within the |
subdir.names |
Should subdirectory path be included in the name of the
spectra? (defaults to |
ignore.case |
Should the extension search be case insensitive? (defaults
to |
You can customise the type of parallel processing used by this function with
the future::plan()
function. This works on all operating systems, as well
as high performance computing (HPC) environment. Similarly, you can customise
the way progress is shown with the progressr::handlers()
functions
(progress bar, acoustic feedback, nothing, etc.)
A data.frame containing one file per row and the following columns:
name
: File name (without the extension)
user
: Name of the spectrometer operator
datetime
: Timestamp of the recording (ISO 8601 format)
spec_model
: Model of the spectrometer
spec_ID
: Unique ID of the spectrometer
white_inttime
: Integration time of the white reference (in ms)
dark_inttime
: Integration time of the dark reference (in ms)
sample_inttime
: Integration time of the sample (in ms)
white_avgs
: Number of averaged measurements for the white reference
dark_avgs
: Number of averaged measurements for the dark reference
sample_avgs
: Number of averaged measurements for the sample
white_boxcar
: Boxcar width for the white reference
dark_boxcar
: Boxcar width for the dark reference
sample_boxcar
: Boxcar width for the sample reference
white_inttime
, dark_inttime
and sample_inttime
should be equal. The
normalised data may be inaccurate otherwise.
White TE, Dalrymple RL, Noble DWA, O'Hanlon JC, Zurek DB, Umbers KDL. Reproducible research in the study of biological coloration. Animal Behaviour. 2015 Aug 1;106:51-7 (doi:10.1016/j.anbehav.2015.05.007).
lr_get_metadata(system.file("testdata", "procspec_files", package = "lightr"), ext = "ProcSpec")
lr_get_metadata(system.file("testdata", "procspec_files", package = "lightr"), ext = "ProcSpec")
Finds and imports reflectance/transmittance/absorbance data from spectra files in a given location.
lr_get_spec( where = getwd(), ext = "txt", lim = c(300, 700), decimal = ".", sep = NULL, subdir = FALSE, subdir.names = FALSE, ignore.case = TRUE, interpolate = TRUE )
lr_get_spec( where = getwd(), ext = "txt", lim = c(300, 700), decimal = ".", sep = NULL, subdir = FALSE, subdir.names = FALSE, ignore.case = TRUE, interpolate = TRUE )
where |
Folder in which files are located (defaults to current working directory). |
ext |
File extension to be searched for, without the "." (defaults to
|
lim |
A vector with two numbers determining the wavelength limits to be
considered (defaults to |
decimal |
Character to be used to identify decimal plates
(defaults to |
sep |
Column delimiting characters to be considered in addition to the default (which are: tab, space, and ";") |
subdir |
Should subdirectories within the |
subdir.names |
Should subdirectory path be included in the name of the
spectra? (defaults to |
ignore.case |
Should the extension search be case insensitive? (defaults
to |
interpolate |
Boolean indicated whether spectral data should be
interpolated and pruned at every nanometre. Note that this option can only
work if all input data samples the same wavelengths. Defaults to |
You can customise the type of parallel processing used by this function with
the future::plan()
function. This works on all operating systems, as well
as high performance computing (HPC) environment. Similarly, you can customise
the way progress is shown with the progressr::handlers()
functions
(progress bar, acoustic feedback, nothing, etc.)
A data.frame, containing the wavelengths in the first column and individual imported spectral files in the subsequent columns.
spcs <- lr_get_spec(system.file("testdata", package = "lightr"), ext = "jdx") head(spcs)
spcs <- lr_get_spec(system.file("testdata", package = "lightr"), ext = "jdx") head(spcs)
Generic function to parse spectra files that don't have a specific parser
lr_parse_generic(filename, decimal = ".", sep = NULL)
lr_parse_generic(filename, decimal = ".", sep = NULL)
filename |
Path of the file to parse |
decimal |
Character to be used to identify decimal plates
(defaults to |
sep |
Column delimiting characters to be considered in addition to the default (which are: tab, space, and ";") |
'processed' column computed by official software and provided as is.
A named list of two elements:
data
: a dataframe with columns "wl", "dark", "white", "scope" and
"processed", in this order.
metadata
: a character vector with metadata including:
user
: Name of the spectrometer operator
datetime
: Timestamp of the recording in format '%Y-%m-%d %H:%M:%S'
and UTC timezone. If timezone is missing in source file, UTC time will
be assumed (for reproducibility purposes across computers with different
localtimes).
spec_model
: Model of the spectrometer
spec_ID
: Unique ID of the spectrometer
white_inttime
: Integration time of the white reference (in ms)
dark_inttime
: Integration time of the dark reference (in ms)
sample_inttime
: Integration time of the sample (in ms)
white_avgs
: Number of averaged measurements for the white reference
dark_avgs
: Number of averaged measurements for the dark reference
sample_avgs
: Number of averaged measurements for the sample
white_boxcar
: Boxcar width for the white reference
dark_boxcar
: Boxcar width for the dark reference
sample_boxcar
: Boxcar width for the sample reference
res_csv <- lr_parse_generic( system.file("testdata", "spec.csv", package = "lightr"), sep = "," ) head(res_csv$data) # No metadata is extracted with this parser res_csv$metadata res_craic <- lr_parse_generic( system.file("testdata", "CRAIC_export.txt", package = "lightr") ) head(res_craic$data) # No metadata is extracted with this parser res_craic$metadata
res_csv <- lr_parse_generic( system.file("testdata", "spec.csv", package = "lightr"), sep = "," ) head(res_csv$data) # No metadata is extracted with this parser res_csv$metadata res_craic <- lr_parse_generic( system.file("testdata", "CRAIC_export.txt", package = "lightr") ) head(res_craic$data) # No metadata is extracted with this parser res_craic$metadata
Parse OceanInsight (formerly OceanOptics) converted file. https://www.oceaninsight.com/
lr_parse_jaz(filename) lr_parse_jazirrad(filename)
lr_parse_jaz(filename) lr_parse_jazirrad(filename)
filename |
Path of the file to parse |
'processed' column computed by official software and provided as is.
A named list of two elements:
data
: a dataframe with columns "wl", "dark", "white", "scope" and
"processed", in this order.
metadata
: a character vector with metadata including:
user
: Name of the spectrometer operator
datetime
: Timestamp of the recording in format '%Y-%m-%d %H:%M:%S'
and UTC timezone. If timezone is missing in source file, UTC time will
be assumed (for reproducibility purposes across computers with different
localtimes).
spec_model
: Model of the spectrometer
spec_ID
: Unique ID of the spectrometer
white_inttime
: Integration time of the white reference (in ms)
dark_inttime
: Integration time of the dark reference (in ms)
sample_inttime
: Integration time of the sample (in ms)
white_avgs
: Number of averaged measurements for the white reference
dark_avgs
: Number of averaged measurements for the dark reference
sample_avgs
: Number of averaged measurements for the sample
white_boxcar
: Boxcar width for the white reference
dark_boxcar
: Boxcar width for the dark reference
sample_boxcar
: Boxcar width for the sample reference
res_jaz <- lr_parse_jaz(system.file("testdata", "jazspec.jaz", package = "lightr")) head(res_jaz$data) res_jaz$metadata res_jazirrad <- lr_parse_jazirrad(system.file("testdata", "irrad.JazIrrad", package = "lightr")) head(res_jazirrad$data) res_jazirrad$metadata res_usb4000 <- lr_parse_jaz(system.file("testdata", "OOusb4000.txt", package = "lightr")) head(res_usb4000$data) res_usb4000$metadata res_transmission <- lr_parse_jaz( system.file("testdata", "FMNH6834.00000001.Master.Transmission", package = "lightr") ) head(res_transmission$data) res_transmission$metadata
res_jaz <- lr_parse_jaz(system.file("testdata", "jazspec.jaz", package = "lightr")) head(res_jaz$data) res_jaz$metadata res_jazirrad <- lr_parse_jazirrad(system.file("testdata", "irrad.JazIrrad", package = "lightr")) head(res_jazirrad$data) res_jazirrad$metadata res_usb4000 <- lr_parse_jaz(system.file("testdata", "OOusb4000.txt", package = "lightr")) head(res_usb4000$data) res_usb4000$metadata res_transmission <- lr_parse_jaz( system.file("testdata", "FMNH6834.00000001.Master.Transmission", package = "lightr") ) head(res_transmission$data) res_transmission$metadata
Parse OceanInsight (formerly OceanOptics) JCAMP-DX (.jdx) file. https://www.oceaninsight.com/
lr_parse_jdx(filename)
lr_parse_jdx(filename)
filename |
Path of the file to parse |
'processed' column computed by lightr with the function
lr_compute_processed()
.
A named list of two elements:
data
: a dataframe with columns "wl", "dark", "white", "scope" and
"processed", in this order.
metadata
: a character vector with metadata including:
user
: Name of the spectrometer operator
datetime
: Timestamp of the recording in format '%Y-%m-%d %H:%M:%S'
and UTC timezone. If timezone is missing in source file, UTC time will
be assumed (for reproducibility purposes across computers with different
localtimes).
spec_model
: Model of the spectrometer
spec_ID
: Unique ID of the spectrometer
white_inttime
: Integration time of the white reference (in ms)
dark_inttime
: Integration time of the dark reference (in ms)
sample_inttime
: Integration time of the sample (in ms)
white_avgs
: Number of averaged measurements for the white reference
dark_avgs
: Number of averaged measurements for the dark reference
sample_avgs
: Number of averaged measurements for the sample
white_boxcar
: Boxcar width for the white reference
dark_boxcar
: Boxcar width for the dark reference
sample_boxcar
: Boxcar width for the sample reference
McDonald RS, Wilks PA. JCAMP-DX: A Standard Form for Exchange of Infrared Spectra in Computer Readable Form. Applied Spectroscopy. 1988;42(1):151-62.
res_jdx <- lr_parse_jdx(system.file("testdata", "OceanOptics_period.jdx", package = "lightr")) head(res_jdx$data) res_jdx$metadata
res_jdx <- lr_parse_jdx(system.file("testdata", "OceanOptics_period.jdx", package = "lightr")) head(res_jdx$data) res_jdx$metadata
Parse OceanInsight (formerly OceanOptics) ProcSpec file. https://www.oceaninsight.com/
lr_parse_procspec(filename)
lr_parse_procspec(filename)
filename |
Path of the file to parse |
'processed' column computed by official software and provided as is.
A named list of two elements:
data
: a dataframe with columns "wl", "dark", "white", "scope" and
"processed", in this order.
metadata
: a character vector with metadata including:
user
: Name of the spectrometer operator
datetime
: Timestamp of the recording in format '%Y-%m-%d %H:%M:%S'
and UTC timezone. If timezone is missing in source file, UTC time will
be assumed (for reproducibility purposes across computers with different
localtimes).
spec_model
: Model of the spectrometer
spec_ID
: Unique ID of the spectrometer
white_inttime
: Integration time of the white reference (in ms)
dark_inttime
: Integration time of the dark reference (in ms)
sample_inttime
: Integration time of the sample (in ms)
white_avgs
: Number of averaged measurements for the white reference
dark_avgs
: Number of averaged measurements for the dark reference
sample_avgs
: Number of averaged measurements for the sample
white_boxcar
: Boxcar width for the white reference
dark_boxcar
: Boxcar width for the dark reference
sample_boxcar
: Boxcar width for the sample reference
https://www.oceaninsight.com/support/faqs/software/
res <- lr_parse_procspec(system.file("testdata", "procspec_files", "OceanOptics_Linux.ProcSpec", package = "lightr")) head(res$data) res$metadata
res <- lr_parse_procspec(system.file("testdata", "procspec_files", "OceanOptics_Linux.ProcSpec", package = "lightr")) head(res$data) res$metadata
Parse SPC binary file. (Used by CRAIC https://www.microspectra.com/ and OceanInsight https://www.oceaninsight.com/)
lr_parse_spc(filename)
lr_parse_spc(filename)
filename |
Path of the file to parse |
'processed' column computed by official software and provided as is.
A named list of two elements:
data
: a dataframe with columns "wl", "dark", "white", "scope" and
"processed", in this order.
metadata
: a character vector with metadata including:
user
: Name of the spectrometer operator
datetime
: Timestamp of the recording in format '%Y-%m-%d %H:%M:%S'
and UTC timezone. If timezone is missing in source file, UTC time will
be assumed (for reproducibility purposes across computers with different
localtimes).
spec_model
: Model of the spectrometer
spec_ID
: Unique ID of the spectrometer
white_inttime
: Integration time of the white reference (in ms)
dark_inttime
: Integration time of the dark reference (in ms)
sample_inttime
: Integration time of the sample (in ms)
white_avgs
: Number of averaged measurements for the white reference
dark_avgs
: Number of averaged measurements for the dark reference
sample_avgs
: Number of averaged measurements for the sample
white_boxcar
: Boxcar width for the white reference
dark_boxcar
: Boxcar width for the dark reference
sample_boxcar
: Boxcar width for the sample reference
Metadata parsing has not yet been implemented for this file format.
res <- lr_parse_spc(system.file("testdata", "compare", "CRAIC", "CRAIC.spc", package = "lightr")) head(res$data) res$metadata
res <- lr_parse_spc(system.file("testdata", "compare", "CRAIC", "CRAIC.spc", package = "lightr")) head(res$data) res$metadata
Parse Avantes binary file (TRM, ABS, ROH, DRK, REF, RAW8, RFL8 file extensions). https://www.avantes.com/products/spectrometers/
lr_parse_trm(filename) lr_parse_abs(filename) lr_parse_roh(filename) lr_parse_rfl8(filename, specnum = 1L) lr_parse_raw8(filename, specnum = 1L) lr_parse_irr8(filename, specnum = 1L)
lr_parse_trm(filename) lr_parse_abs(filename) lr_parse_roh(filename) lr_parse_rfl8(filename, specnum = 1L) lr_parse_raw8(filename, specnum = 1L) lr_parse_irr8(filename, specnum = 1L)
filename |
Path of the file to parse |
specnum |
Integer representing the position of the spectrum to read in the file. This option only makes sense for AvaSoft8 files and is ignored in the other cases. |
'processed' column computed by lightr with the function
lr_compute_processed()
.
A named list of two elements:
data
: a dataframe with columns "wl", "dark", "white", "scope" and
"processed", in this order.
metadata
: a character vector with metadata including:
user
: Name of the spectrometer operator
datetime
: Timestamp of the recording in format '%Y-%m-%d %H:%M:%S'
and UTC timezone. If timezone is missing in source file, UTC time will
be assumed (for reproducibility purposes across computers with different
localtimes).
spec_model
: Model of the spectrometer
spec_ID
: Unique ID of the spectrometer
white_inttime
: Integration time of the white reference (in ms)
dark_inttime
: Integration time of the dark reference (in ms)
sample_inttime
: Integration time of the sample (in ms)
white_avgs
: Number of averaged measurements for the white reference
dark_avgs
: Number of averaged measurements for the dark reference
sample_avgs
: Number of averaged measurements for the sample
white_boxcar
: Boxcar width for the white reference
dark_boxcar
: Boxcar width for the dark reference
sample_boxcar
: Boxcar width for the sample reference
res_trm <- lr_parse_trm( system.file("testdata", "avantes_trans.TRM", package = "lightr") ) head(res_trm$data) res_trm$metadata res_roh <- lr_parse_roh( system.file("testdata", "avantes_reflect.ROH", package = "lightr") ) head(res_roh$data) res_roh$metadata # This parser has a unique `specnum` argument res_rfl8_1 <- lr_parse_rfl8( system.file("testdata", "compare", "Avantes", "feather.RFL8", package = "lightr"), specnum = 1 ) head(res_rfl8_1$data) res_rfl8_1$metadata res_rfl8_2 <- lr_parse_rfl8( system.file("testdata", "compare", "Avantes", "feather.RFL8", package = "lightr"), specnum = 2 ) head(res_rfl8_2$data) res_rfl8_2$metadata
res_trm <- lr_parse_trm( system.file("testdata", "avantes_trans.TRM", package = "lightr") ) head(res_trm$data) res_trm$metadata res_roh <- lr_parse_roh( system.file("testdata", "avantes_reflect.ROH", package = "lightr") ) head(res_roh$data) res_roh$metadata # This parser has a unique `specnum` argument res_rfl8_1 <- lr_parse_rfl8( system.file("testdata", "compare", "Avantes", "feather.RFL8", package = "lightr"), specnum = 1 ) head(res_rfl8_1$data) res_rfl8_1$metadata res_rfl8_2 <- lr_parse_rfl8( system.file("testdata", "compare", "Avantes", "feather.RFL8", package = "lightr"), specnum = 2 ) head(res_rfl8_2$data) res_rfl8_2$metadata
Parse Avantes converted file. https://www.avantes.com/products/spectrometers/
lr_parse_ttt(filename) lr_parse_trt(filename)
lr_parse_ttt(filename) lr_parse_trt(filename)
filename |
Path of the file to parse |
'processed' column computed by official software and provided as is.
A named list of two elements:
data
: a dataframe with columns "wl", "dark", "white", "scope" and
"processed", in this order.
metadata
: a character vector with metadata including:
user
: Name of the spectrometer operator
datetime
: Timestamp of the recording in format '%Y-%m-%d %H:%M:%S'
and UTC timezone. If timezone is missing in source file, UTC time will
be assumed (for reproducibility purposes across computers with different
localtimes).
spec_model
: Model of the spectrometer
spec_ID
: Unique ID of the spectrometer
white_inttime
: Integration time of the white reference (in ms)
dark_inttime
: Integration time of the dark reference (in ms)
sample_inttime
: Integration time of the sample (in ms)
white_avgs
: Number of averaged measurements for the white reference
dark_avgs
: Number of averaged measurements for the dark reference
sample_avgs
: Number of averaged measurements for the sample
white_boxcar
: Boxcar width for the white reference
dark_boxcar
: Boxcar width for the dark reference
sample_boxcar
: Boxcar width for the sample reference
res_ttt <- lr_parse_ttt( system.file("testdata", "avantes_export.ttt", package = "lightr") ) head(res_ttt$data) res_ttt$metadata res_trt <- lr_parse_trt( system.file("testdata", "avantes_export2.trt", package = "lightr") ) head(res_trt$data) res_trt$metadata
res_ttt <- lr_parse_ttt( system.file("testdata", "avantes_export.ttt", package = "lightr") ) head(res_ttt$data) res_ttt$metadata res_trt <- lr_parse_trt( system.file("testdata", "avantes_export2.trt", package = "lightr") ) head(res_trt$data) res_trt$metadata