brukeropus.file
The brukeropus.file
submodule of brukeropus
includes all the functions and classes for reading and exploring OPUS
files. This includes both high-level functions like read_opus
that returns an OPUSFile
class, as well as low-level
parsing functions like parse_directory
that returns data extracted directly from the binary OPUS file bytes. This
overview documentation will focus on the high-level functions which will be useful for most users. If you are
interested in using the low-level parsing functions, perhaps to make your own data class or customize how files are
read, refer to: brukeropus.file.parse
which contains all the low-level parsing functions.
Finding OPUS Files
OPUS files are typically saved with a numeric file extension (e.g. file.0, file.1, file.1001). This makes searching for
a list of OPUS files in a directory a little more cumbersome than a traditional "*.csv" search. To address this,
brukeropus
includes a find_opus_files
function:
from brukeropus import find_opus_files
filepaths = find_opus_files(r'path\to\opus\files', recursive=True)
Which will assign a list of filepaths that match the numeric extension formatting of OPUS files. For full documentation,
see brukeropus.file.utils.find_opus_files
.
Reading OPUS Files
brukeropus
parses OPUS files and assembles them into an OPUSFile
object that contains the extracted data (and
metadata) within the file. You can generate an OPUSFile
object in one of two ways:
from brukeropus import read_opus, OPUSFile
filepath = r'path\to\opusfile.0'
data = read_opus(filepath)
same_data = OPUSFile(filepath)
In the above code, data
and same_data
are both OPUSFile
objects with identical data.
Using the OPUSFile
Class
OPUS files all start with the same first four magic bytes. If the file does not start with these bytes (i.e. is not
a valid OPUS file), the OPUSFile
class will logically evaluate to false
:
data = read_opus('file.pdf')
if data:
print(data)
else:
print(data.filepath, 'is not an OPUS file')
To view all parameter metadata in the file, you can print to the console using the class method: print_parameters
.
This will let you view all the key, value parameter data extracted from the file with labels for what the parameter keys
are referring to wherever known.
data = read_opus('file.0')
data.print_parameters()
Example
print_parameters
Output
====================================================================================================
Sample/Result Parameters (params)
....................................................................................................
Optical Parameters
Key Label Value
ACC Accessory TRANS *010A984F
APR ATR Pressure 0
APT Aperture Setting 1 mm
BMS Beamsplitter KBr-Broadband
CHN Measurement Channel Sample Compartment
DTC Detector RT-DLaTGS [Internal Pos.1]
HPF High Pass Filter 0
LPF Low Pass Filter 10.0
LPV Variable Low Pass Filter (cm-1) 4000
OPF Optical Filter Setting Open
PGN Preamplifier Gain 3
RDX Extended Ready Check 0
SRC Source MIR
VEL Scanner Velocity 10.0
ADC External Analog Signals 0
SON External Sync Off
....................................................................................................
Fourier Transform Parameters
Key Label Value
APF Apodization Function B3
HFQ End Frequency Limit for File 500.0
LFQ Start Frequency Limit for File 10000.0
NLI Nonlinearity Correction 0
PHR Phase Resolution 100.0
PHZ Phase Correction Mode ML
SPZ Stored Phase Mode NO
ZFF Zero Filling Factor 2
....................................................................................................
Acquisition Parameters
Key Label Value
ADT Additional Data Treatment 0
AQM Acquisition Mode DD
CFE Low Intensity Power Mode with DTGS 0
COR Correlation Test Mode 0
DEL Delay Before Measurement 0
DLY Stabilization Delay 0
HFW Wanted High Freq Limit 15000.0
LFW Wanted Low Freq Limit 0.0
NSS Number of Sample Scans 50
PLF Result Spectrum Type AB
RES Resolution (cm-1) 4.0
SOT Sample Scans or Time 0
TCL Command Line for Additional Data Tr...
TDL To Do List 16777271
SGN Sample Signal Gain 1
....................................................................................................
Sample Origin Parameters
Key Label Value
BLD Building
CNM Operator Name Duran
CPY Company
DPM Department
EXP Experiment MWIR-LWIR_Trans_FileNameFormat.XPM
LCT Location
SFM Sample Form Atm-MWIR (All A)
SNM Sample Name File Test
XPP Experiment Path C:\Users\Public\Documents\Bruker\OPUS_8.1.29\XPM
IST Instrument Status OK
CPG Character Encoding Code Page 1252
UID Universally Unique Identifier 0d1348c2-3a2c-41c9-b521-bdaf0a23710c
....................................................................................................
Instrument Status Parameters
Key Label Value
HFL High Folding Limit 15795.820598
LFL Low Folding Limit 0.0
LWN Laser Wavenumber 15795.820598
ABP Absolute Peak Pos in Laser*2 52159
SSP Sample Spacing Divisor 1
ASG Actual Signal Gain 1
ARG Actual Reference Gain 1
ASS Number of Sample Scans 50
GFW Number of Good Forward Scans 25
GBW Number of Good Backward Scans 25
BFW Number of Bad Forward Scans 0
BBW Number of Bad Backward Scans 0
PKA Peak Amplitude 1409
PKL Peak Location 7364
PRA Backward Peak Amplitude 1356
PRL Backward Peak Location 7363
P2A Peak Amplitude Channel 2 1
P2L Peak Location Channel 2 1
P2R Backward Peak Amplitude Channel 2 1
P2K Backward Peak Location Channel 2 1
DAQ Data Acquisition Status 0
AG2 Actual Signal Gain Channel 2 1
HUM Relative Humidity Interferometer 14
SSM Sample Spacing Multiplier 1
RSN Running Sample Number 565
CRR Correlation Rejection Reason 0
SRT Start Time (sec) 1556890484.642
DUR Duration (sec) 42.433990478515625
TSC Scanner Temperature 27.8
MVD Max Velocity Deviation 0.1158025860786438
PRS Pressure Interferometer (hPa) 1009.9999700000001
AN1 Analog Signal 1 0.22596596493037535
AN2 Analog Signal 2 3.459206583321489
VSN Firmware Version 2.450 Oct 10 2014
SRN Instrument Serial Number 1135
CAM Coaddition Mode 0
INS Instrument Type VERTEX 80V
FOC Focal Length 100.0
RDY Ready Check 1
====================================================================================================
Reference Parameters (rf_params)
....................................................................................................
Reference Instrument Status Parameters
Key Label Value
HFL High Folding Limit 15795.820598
LFL Low Folding Limit 0.0
LWN Laser Wavenumber 15795.820598
ABP Absolute Peak Pos in Laser*2 52159
SSP Sample Spacing Divisor 1
ARG Actual Reference Gain 1
ASG Actual Signal Gain 1
ASS Number of Sample Scans 1
GFW Number of Good Forward Scans 1
GBW Number of Good Backward Scans 0
BFW Number of Bad Forward Scans 0
BBW Number of Bad Backward Scans 0
PKA Peak Amplitude 1644
PKL Peak Location 7364
PRA Backward Peak Amplitude 1
PRL Backward Peak Location -1
P2A Peak Amplitude Channel 2 1
P2L Peak Location Channel 2 1
P2R Backward Peak Amplitude Channel 2 1
P2K Backward Peak Location Channel 2 1
DAQ Data Acquisition Status 0
AG2 Actual Signal Gain Channel 2 1
HUM Relative Humidity Interferometer 0
SSM Sample Spacing Multiplier 1
RSN Running Sample Number 5816
CRR Correlation Rejection Reason 0
SRT Start Time (sec) 1556890282.358
DUR Duration (sec) 0.7919998168945312
TSC Scanner Temperature 27.8
MVD Max Velocity Deviation 0.10553144663572311
PRS Pressure Interferometer (hPa) 2.01999
AN1 Analog Signal 1 0.22577181458473206
AN2 Analog Signal 2 4.0960001945495605
VSN Firmware Version 2.450 Oct 10 2014
SRN Instrument Serial Number 1135
CAM Coaddition Mode 0
INS Instrument Type VERTEX 80V
FOC Focal Length 100.0
RDY Ready Check 1
ARS Number of Reference Scans 1
....................................................................................................
Reference Optical Parameters
Key Label Value
ACC Accessory TRANS *010A984F
APR ATR Pressure 0
APT Aperture Setting 1 mm
BMS Beamsplitter KBr-Broadband
DTC Detector RT-DLaTGS [Internal Pos.1]
HPF High Pass Filter 0
LPF Low Pass Filter 10.0
LPV Variable Low Pass Filter (cm-1) 4000
OPF Optical Filter Setting Open
PGR Reference Preamplifier Gain 3
RCH Reference Measurement Channel Sample Compartment
RDX Extended Ready Check 0
SRC Source MIR
VEL Scanner Velocity 10.0
ADC External Analog Signals 0
SON External Sync Off
....................................................................................................
Reference Acquisition Parameters
Key Label Value
ADT Additional Data Treatment 0
AQM Acquisition Mode DD
CFE Low Intensity Power Mode with DTGS 0
COR Correlation Test Mode 0
DEL Delay Before Measurement 0
DLY Stabilization Delay 0
HFW Wanted High Freq Limit 15000.0
LFW Wanted Low Freq Limit 0.0
NSR Number of Background Scans 1
PLF Result Spectrum Type TR
RES Resolution (cm-1) 4.0
RGN Reference Signal Gain 1
STR Scans or Time (Reference) 0
TCL Command Line for Additional Data Tr...
TDL To Do List 16777271
....................................................................................................
Reference Fourier Transform Parameters
Key Label Value
APF Apodization Function B3
HFQ End Frequency Limit for File 500.0
LFQ Start Frequency Limit for File 10000.0
NLI Nonlinearity Correction 0
PHR Phase Resolution 100.0
PHZ Phase Correction Mode ML
SPZ Stored Phase Mode NO
ZFF Zero Filling Factor 2
You can access the sample parameters through the OPUSFile.params
attribute, or as a direct attribute for shorthand
(e.g. OPUSFile.params.apt
or OPUSFile.apt
). The parameter keys are also case insensitive (e.g. OPUSFile.bms
or
OPUSFile.BMS
).
OPUS files can also contain parameter information about the associated reference (aka background) measurement. These
parameters are only accessible through the OPUSFile.rf_params
attribute to avoid namespace collisions (e.g.
OPUSFile.rf_params.apt
).
data = read_opus('file.0')
print('Sample ZFF:', data.zff, 'Reference ZFF:', data.rf_params.zff)
Sample ZFF: 2 Reference ZFF: 2
You can also get the human-readable label for a parameter key using the get_param_label
function:
from brukeropus.file import get_param_label
data = read_opus('file.0')
print(get_param_label('bms') + ':', data.bms)
print(get_param_label('src') + ':', data.src)
Beamsplitter: KBr-Broadband
Source: MIR
You can also iterate over the parameters using the familiar keys()
, values()
, and items()
functions using the
params
or rf_params
attributes (just like a dictionary):
data = read_opus('file.0')
for key, val in data.params.items():
print(key + ':', val)
acc: TRANS *010A984F
apr: 0
apt: 1 mm
bms: KBr-Broadband
chn: Sample Compartment
dtc: RT-DLaTGS [Internal Pos.1]
hpf: 0
lpf: 10.0
lpv: 4000
opf: Open
pgn: 3
... continued ...
Depending on the settings used to save the OPUS file, different data blocks can be stored. To retrieve a list of data
blocks stored in the OPUS File, you can use the all_data_keys
attribute:
data = read_opus('file.0')
print(data.all_data_keys)
['igsm', 'phsm', 'sm', 'a', 'igrf', 'rf']
Each key is also an attribute of the OPUSFile
instance that returns either a Data
(single spectra) or DataSeries
(series of spectra) class. You can use the data_keys
attribute to retrieve a list of only the single-spectra Data
keys in the class, or the series_keys
attribute to retrieve a list of only the DataSeries
keys.
You can also iterate over these data keys using the iter_all_data()
, iter_data()
and iter_series()
class
methods:
data = read_opus('file.0')
for d in data.iter_data():
print(d.label, '(' + d.datetime.isoformat(' ') + ')')
Sample Interferogram (2019-05-03 13:34:44.641000)
Sample Phase (2019-05-03 13:34:44.641000)
Sample Spectrum (2019-05-03 13:34:44.641000)
Absorbance (2019-05-03 13:34:44.641000)
Reference Interferogram (2019-05-03 13:31:22.358000)
Reference Spectrum (2019-05-03 13:31:22.358000)
You can access the x
and y
arrays of a Data
or DataSeries
class:
data = read_opus('file.0')
plt.plot(data.a.x, data.a.y) # Plot absorbance
plt.ylim((0, 1))
plt.show()
For spectra with wavenumber as valid unit (e.g. single-channel or ratioed spectra), the x
array can be given in
wavenumber [cm⁻¹
] or wavelength [µm
] or modulation frequency [Hz
] units by using the attributes wn
, wl
, or f
respectively:
data = read_opus('file.0')
plt.plot(data.sm.wl, data.sm.y)
plt.show()
Each data block in an OPUS file also contains a small parameter block with information such as the min/max y-value
(mny, mxy), x-units (dxu), number of data points (npt), etc. These can be accessed as direct attributes to the Data
class, or through the Data.params
attribute:
data = read_opus('file.0')
print('Sample spectra y-min:', data.sm.mny, 'y-max:', data.sm.mxy)
Sample spectra y-min: 1.2147593224653974e-05 y-max: 0.03543896973133087
For full API documentation, see:
OPUSFile
: brukeropus.file.file.OPUSFile
Data
: brukeropus.file.file.Data
DataSeries
: brukeropus.file.file.DataSeries
1''' 2The `brukeropus.file` submodule of `brukeropus` includes all the functions and classes for reading and exploring OPUS 3files. This includes both high-level functions like `read_opus` that returns an `OPUSFile` class, as well as low-level 4parsing functions like `parse_directory` that returns data extracted directly from the binary OPUS file bytes. This 5overview documentation will focus on the high-level functions which will be useful for most users. If you are 6interested in using the low-level parsing functions, perhaps to make your own data class or customize how files are 7read, refer to: `brukeropus.file.parse` which contains all the low-level parsing functions. 8## Finding OPUS Files 9OPUS files are typically saved with a numeric file extension (e.g. file.0, file.1, file.1001). This makes searching for 10a list of OPUS files in a directory a little more cumbersome than a traditional "*.csv" search. To address this, 11`brukeropus` includes a `find_opus_files` function: 12```python 13from brukeropus import find_opus_files 14 15filepaths = find_opus_files(r'path\\to\\opus\\files', recursive=True) 16``` 17Which will assign a list of filepaths that match the numeric extension formatting of OPUS files. For full documentation, 18see `brukeropus.file.utils.find_opus_files`. 19## Reading OPUS Files 20`brukeropus` parses OPUS files and assembles them into an `OPUSFile` object that contains the extracted data (and 21metadata) within the file. You can generate an `OPUSFile` object in one of two ways: 22```python 23from brukeropus import read_opus, OPUSFile 24 25filepath = r'path\\to\\opusfile.0' 26 27data = read_opus(filepath) 28same_data = OPUSFile(filepath) 29``` 30In the above code, `data` and `same_data` are both `OPUSFile` objects with identical data. 31## Using the `OPUSFile` Class 32OPUS files all start with the same first four *magic bytes*. If the file does not start with these bytes (i.e. is not 33a valid OPUS file), the `OPUSFile` class will logically evaluate to `false`: 34```python 35data = read_opus('file.pdf') 36if data: 37 print(data) 38else: 39 print(data.filepath, 'is not an OPUS file') 40``` 41To view all parameter metadata in the file, you can print to the console using the class method: `print_parameters`. 42This will let you view all the key, value parameter data extracted from the file with labels for what the parameter keys 43are referring to wherever known. 44 45```python 46data = read_opus('file.0') 47data.print_parameters() 48``` 49<details> 50<summary>Example `print_parameters` Output</summary> 51<p> 52```console 53==================================================================================================== 54 Sample/Result Parameters (params) 55 56.................................................................................................... 57 Optical Parameters 58Key Label Value 59ACC Accessory TRANS *010A984F 60APR ATR Pressure 0 61APT Aperture Setting 1 mm 62BMS Beamsplitter KBr-Broadband 63CHN Measurement Channel Sample Compartment 64DTC Detector RT-DLaTGS [Internal Pos.1] 65HPF High Pass Filter 0 66LPF Low Pass Filter 10.0 67LPV Variable Low Pass Filter (cm-1) 4000 68OPF Optical Filter Setting Open 69PGN Preamplifier Gain 3 70RDX Extended Ready Check 0 71SRC Source MIR 72VEL Scanner Velocity 10.0 73ADC External Analog Signals 0 74SON External Sync Off 75 76.................................................................................................... 77 Fourier Transform Parameters 78Key Label Value 79APF Apodization Function B3 80HFQ End Frequency Limit for File 500.0 81LFQ Start Frequency Limit for File 10000.0 82NLI Nonlinearity Correction 0 83PHR Phase Resolution 100.0 84PHZ Phase Correction Mode ML 85SPZ Stored Phase Mode NO 86ZFF Zero Filling Factor 2 87 88.................................................................................................... 89 Acquisition Parameters 90Key Label Value 91ADT Additional Data Treatment 0 92AQM Acquisition Mode DD 93CFE Low Intensity Power Mode with DTGS 0 94COR Correlation Test Mode 0 95DEL Delay Before Measurement 0 96DLY Stabilization Delay 0 97HFW Wanted High Freq Limit 15000.0 98LFW Wanted Low Freq Limit 0.0 99NSS Number of Sample Scans 50 100PLF Result Spectrum Type AB 101RES Resolution (cm-1) 4.0 102SOT Sample Scans or Time 0 103TCL Command Line for Additional Data Tr... 104TDL To Do List 16777271 105SGN Sample Signal Gain 1 106 107.................................................................................................... 108 Sample Origin Parameters 109Key Label Value 110BLD Building 111CNM Operator Name Duran 112CPY Company 113DPM Department 114EXP Experiment MWIR-LWIR_Trans_FileNameFormat.XPM 115LCT Location 116SFM Sample Form Atm-MWIR (All A) 117SNM Sample Name File Test 118XPP Experiment Path C:\\Users\\Public\\Documents\\Bruker\\OPUS_8.1.29\\XPM 119IST Instrument Status OK 120CPG Character Encoding Code Page 1252 121UID Universally Unique Identifier 0d1348c2-3a2c-41c9-b521-bdaf0a23710c 122 123.................................................................................................... 124 Instrument Status Parameters 125Key Label Value 126HFL High Folding Limit 15795.820598 127LFL Low Folding Limit 0.0 128LWN Laser Wavenumber 15795.820598 129ABP Absolute Peak Pos in Laser*2 52159 130SSP Sample Spacing Divisor 1 131ASG Actual Signal Gain 1 132ARG Actual Reference Gain 1 133ASS Number of Sample Scans 50 134GFW Number of Good Forward Scans 25 135GBW Number of Good Backward Scans 25 136BFW Number of Bad Forward Scans 0 137BBW Number of Bad Backward Scans 0 138PKA Peak Amplitude 1409 139PKL Peak Location 7364 140PRA Backward Peak Amplitude 1356 141PRL Backward Peak Location 7363 142P2A Peak Amplitude Channel 2 1 143P2L Peak Location Channel 2 1 144P2R Backward Peak Amplitude Channel 2 1 145P2K Backward Peak Location Channel 2 1 146DAQ Data Acquisition Status 0 147AG2 Actual Signal Gain Channel 2 1 148HUM Relative Humidity Interferometer 14 149SSM Sample Spacing Multiplier 1 150RSN Running Sample Number 565 151CRR Correlation Rejection Reason 0 152SRT Start Time (sec) 1556890484.642 153DUR Duration (sec) 42.433990478515625 154TSC Scanner Temperature 27.8 155MVD Max Velocity Deviation 0.1158025860786438 156PRS Pressure Interferometer (hPa) 1009.9999700000001 157AN1 Analog Signal 1 0.22596596493037535 158AN2 Analog Signal 2 3.459206583321489 159VSN Firmware Version 2.450 Oct 10 2014 160SRN Instrument Serial Number 1135 161CAM Coaddition Mode 0 162INS Instrument Type VERTEX 80V 163FOC Focal Length 100.0 164RDY Ready Check 1 165 166==================================================================================================== 167 Reference Parameters (rf_params) 168 169.................................................................................................... 170 Reference Instrument Status Parameters 171Key Label Value 172HFL High Folding Limit 15795.820598 173LFL Low Folding Limit 0.0 174LWN Laser Wavenumber 15795.820598 175ABP Absolute Peak Pos in Laser*2 52159 176SSP Sample Spacing Divisor 1 177ARG Actual Reference Gain 1 178ASG Actual Signal Gain 1 179ASS Number of Sample Scans 1 180GFW Number of Good Forward Scans 1 181GBW Number of Good Backward Scans 0 182BFW Number of Bad Forward Scans 0 183BBW Number of Bad Backward Scans 0 184PKA Peak Amplitude 1644 185PKL Peak Location 7364 186PRA Backward Peak Amplitude 1 187PRL Backward Peak Location -1 188P2A Peak Amplitude Channel 2 1 189P2L Peak Location Channel 2 1 190P2R Backward Peak Amplitude Channel 2 1 191P2K Backward Peak Location Channel 2 1 192DAQ Data Acquisition Status 0 193AG2 Actual Signal Gain Channel 2 1 194HUM Relative Humidity Interferometer 0 195SSM Sample Spacing Multiplier 1 196RSN Running Sample Number 5816 197CRR Correlation Rejection Reason 0 198SRT Start Time (sec) 1556890282.358 199DUR Duration (sec) 0.7919998168945312 200TSC Scanner Temperature 27.8 201MVD Max Velocity Deviation 0.10553144663572311 202PRS Pressure Interferometer (hPa) 2.01999 203AN1 Analog Signal 1 0.22577181458473206 204AN2 Analog Signal 2 4.0960001945495605 205VSN Firmware Version 2.450 Oct 10 2014 206SRN Instrument Serial Number 1135 207CAM Coaddition Mode 0 208INS Instrument Type VERTEX 80V 209FOC Focal Length 100.0 210RDY Ready Check 1 211ARS Number of Reference Scans 1 212 213.................................................................................................... 214 Reference Optical Parameters 215Key Label Value 216ACC Accessory TRANS *010A984F 217APR ATR Pressure 0 218APT Aperture Setting 1 mm 219BMS Beamsplitter KBr-Broadband 220DTC Detector RT-DLaTGS [Internal Pos.1] 221HPF High Pass Filter 0 222LPF Low Pass Filter 10.0 223LPV Variable Low Pass Filter (cm-1) 4000 224OPF Optical Filter Setting Open 225PGR Reference Preamplifier Gain 3 226RCH Reference Measurement Channel Sample Compartment 227RDX Extended Ready Check 0 228SRC Source MIR 229VEL Scanner Velocity 10.0 230ADC External Analog Signals 0 231SON External Sync Off 232 233.................................................................................................... 234 Reference Acquisition Parameters 235Key Label Value 236ADT Additional Data Treatment 0 237AQM Acquisition Mode DD 238CFE Low Intensity Power Mode with DTGS 0 239COR Correlation Test Mode 0 240DEL Delay Before Measurement 0 241DLY Stabilization Delay 0 242HFW Wanted High Freq Limit 15000.0 243LFW Wanted Low Freq Limit 0.0 244NSR Number of Background Scans 1 245PLF Result Spectrum Type TR 246RES Resolution (cm-1) 4.0 247RGN Reference Signal Gain 1 248STR Scans or Time (Reference) 0 249TCL Command Line for Additional Data Tr... 250TDL To Do List 16777271 251 252.................................................................................................... 253 Reference Fourier Transform Parameters 254Key Label Value 255APF Apodization Function B3 256HFQ End Frequency Limit for File 500.0 257LFQ Start Frequency Limit for File 10000.0 258NLI Nonlinearity Correction 0 259PHR Phase Resolution 100.0 260PHZ Phase Correction Mode ML 261SPZ Stored Phase Mode NO 262ZFF Zero Filling Factor 2 263``` 264</p> 265</details> 266 267You can access the sample parameters through the `OPUSFile.params` attribute, or as a direct attribute for shorthand 268(e.g. `OPUSFile.params.apt` or `OPUSFile.apt`). The parameter keys are also case insensitive (e.g. `OPUSFile.bms` or 269`OPUSFile.BMS`). 270 271OPUS files can also contain parameter information about the associated reference (aka background) measurement. These 272parameters are only accessible through the `OPUSFile.rf_params` attribute to avoid namespace collisions (e.g. 273`OPUSFile.rf_params.apt`). 274 275```python 276data = read_opus('file.0') 277print('Sample ZFF:', data.zff, 'Reference ZFF:', data.rf_params.zff) 278``` 279```console 280Sample ZFF: 2 Reference ZFF: 2 281``` 282 283You can also get the human-readable label for a parameter key using the `get_param_label` function: 284 285```python 286from brukeropus.file import get_param_label 287data = read_opus('file.0') 288print(get_param_label('bms') + ':', data.bms) 289print(get_param_label('src') + ':', data.src) 290``` 291```console 292Beamsplitter: KBr-Broadband 293Source: MIR 294``` 295 296You can also iterate over the parameters using the familiar `keys()`, `values()`, and `items()` functions using the 297`params` or `rf_params` attributes (just like a dictionary): 298 299```python 300data = read_opus('file.0') 301for key, val in data.params.items(): 302 print(key + ':', val) 303``` 304```console 305acc: TRANS *010A984F 306apr: 0 307apt: 1 mm 308bms: KBr-Broadband 309chn: Sample Compartment 310dtc: RT-DLaTGS [Internal Pos.1] 311hpf: 0 312lpf: 10.0 313lpv: 4000 314opf: Open 315pgn: 3 316... continued ... 317``` 318 319Depending on the settings used to save the OPUS file, different data blocks can be stored. To retrieve a list of data 320blocks stored in the OPUS File, you can use the `all_data_keys` attribute: 321 322```python 323data = read_opus('file.0') 324print(data.all_data_keys) 325``` 326```console 327['igsm', 'phsm', 'sm', 'a', 'igrf', 'rf'] 328``` 329 330Each key is also an attribute of the `OPUSFile` instance that returns either a `Data` (single spectra) or `DataSeries` 331(series of spectra) class. You can use the `data_keys` attribute to retrieve a list of only the single-spectra `Data` 332keys in the class, or the `series_keys` attribute to retrieve a list of only the `DataSeries` keys. 333 334You can also iterate over these data keys using the `iter_all_data()`, `iter_data()` and `iter_series()` class 335methods: 336 337```python 338data = read_opus('file.0') 339for d in data.iter_data(): 340 print(d.label, '(' + d.datetime.isoformat(' ') + ')') 341``` 342```console 343Sample Interferogram (2019-05-03 13:34:44.641000) 344Sample Phase (2019-05-03 13:34:44.641000) 345Sample Spectrum (2019-05-03 13:34:44.641000) 346Absorbance (2019-05-03 13:34:44.641000) 347Reference Interferogram (2019-05-03 13:31:22.358000) 348Reference Spectrum (2019-05-03 13:31:22.358000) 349``` 350 351You can access the `x` and `y` arrays of a `Data` or `DataSeries` class: 352 353```python 354data = read_opus('file.0') 355plt.plot(data.a.x, data.a.y) # Plot absorbance 356plt.ylim((0, 1)) 357plt.show() 358``` 359 360For spectra with wavenumber as valid unit (e.g. single-channel or ratioed spectra), the `x` array can be given in 361wavenumber [`cm⁻¹`] or wavelength [`µm`] or modulation frequency [`Hz`] units by using the attributes `wn`, `wl`, or `f` 362respectively: 363 364```python 365data = read_opus('file.0') 366plt.plot(data.sm.wl, data.sm.y) 367plt.show() 368``` 369 370Each data block in an OPUS file also contains a small parameter block with information such as the min/max y-value 371(mny, mxy), x-units (dxu), number of data points (npt), etc. These can be accessed as direct attributes to the `Data` 372class, or through the `Data.params` attribute: 373 374```python 375data = read_opus('file.0') 376print('Sample spectra y-min:', data.sm.mny, 'y-max:', data.sm.mxy) 377``` 378```console 379Sample spectra y-min: 1.2147593224653974e-05 y-max: 0.03543896973133087 380``` 381For full API documentation, see: 382`OPUSFile`: `brukeropus.file.file.OPUSFile` 383`Data`: `brukeropus.file.file.Data` 384`DataSeries`: `brukeropus.file.file.DataSeries` 385''' 386from brukeropus.file.file import * 387from brukeropus.file.block import * 388from brukeropus.file.parse import * 389from brukeropus.file.labels import * 390from brukeropus.file.utils import * 391from brukeropus.file.constants import *