Streamlining spectral data processing and modeling for spectroscopy applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
12 KiB

<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Gather measurements of different spectra types, corresponding x-axis values and metadata from nested list. — gather_spc • simplerspec</title><!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" crossorigin="anonymous"><script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css"><script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet"><script src="../pkgdown.js"></script><meta property="og:title" content="Gather measurements of different spectra types, corresponding x-axis values and metadata from nested list. — gather_spc"><meta property="og:description" content='Gather spectra, corresponding x-axis values, and device and
measurement metadata from a nested list into a spectra tibble, so that one
row represents one spectral measurement. Spectra, x-axis values and metadata
are mapped from the individual list elements (named after file name including
the extension) and transformed into (list-)columns of a spectra tibble,
which is an extended data frame. For each measurement, spectral data and
metadata are combined into one row of the tidy data frame. In addition, the ID
columns unique_id, file_id, and sample_id are extracted from
"metadata" (data frame) list entries and returned as identifier columns of
the spectra tibble. List-columns facilitate keeping related data together in
a rectangular data structure. They can be manipulated easily during
subsequent transformations, for example using the standardized functions of
the simplerspec data processing pipeline.'><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]--></head><body data-spy="scroll" data-target="#toc">
<div class="container template-reference-topic">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">simplerspec</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.2.1</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav"><li>
<a href="../reference/index.html">Reference</a>
</li>
<li>
<a href="../news/index.html">Changelog</a>
</li>
</ul><ul class="nav navbar-nav navbar-right"><li>
<a href="https://github.com/philipp-baumann/simplerspec/" class="external-link">
<span class="fab fa-github fa-lg"></span>
</a>
</li>
</ul></div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
</header><div class="row">
<div class="col-md-9 contents">
<div class="page-header">
<h1>Gather measurements of different spectra types, corresponding x-axis values and metadata from nested list.</h1>
<small class="dont-index">Source: <a href="https://github.com/philipp-baumann/simplerspec/blob/HEAD/R/gather-spc.R" class="external-link"><code>R/gather-spc.R</code></a></small>
<div class="hidden name"><code>gather_spc.Rd</code></div>
</div>
<div class="ref-description">
<p>Gather spectra, corresponding x-axis values, and device and
measurement metadata from a nested list into a spectra tibble, so that one
row represents one spectral measurement. Spectra, x-axis values and metadata
are mapped from the individual list elements (named after file name including
the extension) and transformed into (list-)columns of a spectra tibble,
which is an extended data frame. For each measurement, spectral data and
metadata are combined into one row of the tidy data frame. In addition, the ID
columns <code>unique_id</code>, <code>file_id</code>, and <code>sample_id</code> are extracted from
<code>"metadata"</code> (data frame) list entries and returned as identifier columns of
the spectra tibble. List-columns facilitate keeping related data together in
a rectangular data structure. They can be manipulated easily during
subsequent transformations, for example using the standardized functions of
the simplerspec data processing pipeline.</p>
</div>
<div id="ref-usage">
<div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">gather_spc</span><span class="op">(</span><span class="va">data</span>, spc_types <span class="op">=</span> <span class="st">"spc"</span><span class="op">)</span></span></code></pre></div>
</div>
<div id="arguments">
<h2>Arguments</h2>
<dl><dt>data</dt>
<dd><p>Recursive list named with filename (<code>file_id</code>) at first level
entries, where each element containing a sample measurement has nested
metadata (<code>"metadata"</code>), spectra types (see <code>spc_types</code>), corresponding
x-axis values (see section <em>"Details on spectra data checks and matching"</em>).
The <code>data</code> list is a structural convention to organize spectra and their
metadata. It follows for example the list structure returned from the Bruker
OPUS binary reader <code><a href="read_opus_univ.html">simplerspec::read_opus_univ()</a></code>.</p></dd>
<dt>spc_types</dt>
<dd><p>Character vector with the spectra types to be extracted
from <code>data</code> list and gathered into list-columns. The spectra type names need
to exactly follow the naming conventions, and the element names and contents
need to be present at the second list hierarchy of <code>data</code>. These values are
allowed:</p><ul><li><p><code>"spc"</code> (default): final raw spectra after atmospheric compensation, if
performed (named <code>AB</code> in Bruker OPUS software; results from referencing
sample to reference single channel reflectance and transforming to
absorbance).</p></li>
<li><p><code>"spc_nocomp"</code>: raw spectra without atmospheric correction</p></li>
<li><p><code>"sc_sm"</code>: Single channel reflectance spectra of the samples</p></li>
<li><p><code>"sc_rf"</code>: Single channel reflectance spectra of the reference (background
spectra)</p></li>
<li><p><code>"ig_sm"</code>: Interferograms of the sample spectra (currently only spectra
without x-axis list-columns are matched and returned)</p></li>
<li><p><code>"ig_rf"</code>: Interferograms of the reference spectra (currently only spectra
without x-axis list-columns are matched and returned)</p></li>
</ul></dd>
</dl></div>
<div id="value">
<h2>Value</h2>
<p>Spectra tibble (<code>spc_tbl</code> with classes <code>"tbl_df"</code>, <code>"tbl"</code>, and
<code>"data.frame"</code>) with the following (list-)columns:</p><ul><li><p><code>"unique_id"</code>: Character vector with unique measurement identifier, likely
a string with file names in combination with date and time (extracted from
each <code>"metadata"</code> data frame column).</p></li>
<li><p><code>"file_id"</code> : Character vector with file name including the extension
(extracted from each <code>"metadata"</code> data frame column).</p></li>
<li><p><code>"sample_id"</code>: Character vector with sample identifier. For Bruker OPUS
binary files, this corresponds to the file name without the file extension
in integer increments of sample replicate measurements.</p></li>
<li><p>One or multiple of <code>"spc"</code>, <code>"spc_nocomp"</code>, <code>"sc_sm"</code>, or <code>"sc_rf"</code>:
List(s) of data.table's containing spectra type(s).</p></li>
<li><p>One or multiple of <code>"wavenumbers"</code>, <code>"wavelengths"</code>, <code>"x_values"</code>,
<code>"wavenumbers_sc_sm"</code>, <code>"wavelengths_sc_sm"</code>, <code>"x_values_sc_sm"</code>,
<code>"wavenumbers_sc_rf"</code>, <code>"wavelengths_sc_rf"</code>, or <code>"x_values_sc_rf"</code>:
List(s) of numeric vectors with matched x-axis values (see <em>"Details on
spectra data checks and matching"</em> below).</p></li>
</ul></div>
<div id="details-on-spectra-data-checks-and-matching">
<h2>Details on spectra data checks and matching</h2>
<p><code>gather_spc()</code> checks whether these conditions are met for each measurement
in the list <code>data</code>:</p><ol><li><p>Make sure that the first level <code>data</code> elements are named (assumed to be
the file name the data originate from), and remove missing measurements with
an informative message.</p></li>
<li><p>Remove any duplicated file names and raise a message if there are
name duplicates at first level.</p></li>
<li><p>Check whether <code>spc_types</code> inputs are supported (see argument <code>spc_types</code>)
and present at the second level of the <code>data</code> list. If not, remove
all data elements for incomplete spectral measurements.</p></li>
<li><p>Match spectra types and possible corresponding x-axis types from
a lookup list. For each selected spectrum type (left), at least one of
the element names of the x-axis type (right) needs to be present for each
measurement in the list <code>data</code>:</p><ul><li><p><code>"spc"</code> : <code>"wavenumbers"</code>, <code>"wavelengths"</code>, or <code>"x_values"</code></p></li>
<li><p><code>"spc_nocomp"</code> : <code>"wavenumbers"</code>, <code>"wavelengths"</code>, or <code>"x_values"</code></p></li>
<li><p><code>"sc_sm"</code> : <code>"wavenumbers_sc_sm"</code>, <code>"wavelengths_sc_sm"</code>, or
<code>"x_values_sc_sm"</code></p></li>
<li><p><code>"sc_rf"</code> : <code>"wavenumbers_sc_rf"</code>, <code>"wavelengths_sc_rf"</code>, or
<code>"x_values_sc_rf"</code></p></li>
</ul></li>
<li><p>Check if <code>"metadata"</code> elements are present and remove data elements for
measurements with missing or incorrectly named metadata elements
(message).</p></li>
</ol></div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
<nav id="toc" data-toggle="toc" class="sticky-top"><h2 data-toc-skip>Contents</h2>
</nav></div>
</div>
<footer><div class="copyright">
<p></p><p>Developed by Philipp Baumann.</p>
</div>
<div class="pkgdown">
<p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.9.</p>
</div>
</footer></div>
</body></html>