Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Tidy data structure for infrared spectra and functions to handle and preprocess them.

License

NotificationsYou must be signed in to change notification settings

henningte/ir

Repository files navigation

DOILifecycle: stableCRAN status

Overview

‘ir’ is an R package to import, handle and preprocess infrared spectra.Infrared spectra are stored as list columns in data frames which enablesefficient storage of metadata along with the spectra and using‘tidyverse’ functions for data operations.

Spectra in the following formats can be imported:

  1. csv files with individual spectra.
  2. Thermo Galactic’sspc files with individual spectra.

Functions for spectral preprocessing and data handling:

  1. baseline correction with:
    • a polynomial baseline
    • a convex hull baseline
    • a Savitzky-Golay baseline (Lasch 2012)
  2. binning
  3. clipping
  4. interpolating (resampling, linearly)
  5. replacing selected parts of a spectrum by a straight line
  6. averaging spectra within specified groups
  7. normalizing spectra:
    • to the maximum intensity
    • to the intensity at a specific x value
    • so that all intensity values sum to 1
    • vector normalization
    • Standard Normal Variate correction
  8. smoothing:
    • Savitzky-Golay smoothing
    • Fourier smoothing
  9. computing derivatives of spectra using Savitzky-Golay smoothing
  10. spectral arithmetic (addition, subtraction, multiplication,division)
  11. computing the variance of intensity values (optionally aftersubtracting reference spectra)
  12. computing maxima, minima, median, and ranges of intensity values ofspectra
  13. Atmospheric background correction (Perez-Guaita et al. 2013)
  14. Scaling intensity values in spectra
  15. Wrapper to sampling algorithms implemented in the ‘prospectr’package.
  16. plotting
  17. tidyverse methods

How to install

You can install ‘ir’ from CRAN:

install.packages("ir")

You can install the development version of ‘ir’ from GitHub:

remotes::install_github(repo="henningte/ir",ref="dev")

How to use

Load ‘ir’:

# load ir packagelibrary(ir)# load additional packages needed for this tutoriallibrary(ggplot2)

For brief introductions, see below and the two vignettes:

  1. Introduction to the ‘ir’package
  2. Introduction to theirclass

Sample workflow

Here is an example preprocessing pipeline for the sample data in thepackage (ir_sample_data) which does baseline correction, binning (binwidth of 10), normalization (so that the maximum intensity value is 1and the minimum intensity value is 0), and finally plots thepreprocessed spectra for each sample and sample type:

ir_sample_data|># datair::ir_bc(method="rubberband")|># baseline correctionir::ir_bin(width=10)|># binningir::ir_normalize(method="zeroone")|># normalization  plot()+ggplot2::facet_wrap(~sample_type)# plot

Data structure

You can load the sample data with:

ir::ir_sample_data#> # A tibble: 58 × 7#>    id_measurement id_sample sample_type sample_comment             klason_lignin#>             <int> <chr>     <chr>       <chr>                      <units>#>  1              1 GN 11-389 needles     Abies Firma Momi fir       0.359944#>  2              2 GN 11-400 needles     Cupressocyparis leylandii… 0.339405#>  3              3 GN 11-407 needles     Juniperus chinensis Chine… 0.267552#>  4              4 GN 11-411 needles     Metasequoia glyptostroboi… 0.350016#>  5              5 GN 11-416 needles     Pinus strobus Torulosa     0.331100#>  6              6 GN 11-419 needles     Pseudolarix amabili Golde… 0.279360#>  7              7 GN 11-422 needles     Sequoia sempervirens Cali… 0.329672#>  8              8 GN 11-423 needles     Taxodium distichum Cascad… 0.356950#>  9              9 GN 11-428 needles     Thuja occidentalis Easter… 0.369360#> 10             10 GN 11-434 needles     Tsuga caroliniana Carolin… 0.289050#> # ℹ 48 more rows#> # ℹ 2 more variables: holocellulose <units>, spectra <named list>

ir_sample_data is an object of classir. An Object of classir isa data frame where each row represents one infrared measurement andcolumnspectra contains the infrared spectra (one per row) as listcolumn. This allows to store metadata along each spectrum (for examplethe N content for each sample) and to manipulateir objects with‘tidyverse’ functions.

The columnspectra is a list column of data frames, meaning that eachcell ofspectra contains a data frame which contains the data for onespectrum. For example, here are the first rows of the first spectrum inir_smaple_data:

# View the first ten rows of the first spectrum in ir_sample_datahead(ir_sample_data$spectra[[1]])#> # A tibble: 6 × 2#>       x        y#>   <int>    <dbl>#> 1  4000 0.000361#> 2  3999 0.000431#> 3  3998 0.000501#> 4  3997 0.000571#> 5  3996 0.000667#> 6  3995 0.000704

Columnx contains values for the spectral channel (in this casewavenumbers [cm-1]) and columny the correspondingintensity values.

How to cite

Please cite this R package as:

Henning Teickner (2025).ir: Functions to Handle and PreprocessInfrared Spectra. DOI: 10.5281/zenodo.5747169. Accessed 06 Apr 2025.Online athttps://zenodo.org/record/5747169.

Companion packages

Theirpeat package providesfunctions to analyze infrared spectra of peat (humification indices,prediction models) and uses the ‘ir’ package to handle spectral data.

Licenses

Text and figures :CC BY4.0

Code : See theDESCRIPTION file

Data :CC BY 4.0attribution requested in reuse. See the sources section for data sourcesand how to give credit to the original author(s) and the source.

Contributions

We welcome contributions from everyone. Before you get started, pleasesee ourcontributor guidelines. Please note that thisproject is released with aContributor Code of Conduct. Byparticipating in this project you agree to abide by its terms.

Sources

ir_sample_data is derived from Hodgkins et al. (2018) and wasreformatted to match the requirements of ‘ir’. The original articlecontaining the data can be downloaded fromhttps://www.nature.com/articles/s41467-018-06050-2 and is distributedunder the Creative Commons Attribution 4.0 International License(https://creativecommons.org/licenses/by/4.0/). The data on Klasonlignin and holocellulose content are originally from De la Cruz,Osborne, and Barlaz (2016).

References

De la Cruz, Florentino B., Jason Osborne, and Morton A. Barlaz. 2016.“Determination of Sources of Organic Matter in Solid Waste by Analysisof Phenolic Copper Oxide Oxidation Products of Lignin.”Journal ofEnvironmental Engineering 142 (2): 04015076.https://doi.org/10.1061/(ASCE)EE.1943-7870.0001038.

Hodgkins, Suzanne B., Curtis J. Richardson, René Dommain, Hongjun Wang,Paul H. Glaser, Brittany Verbeke, B. Rose Winkler, et al. 2018.“Tropical Peatland Carbon Storage Linked to Global Latitudinal Trends inPeat Recalcitrance.”Nature Communications 9 (1): 3640.https://doi.org/10.1038/s41467-018-06050-2.

Lasch, Peter. 2012. “Spectral Pre-Processing for Biomedical VibrationalSpectroscopy and Microspectroscopic Imaging.”Chemometrics andIntelligent Laboratory Systems 117 (August): 100–114.https://doi.org/10.1016/j.chemolab.2012.03.011.

Perez-Guaita, David, Julia Kuligowski, Guillermo Quintás, SalvadorGarrigues, and Miguel de la Guardia. 2013. “Atmospheric Compensation inFourier Transform Infrared (FT-IR) Spectra of Clinical Samples.”Applied Spectroscopy 67 (11): 1339–42.https://doi.org/10.1366/13-07159.

About

Tidy data structure for infrared spectra and functions to handle and preprocess them.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp