opusreader2

🪄🪩 Scope and Motivation
grab 'em all — {opusreader2} lets you import OPUS measurement data and parameters from Bruker Optics GmbH & Co. instruments directly in R. Developed in our spare time — if you find it useful, consider buying us a coffee!
The Bruker corporation produces reliable instruments; however, there is no official documentation for the OPUS file format, making it proprietary. Fortunately, over time, our team and colleagues from the open-source spectroscopy community have figured out how the OPUS binary format is structured and how we can parse it (see credits).
{opusreader2} has no hard dependencies beyond base R. Community efforts are there to enhance support for a growing array of instruments, measurement modes, and block types.
📦 Installation
The latest version can be installed
from CodeFloe.com via {remotes} [expand]
directly via R-universe [expand]
🔦 Examples
We recommend to start with the vignette "Reading OPUS binary files from Bruker® spectrometers in R".
library("opusreader2")
# read a single file (one measurement)
file <- opus_test_file()
data <- read_opus(dsn = file)
Reading files in parallel [expand]
Multiple OPUS files can optionally be read in parallel using the {mirai} backend. For this, parallel workers need to be registered.Reading files in parallel with progress updates [expand]
If `parallel = TRUE`, progress updates via {progressr} are optionally availableif (!require("progressr")) install.packages("progressr")
library("progressr")
handlers(global = TRUE)
handlers("progress") # base R progress animation
file <- opus_test_file()
files_1000 <- rep(file, 1000L)
# read with progress bar
data <- read_opus(dsn = files_1000, parallel = TRUE, progress_bar = TRUE)
Advanced testing and Bruker OPUS file specification
We strive to have a full-fledged reader of OPUS files that is on par with the commercial reader in the Bruker OPUS software suite.
To contribute to the development, we will provide an additional vignette that describes the OPUS format and the technical details of our implementation in the package.
How to contribute
We like the spirit of open source development, so any constructive suggestions or questions are always welcome. To trade off the consistency and quality of code with the drive for innovation, we are following some best practices (which can be indeed improved, as many other things in life). These are:
- Code checks (linting), styling, and spell checking: We use the pre-commit framework with both some generic coding and R specific hooks configured in
.pre-commit-config.yaml. Generally, we follow the tidyverse style guide, with slight exceptions. To provide auto-fixing in PRs where possible, we rely on pre-commit.ci lite.
Install and enable pre-commit hooks locally (details)
1. install pre-commit with python3. For more details and options, see [the official documentation](https://pre-commit.com/) 2. enable the pre-commit hooks in `.pre-commit-config.yaml` Once you do a `git commit -m "Check all files for which pre-commit hooks are configured (details)
Performance benchmarking
git clone ssh://git@codefloe.com/spectral-cockpit/opusreader2.git
cd opusreader2
hyperfine --warmup 3 --min-runs 5 ./inst/scripts/benchmark_read_opus_parallel.sh --show-output
Organizations and projects using {opusreader2}
As far as we know, the following organizations and projects use our package. Please make a pull request if you want to be listed here.
- CSIRO
- Open Soil Spectral Library
- ETH Zürich: Sustainable Agroecosystems group and Soil Resources group
Background
This package is a major rework of {opusreader} made by Pierre Roudier and Philipp Baumann. This precessor package relies on an interesting but not optimal reverse engineered logic. Particularly, the assignment of spectral data types (i.e., single channel reflectance vs. final result spectrum), was buggy because the CO2 peak ratio was used as a heuristic. Also, byte offsets from three letter strings were directly used to read specific data and assign block types.
The new package parses the file header for assigning spectral blocks.
Credits
- Pierre Roudier and Philipp Baumann made an improved R reader, further developing the version in simplerspec by Philipp. https://github.com/pierreroudier/opusreader
- QED.ai: implemented a python parser which takes the main the logic of ono. https://github.com/qedsoftware/brukeropusreader
- twagner: wrote a OPUS FTIR clone called ono. Original decrypter of the header. https://pypi.org/project/ono/
- Andrew Sila and Tomislav Hengl: wrote a first OPUS reader in R. https://github.com/cran/soil.spec/blob/master/R/read.opus.R
