Import of Bruker OPUS files
Bruker OPUS files have also a proprietary file format. The Opus reader (read_opus()
) of spectrochempy is essentially a wrapper of the python module brukeropus developed by Josh Duran. The use of read_opus()
is similar to that of read_omnic()
.
Basic loading of OPUS file
Individual Opus files can be opened and loaded as a new NDDataset using:
[1]:
import spectrochempy as scp
|
SpectroChemPy's API - v.0.8.2.dev7 ©Copyright 2014-2025 - A.Travert & C.Fernandez @ LCS |
[2]:
Z = scp.read_opus("irdata/OPUS/test.0002")
Z
Running on GitHub Actions
MPL Configuration directory: /home/runner/.config/matplotlib
Stylelib directory: /home/runner/.config/matplotlib/stylelib
[2]:
NDDataset: [float64] a.u. (shape: (y:1, x:2567))[test]
Summary
Spectra type: Absorbance
Data
Dimension `x`
Dimension `y`
[ MCT D317 1mm² [8500 - 700 Cm-1]]
[ /home/runner/.spectrochempy/testdata/irdata/OPUS/test.0002]]
Note: In the previous use of read_opus(), we have assumed that the file is in datadir folder (see the import tutorial or more details on this). If this not the case, you should use an absolute path or a relative path to the current notebook folder.
For multifile loading, one can use:
[3]:
Z1 = scp.read_opus("test.0000", "test.0001", "test.0002", directory="irdata/OPUS")
Z1
[3]:
NDDataset: [float64] a.u. (shape: (y:3, x:2567))[test]
Summary
( test, test, test )
2025-04-27 01:45:47+00:00> Merged from several files
Data
[0.000451 0.0004229 ... 0.5752 0.6311]
[0.0002479 0.0002325 ... 0.5809 0.6376]] a.u.
Dimension `x`
Dimension `y`
[ MCT D317 1mm² [8500 - 700 Cm-1] MCT D317 1mm² [8500 - 700 Cm-1] MCT D317 1mm² [8500 - 700 Cm-1]]
[ /home/runner/.spectrochempy/testdata/irdata/OPUS/test.0000 /home/runner/.spectrochempy/testdata/irdata/OPUS/test.0001
/home/runner/.spectrochempy/testdata/irdata/OPUS/test.0002]]
Note: By default all files in the given directory are merged as a single dataset if they are compatibles (i.e., same shape, same type of experiment…). If they cannot be merged due to imcompatible shape or type, separate datasets are returned with dataset merged in different groups.
For instance in the following, two dataset will be returned:
[4]:
LZ1 = scp.read_opus(
"test.0000", "test.0001", "test.0002", "background.0", directory="irdata/OPUS"
)
LZ1
[4]:
List (len=2, type=NDDataset)
0: NDDataset: [float64] a.u. (shape: (y:3, x:2567))[test]
Summary
( test, test, test )
2025-04-27 01:45:48+00:00> Merged from several files
Data
[0.000451 0.0004229 ... 0.5752 0.6311]
[0.0002479 0.0002325 ... 0.5809 0.6376]] a.u.
Dimension `x`
Dimension `y`
[ MCT D317 1mm² [8500 - 700 Cm-1] MCT D317 1mm² [8500 - 700 Cm-1] MCT D317 1mm² [8500 - 700 Cm-1]]
[ /home/runner/.spectrochempy/testdata/irdata/OPUS/test.0000 /home/runner/.spectrochempy/testdata/irdata/OPUS/test.0001
/home/runner/.spectrochempy/testdata/irdata/OPUS/test.0002]]
1: NDDataset: [float64] unitless (shape: (y:1, x:4096))[background]
Summary
( background )
2025-04-27 01:45:48+00:00> Merged from several files
Data
Dimension `x`
Dimension `y`
[ MCT D317 1mm² [8500 - 700 Cm-1]]
[ /home/runner/.spectrochempy/testdata/irdata/OPUS/background.0]]
Multifile loading can also be achieved by only specifying the directory to read, if all files in a directory must be read:
[5]:
LZ = scp.read_opus("irdata/OPUS")
LZ
[5]:
List (len=2, type=NDDataset)
0: NDDataset: [float64] a.u. (shape: (y:4, x:2567))[test]
Summary
( test )
2025-04-27 01:45:48+00:00> Merged from several files
Data
[0.000451 0.0004229 ... 0.5752 0.6311]
[0.0002479 0.0002325 ... 0.5809 0.6376]
[0.0003685 0.0003442 ... 0.5827 0.6388]] a.u.
Dimension `x`
Dimension `y`
[ MCT D317 1mm² [8500 - 700 Cm-1] MCT D317 1mm² [8500 - 700 Cm-1] MCT D317 1mm² [8500 - 700 Cm-1] MCT D317 1mm² [8500 - 700 Cm-1]]
[ /home/runner/.spectrochempy/testdata/irdata/OPUS/test.0000 /home/runner/.spectrochempy/testdata/irdata/OPUS/test.0001
/home/runner/.spectrochempy/testdata/irdata/OPUS/test.0002 /home/runner/.spectrochempy/testdata/irdata/OPUS/test.0003]]
1: NDDataset: [float64] unitless (shape: (y:1, x:4096))[background]
Summary
( background )
2025-04-27 01:45:48+00:00> Merged from several files
Data
Dimension `x`
Dimension `y`
[ MCT D317 1mm² [8500 - 700 Cm-1]]
[ /home/runner/.spectrochempy/testdata/irdata/OPUS/background.0]]
As previously two datasets are returned due to the imcompatible types and shapes of the experiments.
If one desire to load of files into separate datasets, then set the merge attribute to False.
[6]:
LZ1 = scp.read_opus("irdata/OPUS", merge=False)
LZ1
[6]:
List (len=5, type=NDDataset)
0: NDDataset: [float64] a.u. (shape: (y:1, x:2567))[test]
Summary
Spectra type: Absorbance
Data
Dimension `x`
Dimension `y`
[ MCT D317 1mm² [8500 - 700 Cm-1]]
[ /home/runner/.spectrochempy/testdata/irdata/OPUS/test.0000]]
1: NDDataset: [float64] a.u. (shape: (y:1, x:2567))[test]
Summary
Spectra type: Absorbance
Data
Dimension `x`
Dimension `y`
[ MCT D317 1mm² [8500 - 700 Cm-1]]
[ /home/runner/.spectrochempy/testdata/irdata/OPUS/test.0001]]
2: NDDataset: [float64] a.u. (shape: (y:1, x:2567))[test]
Summary
Spectra type: Absorbance
Data
Dimension `x`
Dimension `y`
[ MCT D317 1mm² [8500 - 700 Cm-1]]
[ /home/runner/.spectrochempy/testdata/irdata/OPUS/test.0002]]
3: NDDataset: [float64] a.u. (shape: (y:1, x:2567))[test]
Summary
Spectra type: Absorbance
Data
Dimension `x`
Dimension `y`
[ MCT D317 1mm² [8500 - 700 Cm-1]]
[ /home/runner/.spectrochempy/testdata/irdata/OPUS/test.0003]]
4: NDDataset: [float64] unitless (shape: (y:1, x:4096))[background]
Summary
Spectra type: Single-channel reference spectra
Data
Dimension `x`
Dimension `y`
[ MCT D317 1mm² [8500 - 700 Cm-1]]
[ /home/runner/.spectrochempy/testdata/irdata/OPUS/background.0]]
Loading given type of OPUS spectra
By default absortion spectra (AB) are load, if present in the file.
Opus file however can contain several types of spectra and they can be retrieved eventually using the correct type in the call to read_opus
:
Types possibly availables and readables by read_opus
are listed here:
AB
: Absorbance (default if present in the file)TR
: TransmittanceKM
: Kubelka-MunkRAM
: RamanEMI
: EmissionRFL
: ReflectanceLRF
: log(Reflectance)ATR
: ATRPAS
: PhotoacousticRF
: Single-channel reference spectraSM
: Single-channel sample spectraIGRF
: Reference interferogramIGSM
: Sample interferogramPHRF
: Reference phasePHSM
: Sample phase
It is possible to know which are the other types availables in the original file:
[7]:
Z.meta.other_data_types
[7]:
['RF', 'IGRF', 'AB', 'SM', 'PHSM', 'IGSM']
Thus if one wants to load the single-channel sample spectra, the read function syntax would be:
[8]:
ZSM = scp.read_opus("irdata/OPUS/test.0002", type="SM")
ZSM
[8]:
NDDataset: [float64] unitless (shape: (y:1, x:2567))[test]
Summary
Spectra type: Single-channel sample spectra
Data
Dimension `x`
Dimension `y`
[ MCT D317 1mm² [8500 - 700 Cm-1]]
[ /home/runner/.spectrochempy/testdata/irdata/OPUS/test.0002]]
Reading OPUS file Metadata
As just seen above, more informations can be obtained on the experiment and spectrometer parameters using the dataset metadata (meta attribute).
For instance, to get a display of all metadata:
[9]:
Z.meta
[9]:
OPUS Parameters
Sample/Result Parameters [params]
Reference Parameters [rf_params]
To display only a sub-group of metadata, you can use :
[10]:
Z.meta.params.fourier_transform
[10]:
Fourier Transform Parameters
or a single parameter:
[11]:
Z.meta.params.optical.bms
[11]:
Beamsplitter
[12]:
Z.meta.params.optical.bms.value
[12]:
'KBr'
Acting on a parameter
Metadata modification, addition, deletion are forbidden by default (readonly=True
).
For instance, if one want to add a new parameters, the following is not permitted and then raise an error:
[13]:
try:
Z.meta.xxx = "forbidden"
except ValueError:
scp.error_("meta data dictionary is read only!")
ERROR | SpectroChemPyError: meta data dictionary is read only!
To add a new value (or to modifify/delete an existing value), the readonly
flag must be unset before the operation:
[14]:
Z.meta.readonly = False
Z.meta.xxx = "permitted"
Z.meta
[14]:
OPUS Parameters
Sample/Result Parameters [params]
Reference Parameters [rf_params]
It is advised to set back the readonly
flag to True.