Giter VIP home page Giter VIP logo

joshduran / brukeropus Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 1.18 MB

A python package for communicating with Bruker OPUS spectroscopy software and reading its binary file format.

Home Page: https://joshduran.github.io/brukeropus/

License: MIT License

Python 100.00%
bruker bruker-opus ftir ftir-data-analysis opus spectroscopy absorption interferograms python raman raman-spectroscopy reflection spectra transmission

brukeropus's Introduction

Bruker OPUS

brukeropus is a Python package for interacting with Bruker's OPUS spectroscopy software. Currently, the package can read OPUS data files and communicate/control OPUS through the DDE interface (e.g. for scripting measurement sequences).

Reading OPUS Data Files

brukeropus can read the binary data files saved by OPUS. The parsing algorithm in this package is more complete than previous efforts, with a goal to achieve 100% extraction accuracy.

Features

  • Extracts spectral data (e.g. sample, reference, absorbance, transmittance, etc.)
  • Extracts 3D spectral data (e.g. spectral time series)
  • Extracts file metadata (e.g. beamsplitter, source, aperture, etc.)
  • Very fast data parsing and assigning to OPUSFile class (limited by disk I/O)
  • Low-level parsing functions are well documented and could be used to build your own custom OPUS file class if OPUSFile does not suit your needs)

Usage

from brukeropus import read_opus
from matplotlib import pyplot as plt

opus_file = read_opus('file.0')  # Returns an OPUSFile class

opus_file.print_parameters()  # Pretty prints all metadata in the file to the console

if 'a' in opus_file.data_keys:  # If absorbance spectra was extracted from file
    plt.plot(opus_file.a.x, opus_file.a.y)  # Plot absorbance spectra
    plt.title(opus_file.sfm + ' - ' + opus_file.snm)  # Sets plot title to Sample Form - Sample Name
    plt.show()  # Display plot

Known Limitations

  • While all metadata can be be extracted as key: val pairs, the keys are stored as three characters (e.g. BMS, SRT, SRC) and are not particularly descriptive. This package has human readable labels for over 100 of these metadata keys, but it is not complete.

    • OPUS software should be using a local file (perhaps PARMTEXT.bin) to convert these keys to human readable lables. it would be ideal to extract these labels directly from this file rather than manually adding them by hand as is currently done.
  • I have only tested this on ~5000 files generated in my lab (all very similiar) as well as a handful of files I've found online (most of which had some error when being read by other tools). This package is capable of reading all of those files, but thorough testing on a wide variety of files is incomplete.

    • If you have a file that cannot be read by brukeropus, please open an issue with a description about the file and what seems to be failing. Also provide a link for me to download the file. Make sure the file can be read by OPUS first (i.e. if the file is corrupted and unreadable by OPUS then brukeropus will not be able to read it either).

Controlling OPUS Software

brukeropus can send commands and perform queries to an OPUS software instance through the DDE communication protocol. OPUS must be open and logged in on the same PC where brukeropus is called from to operate.

Features

  • Initiate a sample or reference measurement
  • Change/define measurement parameters prior to performing measurement (useful for sweeping parameters like aperture size, mirror velocity, etc.)
  • Send commands for interacting with motors and other accessories (e.g. moving mirrors, rotating polarizers, etc.)
  • Control vacuum operation for vacuum-equipped spectrometers (e.g. Vertex 80V FTIR)
  • Unload files from OPUS software (so they can be unlocked for moving, renaming, etc.)

Usage

from brukeropus import opus, read_opus
from matplotlib import pyplot as plt

opus = Opus()  # Connects to actively running OPUS software

apt_options = opus.get_param_options('apt') # Get all valid aperture settings

for apt in apt_options[2:-2]: # Loop over all but the two smallest and two largest aperature settings
    filepath = opus.measure_sample(apt=apt, nss=10, unload=True) # Perform measurement and unload file from OPUS
    data = read_opus(filepath) # Read OPUS file from measurement
    plt.plot(data.sm.x, data.sm.y, label=apt) # Plot single-channel sample spectra
plt.legend()
plt.show()

Future Plans

  • Continue to improve the file reader towards 100% compliance
  • Parse "PARMTEXT.BIN" file to extract all parameter labels and setup options
  • Add a basic GUI for browsing OPUS files

Installation

Requirements

  • Python 3.6+
  • numpy

Optional

  • matplotlib (for plotting examples)

pip

pip install brukeropus

https://pypi.org/project/brukeropus/

Documentation

https://joshduran.github.io/brukeropus/brukeropus.html

brukeropus's People

Contributors

joshduran avatar

Stargazers

Michael A. avatar Sean Clancy avatar Vikram KVNG avatar

Watchers

 avatar

brukeropus's Issues

Add friendly data keys for unknown type_code[3] entries: 33, 34, 36, 65, 97

These are all multi-channel measurements (e.g. sm-2ch, a-2ch, sm-3ch, rf-4ch) codes. Current version parses the data and assigns matching data status blocks properly, but without readable codes (e.g. sm_33, _36, sm_65, rf_97).

Update the constants and methods for getting data keys to use friendly keys for these codes.

Example files posted in other issues:

spectral-cockpit/opusreader2#67

wincowgerDEV/OpenSpecy-package#118

qedsoftware/brukeropusreader#17

Handle files with duplicate data/data status pairs

Some files will have duplicate data and data status block pairs within the file. One reason could be when "make compatible scalar" option is selected in OPUS.

Currently duplicate data is ignored, but instead an effort should be made to identify the matching data status block between the duplicate entries.

Issue first posted here: stuart-cls/python-opusfc-dist#13

Import Exception for OPUS Control

brukeropus fails to import whenever brukeropus.control.Opus fails to import. This will impact any non-windows users (OPUS control only supported by windows) as well as any specialized configurations for which DDE imports fail to initialize.

For these cases, the Opus class should simply not be imported so that OPUS file reading still functions as expected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.