brukeropus

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 software using the DDE communication protocol)

Installation

brukeropus requires python 3.6+ and numpy, but matplotlib is needed to run the plotting examples. You can install with pip:

pip install brukeropus

Namespace

brukeropus provides direct imports to the following:

from brukeropus import find_opus_files, read_opus, OPUSFile, Opus, parse_file_and_print

All other file functions or classes can be directly imported from the brukeropus.file or brukeropus.control submodules, e.g.:

from brukeropus.file import parse_header

It is recommended that you do not import from the fully qualified namespace, e.g.:

from brukeropus.file.parse import parse_header

as that namespace is subject to change. Instead import directly from brukeropus or its first level submodules.

Reading OPUS Files (Basic Usage)

brukeropus can read the proprietary binary files saved by Bruker's OPUS software.

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

More detailed documentation on the file submodule can be found in brukeropus.file

Controlling OPUS Software (Basic Usage)

brukeropus can also control/communicate directly with OPUS over the DDE communication protocol. For this to work, you must be on Windows and OPUS must be open and logged in.

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()

More detailed documentation on the control submodule can be found in brukeropus.control.

 1'''
 2`brukeropus` is a Python package for interacting with Bruker's OPUS spectroscopy software. Currently, the package can
 3read OPUS data files and communicate/control OPUS software using the DDE communication protocol)
 4
 5### Installation
 6`brukeropus` requires `python 3.6+` and `numpy`, but `matplotlib` is needed to run the plotting examples.  You can
 7install with pip:
 8```python
 9pip install brukeropus
10```
11
12### Namespace
13`brukeropus` provides direct imports to the following:
14```python
15from brukeropus import find_opus_files, read_opus, OPUSFile, Opus, parse_file_and_print
16```
17All other file functions or classes can be directly imported from the `brukeropus.file` or `brukeropus.control`
18submodules, e.g.:
19```python
20from brukeropus.file import parse_header
21```
22It is recommended that you do **not** import from the fully qualified namespace, e.g.:
23```python
24from brukeropus.file.parse import parse_header
25```
26as that namespace is subject to change. Instead import directly from `brukeropus` or its first level submodules.
27
28### Reading OPUS Files (Basic Usage)
29`brukeropus` can read the proprietary binary files saved by Bruker's OPUS software.
30```python
31from brukeropus import read_opus
32from matplotlib import pyplot as plt
33
34opus_file = read_opus('file.0')  # Returns an OPUSFile class
35
36opus_file.print_parameters()  # Pretty prints all metadata in the file to the console
37
38if 'a' in opus_file.data_keys:  # If absorbance spectra was extracted from file
39    plt.plot(opus_file.a.x, opus_file.a.y)  # Plot absorbance spectra
40    plt.title(opus_file.sfm + ' - ' + opus_file.snm)  # Sets plot title to Sample Form - Sample Name
41    plt.show()  # Display plot
42```
43More detailed documentation on the file submodule can be found in `brukeropus.file`
44
45### Controlling OPUS Software (Basic Usage)
46`brukeropus` can also control/communicate directly with OPUS over the DDE communication protocol.  For this to work,
47you must be on Windows and OPUS must be open and logged in.
48```python
49from brukeropus import opus, read_opus
50from matplotlib import pyplot as plt
51
52opus = Opus()  # Connects to actively running OPUS software
53
54apt_options = opus.get_param_options('apt') # Get all valid aperture settings
55
56for apt in apt_options[2:-2]: # Loop over all but the two smallest and two largest aperature settings
57    filepath = opus.measure_sample(apt=apt, nss=10, unload=True) # Perform measurement and unload file from OPUS
58    data = read_opus(filepath) # Read OPUS file from measurement
59    plt.plot(data.sm.x, data.sm.y, label=apt) # Plot single-channel sample spectra
60plt.legend()
61plt.show()
62```
63More detailed documentation on the control submodule can be found in `brukeropus.control`.
64'''
65
66from brukeropus.file import OPUSFile, read_opus, find_opus_files, parse_file_and_print
67
68try:
69    from brukeropus.control import Opus
70except:
71    pass