diff --git a/brukeropus/file/file.py b/brukeropus/file/file.py index ac678d0..3d70fa4 100644 --- a/brukeropus/file/file.py +++ b/brukeropus/file/file.py @@ -161,9 +161,10 @@ class FileBlockInfo: start: pointer to start location of the block within the file keys: tuple of three char keys contained in parameter blocks. This attribute is set by the OPUSFile class only when the block is parameter block. This enables grouping parameters by block if desired. + bytes: raw bytes of file block (currently only set for unknown blocks) ''' - __slots__ = ('type', 'size', 'start', 'keys') + __slots__ = ('type', 'size', 'start', 'keys', 'bytes') keys: tuple @@ -176,10 +177,6 @@ def __str__(self): label = self.get_label() return 'Block Info: ' + label + ' (size: ' + str(self.size) + ' bytes; start: ' + str(self.start) + ')' - def is_valid(self): - '''Returns False if FileBlockInfo is undefined (i.e. FileBlockInfo.type == (0, 0, 0, 0, 0, 0))''' - return self.type != (0, 0, 0, 0, 0, 0) - def is_data_status(self): '''Returns True if FileBlockInfo is a data status parameter block''' return self.type[2] == 1 @@ -190,7 +187,7 @@ def is_rf_param(self): def is_param(self): '''Returns True if FileBlockInfo is a parameter block''' - return self.type[2] > 1 + return self.type[2] > 1 or self.type == (0, 0, 0, 0, 0, 1) def is_directory(self): '''Returns True if FileBlockInfo is the directory block''' @@ -202,7 +199,7 @@ def is_file_log(self): def is_data(self): '''Returns True if FileBlockInfo is a data block or 3D data block''' - return self.type[2] == 0 and self.type[3] > 0 and self.type[3] != 13 + return self.type[0] > 0 and self.type[1] > 0 and self.type[2] == 0 and self.type[3] > 0 def is_3d_data(self): '''Returns True if FileBlockInfo is a 3D data block (i.e. data series)''' @@ -466,10 +463,12 @@ class FileDirectory: file_log_block: `FileBlockInfo` of the file log (changes, etc.) data_and_status_block_pairs: (data: `FileBlockInfo`, data_status: `FileBlockInfo`) which pairs the data status parameter block (time, x units, y units, etc.) with the data block it informs + unknown_blocks: list of `FileBlockInfo` with an unrecognized type (i.e. not sure how to parse) ''' __slots__ = ('version', 'start', 'max_blocks', 'num_blocks', 'data_blocks', 'data_status_blocks', 'param_blocks', - 'rf_param_blocks', 'directory_block', 'file_log_block', 'data_and_status_block_pairs') + 'rf_param_blocks', 'directory_block', 'file_log_block', 'data_and_status_block_pairs', + 'unknown_blocks') def __init__(self, filebytes: bytes): self.version, self.start, self.max_blocks, self.num_blocks = parse_header(filebytes) @@ -479,6 +478,7 @@ def __init__(self, filebytes: bytes): self.rf_param_blocks: list = [] self.directory_block: FileBlockInfo self.file_log_block: FileBlockInfo + self.unknown_blocks: list = [] for block_type, size, start in parse_directory(filebytes, self.start, self.num_blocks): block = FileBlockInfo(block_type=block_type, size=size, start=start) if block.is_data_status(): @@ -491,8 +491,11 @@ def __init__(self, filebytes: bytes): self.directory_block = block elif block.is_file_log(): self.file_log_block = block - elif block.is_valid(): + elif block.is_data(): self.data_blocks.append(block) + else: + block.bytes = filebytes[block.start:block.start + block.size] + self.unknown_blocks.append(block) self.data_and_status_block_pairs = [] self._pair_data_and_status_blocks() diff --git a/brukeropus/file/utils.py b/brukeropus/file/utils.py index a5965e2..54e218a 100644 --- a/brukeropus/file/utils.py +++ b/brukeropus/file/utils.py @@ -199,7 +199,7 @@ def _parse_block_and_print(filebytes, block_info, width): param_col_labels = ('Key', 'Friendly Name', 'Value') if block_info[0] != (0, 0, 0, 13, 0, 0): _print_block_header(get_block_type_label(block_info[0]), width) - if block_info[0][2] > 0: + if block_info[0][2] > 0 or block_info[0] == (0, 0, 0, 0, 0, 1): _print_cols(param_col_labels, param_col_widths) for key, val in parse_param_block(filebytes, block_info[1], block_info[2]): _print_cols((key, get_param_label(key), val), param_col_widths) @@ -213,12 +213,12 @@ def _parse_block_and_print(filebytes, block_info, width): _print_centered('Num Blocks: ' + str(data['num_blocks']), width) _print_centered('Store Table: ' + str(data['store_table']), width) print(data['y']) - elif block_info[0] == (0, 0, 0, 0, 0, 0): - _print_centered('Undefined Block Type: Raw Bytes', width) - print(filebytes[block_info[1]: block_info[1] + block_info[2]]) - else: + elif block_info[0][0] > 0 and block_info[0][1] > 0 and block_info[0][2] == 0 and block_info[0][3] > 0: array = parse_data_block(filebytes, block_info[1], block_info[2]) print(array) + else: + _print_centered('Undefined Block Type: Raw Bytes', width) + print(filebytes[block_info[2]: block_info[2] + block_info[1]]) def _print_cols(vals, col_widths,): diff --git a/docs/brukeropus/control/dde.html b/docs/brukeropus/control/dde.html index 55d1a20..fcc43e7 100644 --- a/docs/brukeropus/control/dde.html +++ b/docs/brukeropus/control/dde.html @@ -1365,7 +1365,11 @@
171 def __init__(self, block_type: tuple, size: int, start: int): -172 self.type = block_type -173 self.size = size -174 self.start = start +@@ -1299,28 +1409,6 @@172 def __init__(self, block_type: tuple, size: int, start: int): +173 self.type = block_type +174 self.size = size +175 self.start = startAttributes:
-
180 def is_valid(self): -181 '''Returns False if FileBlockInfo is undefined (i.e. FileBlockInfo.type == (0, 0, 0, 0, 0, 0))''' -182 return self.type != (0, 0, 0, 0, 0, 0) -
Returns False if FileBlockInfo is undefined (i.e. FileBlockInfo.type == (0, 0, 0, 0, 0, 0))
-184 def is_data_status(self): -185 '''Returns True if FileBlockInfo is a data status parameter block''' -186 return self.type[2] == 1 +@@ -1355,9 +1443,9 @@181 def is_data_status(self): +182 '''Returns True if FileBlockInfo is a data status parameter block''' +183 return self.type[2] == 1Attributes:
188 def is_rf_param(self): -189 '''Returns True if FileBlockInfo is a parameter block associated with the reference measurement''' -190 return self.type[2] > 1 and self.type[1] == 2 +@@ -1377,9 +1465,9 @@185 def is_rf_param(self): +186 '''Returns True if FileBlockInfo is a parameter block associated with the reference measurement''' +187 return self.type[2] > 1 and self.type[1] == 2Attributes:
192 def is_param(self): -193 '''Returns True if FileBlockInfo is a parameter block''' -194 return self.type[2] > 1 +@@ -1399,9 +1487,9 @@189 def is_param(self): +190 '''Returns True if FileBlockInfo is a parameter block''' +191 return self.type[2] > 1 or self.type == (0, 0, 0, 0, 0, 1)Attributes:
196 def is_directory(self): -197 '''Returns True if FileBlockInfo is the directory block''' -198 return self.type == (0, 0, 0, 13, 0, 0) +@@ -1421,9 +1509,9 @@193 def is_directory(self): +194 '''Returns True if FileBlockInfo is the directory block''' +195 return self.type == (0, 0, 0, 13, 0, 0)Attributes:
200 def is_file_log(self): -201 '''Returns True if FileBlockInfo is the file log block''' -202 return self.type == (0, 0, 0, 0, 0, 5) +@@ -1443,9 +1531,9 @@197 def is_file_log(self): +198 '''Returns True if FileBlockInfo is the file log block''' +199 return self.type == (0, 0, 0, 0, 0, 5)Attributes:
204 def is_data(self): -205 '''Returns True if FileBlockInfo is a data block or 3D data block''' -206 return self.type[2] == 0 and self.type[3] > 0 and self.type[3] != 13 +@@ -1465,9 +1553,9 @@201 def is_data(self): +202 '''Returns True if FileBlockInfo is a data block or 3D data block''' +203 return self.type[0] > 0 and self.type[1] > 0 and self.type[2] == 0 and self.type[3] > 0Attributes:
208 def is_3d_data(self): -209 '''Returns True if FileBlockInfo is a 3D data block (i.e. data series)''' -210 return self.is_data() and self.type[5] == 2 +@@ -1487,19 +1575,19 @@205 def is_3d_data(self): +206 '''Returns True if FileBlockInfo is a 3D data block (i.e. data series)''' +207 return self.is_data() and self.type[5] == 2Attributes:
212 def is_data_status_match(self, data_block_info): -213 '''Returns True if FileBlockInfo is a data status block and a match to the data_block_info argument. +@@ -1534,9 +1622,9 @@209 def is_data_status_match(self, data_block_info): +210 '''Returns True if FileBlockInfo is a data status block and a match to the data_block_info argument. +211 +212 This function is used to match a data status block (contains metadata for data block) with its associated data +213 block (contains array data). 214 -215 This function is used to match a data status block (contains metadata for data block) with its associated data -216 block (contains array data). +215 Args: +216 data_block_info (FileBlockInfo): data block being tested as a match. 217 -218 Args: -219 data_block_info (FileBlockInfo): data block being tested as a match. -220 -221 Returns: -222 is_match (bool): True if FileBlockInfo is data status block and input argument is matching data block''' -223 if self.is_data_status(): -224 return data_block_info.type[:2] == self.type[:2] and data_block_info.type[3:] == self.type[3:] +218 Returns: +219 is_match (bool): True if FileBlockInfo is data status block and input argument is matching data block''' +220 if self.is_data_status(): +221 return data_block_info.type[:2] == self.type[:2] and data_block_info.type[3:] == self.type[3:]Returns:
226 def get_label(self): -227 '''Returns a friendly string label that describes the block type''' -228 return get_block_type_label(self.type) +@@ -1556,15 +1644,15 @@223 def get_label(self): +224 '''Returns a friendly string label that describes the block type''' +225 return get_block_type_label(self.type)Returns:
230 def get_data_key(self): -231 '''If block is a data block, this function will return an shorthand key to reference that data. -232 -233 e.g. t: transmission, a: absorption, sm: sample, rf: reference, smph: sample phase etc. If the block is not -234 a data block, it will return None.''' -235 if self.is_data(): -236 return get_data_key(self.type) -237 else: -238 return None +@@ -1575,6 +1663,17 @@227 def get_data_key(self): +228 '''If block is a data block, this function will return an shorthand key to reference that data. +229 +230 e.g. t: transmission, a: absorption, sm: sample, rf: reference, smph: sample phase etc. If the block is not +231 a data block, it will return None.''' +232 if self.is_data(): +233 return get_data_key(self.type) +234 else: +235 return NoneReturns:
241class Data: -242 '''Class containing array data and associated parameter/metadata from an OPUS file. -243 -244 Args: -245 filebytes: raw bytes from OPUS file. see: `read_opus_file_bytes` -246 data_info: `FileBlockInfo` instance of a data block -247 data_status_info: `FileBlockInfo` instance of a data status block which contains metadata about the data_info -248 block. This block is a parameter block. -249 -250 Attributes: -251 params: `Parameter` class with metadata associated with the data block such as first x point: `fxp`, last x -252 point: `lxp`, number of points: `npt`, date: `dat`, time: `tim` etc. -253 y: 1D `numpy` array containing y values of data block -254 x: 1D `numpy` array containing x values of data block. Units of x array are given by `dxu` parameter. -255 label: human-readable string label describing the data block (e.g. Sample Spectrum, Absorbance, etc.) -256 -257 Extended Attributes: -258 **wn:** Returns the x array in wavenumber (cm⁻¹) units regardless of what units the x array was originally +@@ -1718,14 +1817,14 @@238class Data: +239 '''Class containing array data and associated parameter/metadata from an OPUS file. +240 +241 Args: +242 filebytes: raw bytes from OPUS file. see: `read_opus_file_bytes` +243 data_info: `FileBlockInfo` instance of a data block +244 data_status_info: `FileBlockInfo` instance of a data status block which contains metadata about the data_info +245 block. This block is a parameter block. +246 +247 Attributes: +248 params: `Parameter` class with metadata associated with the data block such as first x point: `fxp`, last x +249 point: `lxp`, number of points: `npt`, date: `dat`, time: `tim` etc. +250 y: 1D `numpy` array containing y values of data block +251 x: 1D `numpy` array containing x values of data block. Units of x array are given by `dxu` parameter. +252 label: human-readable string label describing the data block (e.g. Sample Spectrum, Absorbance, etc.) +253 +254 Extended Attributes: +255 **wn:** Returns the x array in wavenumber (cm⁻¹) units regardless of what units the x array was originally +256 saved in. This is only valid for spectral data blocks such as sample, reference, transmission, etc., not +257 interferogram or phase blocks. +258 **wl:** Returns the x array in wavelength (µm) units regardless of what units the x array was originally 259 saved in. This is only valid for spectral data blocks such as sample, reference, transmission, etc., not 260 interferogram or phase blocks. -261 **wl:** Returns the x array in wavelength (µm) units regardless of what units the x array was originally -262 saved in. This is only valid for spectral data blocks such as sample, reference, transmission, etc., not -263 interferogram or phase blocks. -264 **f:** Returns the x array in modulation frequency units (Hz) regardless of what units the x array was -265 originally saved in. This is only valid for spectral data blocks such as sample, reference, transmission, -266 etc., not interferogram or phase blocks. -267 **datetime:** Returns a `datetime` class of when the data was taken (extracted from data status parameter block). -268 **xxx:** the various three char parameter keys from the `params` attribute can be directly called from the -269 `Data` class for convenience. Common parameters include `dxu` (x units), `mxy` (max y value), `mny` (min y -270 value), etc. -271 ''' -272 __slots__ = ('_key', 'params', 'y', 'x', 'label', 'vel') -273 -274 def __init__(self, filebytes: bytes, data_info: FileBlockInfo, data_status_info: FileBlockInfo): -275 self._key = data_info.get_data_key() -276 self.params = Parameters(filebytes, [data_status_info]) -277 y = parse_data_block(filebytes, size=data_info.size, start=data_info.start, dpf=self.params.dpf) -278 self.y = y[:self.params.npt] # Trim extra values on some spectra -279 self.x = np.linspace(self.params.fxv, self.params.lxv, self.params.npt) -280 self.label = data_info.get_label() -281 self.vel = 0 -282 -283 def __getattr__(self, name): -284 if name.lower() == 'wn' and self.params.dxu in ('WN', 'MI', 'LGW'): -285 return self._get_wn() -286 elif name.lower() == 'wl' and self.params.dxu in ('WN', 'MI', 'LGW'): -287 return self._get_wl() -288 elif name.lower() == 'f' and self.params.dxu in ('WN', 'MI', 'LGW'): -289 return self._get_freq() -290 elif name.lower() in self.params.keys(): -291 return getattr(self.params, name.lower()) -292 elif name == 'datetime': -293 return self.params.datetime -294 else: -295 text = str(name) + ' is not a valid attribute for Data: ' + str(self._key) -296 raise AttributeError(text) -297 -298 def _get_wn(self): -299 if self.params.dxu == 'WN': -300 return self.x -301 elif self.params.dxu == 'MI': -302 return 10000. / self.x -303 elif self.params.dxu == 'LGW': -304 return np.exp(self.x) -305 -306 def _get_wl(self): -307 if self.params.dxu == 'WN': -308 return 10000. / self.x -309 elif self.params.dxu == 'MI': -310 return self.x -311 elif self.params.dxu == 'LGW': -312 return 10000 / np.exp(self.x) -313 -314 def _get_freq(self): -315 vel = 1000 * np.float(self.vel) / 7900 # cm/s -316 return vel * self.wn +261 **f:** Returns the x array in modulation frequency units (Hz) regardless of what units the x array was +262 originally saved in. This is only valid for spectral data blocks such as sample, reference, transmission, +263 etc., not interferogram or phase blocks. +264 **datetime:** Returns a `datetime` class of when the data was taken (extracted from data status parameter block). +265 **xxx:** the various three char parameter keys from the `params` attribute can be directly called from the +266 `Data` class for convenience. Common parameters include `dxu` (x units), `mxy` (max y value), `mny` (min y +267 value), etc. +268 ''' +269 __slots__ = ('_key', 'params', 'y', 'x', 'label', 'vel') +270 +271 def __init__(self, filebytes: bytes, data_info: FileBlockInfo, data_status_info: FileBlockInfo): +272 self._key = data_info.get_data_key() +273 self.params = Parameters(filebytes, [data_status_info]) +274 y = parse_data_block(filebytes, size=data_info.size, start=data_info.start, dpf=self.params.dpf) +275 self.y = y[:self.params.npt] # Trim extra values on some spectra +276 self.x = np.linspace(self.params.fxv, self.params.lxv, self.params.npt) +277 self.label = data_info.get_label() +278 self.vel = 0 +279 +280 def __getattr__(self, name): +281 if name.lower() == 'wn' and self.params.dxu in ('WN', 'MI', 'LGW'): +282 return self._get_wn() +283 elif name.lower() == 'wl' and self.params.dxu in ('WN', 'MI', 'LGW'): +284 return self._get_wl() +285 elif name.lower() == 'f' and self.params.dxu in ('WN', 'MI', 'LGW'): +286 return self._get_freq() +287 elif name.lower() in self.params.keys(): +288 return getattr(self.params, name.lower()) +289 elif name == 'datetime': +290 return self.params.datetime +291 else: +292 text = str(name) + ' is not a valid attribute for Data: ' + str(self._key) +293 raise AttributeError(text) +294 +295 def _get_wn(self): +296 if self.params.dxu == 'WN': +297 return self.x +298 elif self.params.dxu == 'MI': +299 return 10000. / self.x +300 elif self.params.dxu == 'LGW': +301 return np.exp(self.x) +302 +303 def _get_wl(self): +304 if self.params.dxu == 'WN': +305 return 10000. / self.x +306 elif self.params.dxu == 'MI': +307 return self.x +308 elif self.params.dxu == 'LGW': +309 return 10000 / np.exp(self.x) +310 +311 def _get_freq(self): +312 vel = 1000 * np.float(self.vel) / 7900 # cm/s +313 return vel * self.wnExtended Attributes:
274 def __init__(self, filebytes: bytes, data_info: FileBlockInfo, data_status_info: FileBlockInfo): -275 self._key = data_info.get_data_key() -276 self.params = Parameters(filebytes, [data_status_info]) -277 y = parse_data_block(filebytes, size=data_info.size, start=data_info.start, dpf=self.params.dpf) -278 self.y = y[:self.params.npt] # Trim extra values on some spectra -279 self.x = np.linspace(self.params.fxv, self.params.lxv, self.params.npt) -280 self.label = data_info.get_label() -281 self.vel = 0 +@@ -1799,49 +1898,49 @@271 def __init__(self, filebytes: bytes, data_info: FileBlockInfo, data_status_info: FileBlockInfo): +272 self._key = data_info.get_data_key() +273 self.params = Parameters(filebytes, [data_status_info]) +274 y = parse_data_block(filebytes, size=data_info.size, start=data_info.start, dpf=self.params.dpf) +275 self.y = y[:self.params.npt] # Trim extra values on some spectra +276 self.x = np.linspace(self.params.fxv, self.params.lxv, self.params.npt) +277 self.label = data_info.get_label() +278 self.vel = 0Extended Attributes:
319class Data3D(Data): -320 '''Class containing 3D array data (series of spectra) and associated parameter/metadata from an OPUS file. -321 -322 Args: -323 filebytes: raw bytes from OPUS file. see: read_opus_file_bytes -324 data_info: FileBlockInfo instance of a 3D data block -325 data_status_info: FileBlockInfo instance of a data status block which contains metadata about the data_info -326 block. This block is a parameter block. -327 -328 Attributes: -329 params: Parameter class with metadata associated with the data block such as first x point (fxp), last x point -330 (lxp), number of points (npt), date (dat), time (tim) etc. -331 y: 2D numpy array containing y values of data block -332 x: 1D numpy array containing x values of data block. Units of x array are given by .dxu attribute. -333 num_spectra: number of spectra in the series (i.e. length of y) -334 label: human-readable string label describing the data block (e.g. Sample Spectrum, Absorbance, etc.) -335 -336 Extended Attributes: -337 **wn:** Returns the x array in wavenumber (cm⁻¹) units regardless of what units the x array was originally saved +@@ -1895,17 +1994,17 @@316class Data3D(Data): +317 '''Class containing 3D array data (series of spectra) and associated parameter/metadata from an OPUS file. +318 +319 Args: +320 filebytes: raw bytes from OPUS file. see: read_opus_file_bytes +321 data_info: FileBlockInfo instance of a 3D data block +322 data_status_info: FileBlockInfo instance of a data status block which contains metadata about the data_info +323 block. This block is a parameter block. +324 +325 Attributes: +326 params: Parameter class with metadata associated with the data block such as first x point (fxp), last x point +327 (lxp), number of points (npt), date (dat), time (tim) etc. +328 y: 2D numpy array containing y values of data block +329 x: 1D numpy array containing x values of data block. Units of x array are given by .dxu attribute. +330 num_spectra: number of spectra in the series (i.e. length of y) +331 label: human-readable string label describing the data block (e.g. Sample Spectrum, Absorbance, etc.) +332 +333 Extended Attributes: +334 **wn:** Returns the x array in wavenumber (cm⁻¹) units regardless of what units the x array was originally saved +335 in. This is only valid for spectral data blocks such as sample, reference, transmission, etc., not +336 interferogram or phase blocks. +337 **wl:** Returns the x array in wavelength (µm) units regardless of what units the x array was originally saved 338 in. This is only valid for spectral data blocks such as sample, reference, transmission, etc., not 339 interferogram or phase blocks. -340 **wl:** Returns the x array in wavelength (µm) units regardless of what units the x array was originally saved -341 in. This is only valid for spectral data blocks such as sample, reference, transmission, etc., not -342 interferogram or phase blocks. -343 **datetime:** Returns a `datetime` class of when the data was taken (extracted from data status parameter -344 block). -345 **xxx:** the various three char parameter keys from the "params" attribute can be directly called from the data -346 class for convenience. Several of these parameters return arrays, rather than singular values because they -347 are recorded for every spectra in the series, e.g. `npt`, `mny`, `mxy`, `tim`, `nsn`. -348 ''' -349 __slots__ = ('_key', 'params', 'y', 'x', 'num_spectra', 'label') -350 -351 def __init__(self, filebytes: bytes, data_info: FileBlockInfo, data_status_info: FileBlockInfo): -352 self._key = data_info.get_data_key() -353 self.params = Parameters(filebytes, [data_status_info]) -354 data = parse_3d_data_block(filebytes, start=data_info.start, dpf=self.params.dpf) -355 self.y = data['y'][:, :self.params.npt] # Trim extra values on some spectra -356 self.x = np.linspace(self.params.fxv, self.params.lxv, self.params.npt) -357 self.num_spectra = data['num_blocks'] -358 for key, val in data.items(): -359 if key not in ['y', 'version', 'offset', 'num_blocks', 'data_size', 'info_size']: -360 self.params._params[key] = val -361 self.label = data_info.get_label() +340 **datetime:** Returns a `datetime` class of when the data was taken (extracted from data status parameter +341 block). +342 **xxx:** the various three char parameter keys from the "params" attribute can be directly called from the data +343 class for convenience. Several of these parameters return arrays, rather than singular values because they +344 are recorded for every spectra in the series, e.g. `npt`, `mny`, `mxy`, `tim`, `nsn`. +345 ''' +346 __slots__ = ('_key', 'params', 'y', 'x', 'num_spectra', 'label') +347 +348 def __init__(self, filebytes: bytes, data_info: FileBlockInfo, data_status_info: FileBlockInfo): +349 self._key = data_info.get_data_key() +350 self.params = Parameters(filebytes, [data_status_info]) +351 data = parse_3d_data_block(filebytes, start=data_info.start, dpf=self.params.dpf) +352 self.y = data['y'][:, :self.params.npt] # Trim extra values on some spectra +353 self.x = np.linspace(self.params.fxv, self.params.lxv, self.params.npt) +354 self.num_spectra = data['num_blocks'] +355 for key, val in data.items(): +356 if key not in ['y', 'version', 'offset', 'num_blocks', 'data_size', 'info_size']: +357 self.params._params[key] = val +358 self.label = data_info.get_label()Extended Attributes:
351 def __init__(self, filebytes: bytes, data_info: FileBlockInfo, data_status_info: FileBlockInfo): -352 self._key = data_info.get_data_key() -353 self.params = Parameters(filebytes, [data_status_info]) -354 data = parse_3d_data_block(filebytes, start=data_info.start, dpf=self.params.dpf) -355 self.y = data['y'][:, :self.params.npt] # Trim extra values on some spectra -356 self.x = np.linspace(self.params.fxv, self.params.lxv, self.params.npt) -357 self.num_spectra = data['num_blocks'] -358 for key, val in data.items(): -359 if key not in ['y', 'version', 'offset', 'num_blocks', 'data_size', 'info_size']: -360 self.params._params[key] = val -361 self.label = data_info.get_label() +@@ -1988,49 +2087,53 @@348 def __init__(self, filebytes: bytes, data_info: FileBlockInfo, data_status_info: FileBlockInfo): +349 self._key = data_info.get_data_key() +350 self.params = Parameters(filebytes, [data_status_info]) +351 data = parse_3d_data_block(filebytes, start=data_info.start, dpf=self.params.dpf) +352 self.y = data['y'][:, :self.params.npt] # Trim extra values on some spectra +353 self.x = np.linspace(self.params.fxv, self.params.lxv, self.params.npt) +354 self.num_spectra = data['num_blocks'] +355 for key, val in data.items(): +356 if key not in ['y', 'version', 'offset', 'num_blocks', 'data_size', 'info_size']: +357 self.params._params[key] = val +358 self.label = data_info.get_label()Inherited Members
364class Parameters: -365 '''Class containing parameter metadata of an OPUS file. -366 -367 Parameters of an OPUS file are stored as key, val pairs, where the key is always three chars. For example, the -368 beamsplitter is stored in the "bms" attribute, source in "src" etc. A list of known keys, with friendly label can -369 be found in `brukeropus.file.constants.PARAM_LABELS`. The keys in an OPUS file are not case sensitive, and stored -370 in all CAPS (i.e. `BMS`, `SRC`, etc.) but this class uses lower case keys to follow python convention. The class is -371 initialized from a list of parameter `FileBlockInfo`. The key, val items in blocks of the list are combined into -372 one parameter class, so care must be taken not to pass blocks that will overwrite each others keys. Analagous to a -373 dict, the keys, values, and (key, val) can be iterated over using the functions: `keys()`, `values()`, and `items()` -374 respectively. -375 -376 Args: -377 filebytes: raw bytes from OPUS file. see: `brukeropus.file.parser.read_opus_file_bytes` -378 param_blocks: list of `FileBlockInfo`; every block in the list should be classified as a parameter block. -379 -380 Attributes: -381 xxx: parameter attributes are stored as three char keys. Which keys are generated depends on the list of -382 `FileBlockInfo` that is used to initialize the class. If input list contains a single data status -383 `FileBlockInfo`, attributes will include: `fxv`, `lxv`, `npt` (first x-val, last x-val, number of points), -384 etc. Other blocks produce attributes such as: `bms`, `src`, `apt` (beamsplitter, source, aperture) etc. A -385 full list of keys available in a given Parameters instance are given by the `keys()` method. -386 datetime: if blocks contain the keys: `dat` (date) and `tim` (time), the `datetime` attribute of this class will -387 be set to a python `datetime` object. Currently, only data status blocks are known to have these keys. If -388 `dat` and `tim` are not present in the class, the `datetime` attribute will return `None`. -389 ''' -390 __slots__ = ('_params', 'datetime') -391 -392 def __init__(self, filebytes: bytes, param_blocks: list): -393 self._params = dict() -394 for block_info in param_blocks: -395 params = {key.lower(): val for key, val in parse_param_block(filebytes, block_info.size, block_info.start)} -396 self._params.update(params) -397 block_info.keys = tuple(params.keys()) -398 self._set_datetime() -399 -400 def __getattr__(self, name): -401 if name.lower() in self._params.keys(): -402 return self._params[name.lower()] -403 else: -404 text = str(name) + ' not a valid attribute. For list of valid parameter keys, use: .keys()' -405 raise AttributeError(text) +@@ -2112,13 +2249,13 @@361class Parameters: +362 '''Class containing parameter metadata of an OPUS file. +363 +364 Parameters of an OPUS file are stored as key, val pairs, where the key is always three chars. For example, the +365 beamsplitter is stored in the "bms" attribute, source in "src" etc. A list of known keys, with friendly label can +366 be found in `brukeropus.file.constants.PARAM_LABELS`. The keys in an OPUS file are not case sensitive, and stored +367 in all CAPS (i.e. `BMS`, `SRC`, etc.) but this class uses lower case keys to follow python convention. The class is +368 initialized from a list of parameter `FileBlockInfo`. The key, val items in blocks of the list are combined into +369 one parameter class, so care must be taken not to pass blocks that will overwrite each others keys. Analagous to a +370 dict, the keys, values, and (key, val) can be iterated over using the functions: `keys()`, `values()`, and `items()` +371 respectively. +372 +373 Args: +374 filebytes: raw bytes from OPUS file. see: `brukeropus.file.parser.read_opus_file_bytes` +375 param_blocks: list of `FileBlockInfo`; every block in the list should be classified as a parameter block. +376 +377 Attributes: +378 xxx: parameter attributes are stored as three char keys. Which keys are generated depends on the list of +379 `FileBlockInfo` that is used to initialize the class. If input list contains a single data status +380 `FileBlockInfo`, attributes will include: `fxv`, `lxv`, `npt` (first x-val, last x-val, number of points), +381 etc. Other blocks produce attributes such as: `bms`, `src`, `apt` (beamsplitter, source, aperture) etc. A +382 full list of keys available in a given Parameters instance are given by the `keys()` method. +383 datetime: if blocks contain the keys: `dat` (date) and `tim` (time), the `datetime` attribute of this class will +384 be set to a python `datetime` object. Currently, only data status blocks are known to have these keys. If +385 `dat` and `tim` are not present in the class, the `datetime` attribute will return `None`. +386 ''' +387 __slots__ = ('_params', 'datetime') +388 +389 def __init__(self, filebytes: bytes, param_blocks: list): +390 self._params = dict() +391 for block_info in param_blocks: +392 params = {key.lower(): val for key, val in parse_param_block(filebytes, block_info.size, block_info.start)} +393 self._params.update(params) +394 block_info.keys = tuple(params.keys()) +395 self._set_datetime() +396 +397 def __getattr__(self, name): +398 if name.lower() in self._params.keys(): +399 return self._params[name.lower()] +400 else: +401 text = str(name) + ' not a valid attribute. For list of valid parameter keys, use: .keys()' +402 raise AttributeError(text) +403 +404 def __getitem__(self, item): +405 return self._params.__getitem__(item) 406 +<<<<<<< HEAD 407 def __getitem__(self, item): 408 return self._params.__getitem__(item) 409 @@ -2066,6 +2169,40 @@Inherited Members
439 def items(self): 440 '''Returns a `dict_items` class of all the values in the class (i.e. dict.items())''' 441 return self._params.items() +======= +407 def _set_datetime(self): +408 if 'dat' in self.keys() and 'tim' in self.keys(): +409 try: +410 date_str = self.dat +411 time_str = self.tim +412 dt_str = date_str + '-' + time_str[:time_str.index(' (')] +413 try: +414 fmt = '%d/%m/%Y-%H:%M:%S.%f' +415 dt = datetime.datetime.strptime(dt_str, fmt) +416 except: +417 try: +418 fmt = '%Y/%m/%d-%H:%M:%S.%f' +419 dt = datetime.datetime.strptime(dt_str, fmt) +420 except: +421 self.datetime = None +422 self.datetime = dt +423 except: +424 self.datetime = None +425 else: +426 self.datetime = None +427 +428 def keys(self): +429 '''Returns a `dict_keys` class of all valid keys in the class (i.e. dict.keys())''' +430 return self._params.keys() +431 +432 def values(self): +433 '''Returns a `dict_values` class of all the values in the class (i.e. dict.values())''' +434 return self._params.values() +435 +436 def items(self): +437 '''Returns a `dict_items` class of all the values in the class (i.e. dict.items())''' +438 return self._params.items() +>>>>>>> origin/masterAttributes:
392 def __init__(self, filebytes: bytes, param_blocks: list): -393 self._params = dict() -394 for block_info in param_blocks: -395 params = {key.lower(): val for key, val in parse_param_block(filebytes, block_info.size, block_info.start)} -396 self._params.update(params) -397 block_info.keys = tuple(params.keys()) -398 self._set_datetime() +@@ -2136,9 +2273,15 @@389 def __init__(self, filebytes: bytes, param_blocks: list): +390 self._params = dict() +391 for block_info in param_blocks: +392 params = {key.lower(): val for key, val in parse_param_block(filebytes, block_info.size, block_info.start)} +393 self._params.update(params) +394 block_info.keys = tuple(params.keys()) +395 self._set_datetime()Attributes:
431 def keys(self): 432 '''Returns a `dict_keys` class of all valid keys in the class (i.e. dict.keys())''' 433 return self._params.keys() +======= +@@ -2158,9 +2301,15 @@428 def keys(self): +429 '''Returns a `dict_keys` class of all valid keys in the class (i.e. dict.keys())''' +430 return self._params.keys() +>>>>>>> origin/masterAttributes:
435 def values(self): 436 '''Returns a `dict_values` class of all the values in the class (i.e. dict.values())''' 437 return self._params.values() +======= +@@ -2180,9 +2329,15 @@432 def values(self): +433 '''Returns a `dict_values` class of all the values in the class (i.e. dict.values())''' +434 return self._params.values() +>>>>>>> origin/masterAttributes:
439 def items(self): 440 '''Returns a `dict_items` class of all the values in the class (i.e. dict.items())''' 441 return self._params.items() +======= +@@ -2214,6 +2369,7 @@436 def items(self): +437 '''Returns a `dict_items` class of all the values in the class (i.e. dict.items())''' +438 return self._params.items() +>>>>>>> origin/masterAttributes:
444class FileDirectory: 445 '''Contains type and pointer information for all blocks of data in an OPUS file. 446 @@ -2253,6 +2409,50 @@Attributes:
480 self.rf_param_blocks: list = [] 481 self.directory_block: FileBlockInfo 482 self.file_log_block: FileBlockInfo +======= +@@ -2322,6 +2552,7 @@441class FileDirectory: +442 '''Contains type and pointer information for all blocks of data in an OPUS file. +443 +444 `FileDirectory` information is decoded from the raw file bytes of an OPUS file. First the header is read which +445 provides the start location of the directory block, number of blocks in file, and maximum number of blocks the file +446 supports. Then it decodes the block pointer information from each entry of the file's directory block. Rather than +447 store all file blocks in a single list (as it is done in the OPUS file directory), this class sorts the blocks into +448 categories: `data`, `data_status`, `params`, `rf_params`, `directory`, and `file_log`. It also pairs the data +449 blocks with their corresponding `data_status` block to simplify grouping y data with the parameters that are used to +450 generate x data and other data block specific metadata. +451 +452 Args: +453 filebytes: raw bytes from OPUS file. see: `brukeropus.file.parser.read_opus_file_bytes` +454 +455 Attributes: +456 start: pointer to start location of the directory block +457 max_blocks: maximum number of blocks supported by file +458 num_blocks: total number of blocks in the file +459 data_blocks: list of `FileBlockInfo` that contain array data (e.g. sample, reference, phase) +460 data_status_blocks: list of `FileBlockInfo` that contain metadata specific to a data block (units, etc.) +461 param_blocks: list of `FileBlockInfo` that contain metadata about the measurement sample +462 rf_param_blocks: list of `FileBlockInfo` that contain metatdata about the reference measurement +463 directory_block: `FileBlockInfo` for directory block that contains all the block info in the file +464 file_log_block: `FileBlockInfo` of the file log (changes, etc.) +465 data_and_status_block_pairs: (data: `FileBlockInfo`, data_status: `FileBlockInfo`) which pairs the data status +466 parameter block (time, x units, y units, etc.) with the data block it informs +467 unknown_blocks: list of `FileBlockInfo` with an unrecognized type (i.e. not sure how to parse) +468 ''' +469 +470 __slots__ = ('version', 'start', 'max_blocks', 'num_blocks', 'data_blocks', 'data_status_blocks', 'param_blocks', +471 'rf_param_blocks', 'directory_block', 'file_log_block', 'data_and_status_block_pairs', +472 'unknown_blocks') +473 +474 def __init__(self, filebytes: bytes): +475 self.version, self.start, self.max_blocks, self.num_blocks = parse_header(filebytes) +476 self.data_blocks: list = [] +477 self.data_status_blocks: list = [] +478 self.param_blocks: list = [] +479 self.rf_param_blocks: list = [] +480 self.directory_block: FileBlockInfo +481 self.file_log_block: FileBlockInfo +482 self.unknown_blocks: list = [] +>>>>>>> origin/master 483 for block_type, size, start in parse_directory(filebytes, self.start, self.num_blocks): 484 block = FileBlockInfo(block_type=block_type, size=size, start=start) 485 if block.is_data_status(): @@ -2265,6 +2465,7 @@Attributes:
492 self.directory_block = block 493 elif block.is_file_log(): 494 self.file_log_block = block +<<<<<<< HEAD 495 elif block.is_valid(): 496 self.data_blocks.append(block) 497 self.data_and_status_block_pairs = [] @@ -2289,6 +2490,35 @@Attributes:
516 warnings.warn(text) 517 else: 518 self.data_and_status_block_pairs.append((data_block, status_matches[0])) +======= +495 elif block.is_data(): +496 self.data_blocks.append(block) +497 else: +498 block.bytes = filebytes[block.start:block.start + block.size] +499 self.unknown_blocks.append(block) +500 self.data_and_status_block_pairs = [] +501 self._pair_data_and_status_blocks() +502 +503 def __str__(self): +504 data_keys = [b.get_data_key() for b in self.data_blocks] +505 data_str = ', '.join(data_keys) +506 return 'File Directory: ' + str(self.num_blocks) + ' total blocks; data blocks: (' + data_str + ')' +507 +508 def _pair_data_and_status_blocks(self): +509 for data_block in self.data_blocks: +510 status_matches = [block for block in self.data_status_blocks if block.is_data_status_match(data_block)] +511 if len(status_matches) == 0: +512 text = 'Warning: No data status block match for data block: ' + str(data_block) \ +513 + '\n\tdata block will be ignored.' +514 warnings.warn(text) +515 elif len(status_matches) > 1: +516 text = 'Warning: Multiple data status block matches for data block: ' + str(data_block) \ +517 + '\n\tMatches:' + '; '.join([str(match) for match in status_matches]) \ +518 + '\n\tdata block will be ignored.' +519 warnings.warn(text) +520 else: +521 self.data_and_status_block_pairs.append((data_block, status_matches[0])) +>>>>>>> origin/masterAttributes:
file_log_block: FileBlockInfo
of the file log (changes, etc.)data_and_status_block_pairs: (data: +FileBlockInfo
, data_status:FileBlockInfo
) which pairs the data status parameter block (time, x units, y units, etc.) with the data block it informsunknown_blocks: list of FileBlockInfo
with an unrecognized type (i.e. not sure how to parse)
475 def __init__(self, filebytes: bytes): 476 self.version, self.start, self.max_blocks, self.num_blocks = parse_header(filebytes) 477 self.data_blocks: list = [] @@ -2344,6 +2576,17 @@Attributes:
480 self.rf_param_blocks: list = [] 481 self.directory_block: FileBlockInfo 482 self.file_log_block: FileBlockInfo +======= +@@ -2431,6 +2684,17 @@474 def __init__(self, filebytes: bytes): +475 self.version, self.start, self.max_blocks, self.num_blocks = parse_header(filebytes) +476 self.data_blocks: list = [] +477 self.data_status_blocks: list = [] +478 self.param_blocks: list = [] +479 self.rf_param_blocks: list = [] +480 self.directory_block: FileBlockInfo +481 self.file_log_block: FileBlockInfo +482 self.unknown_blocks: list = [] +>>>>>>> origin/master 483 for block_type, size, start in parse_directory(filebytes, self.start, self.num_blocks): 484 block = FileBlockInfo(block_type=block_type, size=size, start=start) 485 if block.is_data_status(): @@ -2356,10 +2599,20 @@Attributes:
492 self.directory_block = block 493 elif block.is_file_log(): 494 self.file_log_block = block +<<<<<<< HEAD 495 elif block.is_valid(): 496 self.data_blocks.append(block) 497 self.data_and_status_block_pairs = [] 498 self._pair_data_and_status_blocks() +======= +495 elif block.is_data(): +496 self.data_blocks.append(block) +497 else: +498 block.bytes = filebytes[block.start:block.start + block.size] +499 self.unknown_blocks.append(block) +500 self.data_and_status_block_pairs = [] +501 self._pair_data_and_status_blocks() +>>>>>>> origin/masterAttributes:
+
brukeropus
is a Python package for interacting with Bruker's OPUS spectroscopy software. Currently, the package can\nread OPUS data files and communicate/control OPUS software using the DDE communication protocol)\n\nbrukeropus
requires python 3.6+
and numpy
, but matplotlib
is needed to run the plotting examples. You can\ninstall with pip:
pip install brukeropus\n
\nbrukeropus
provides direct imports to the following:
from brukeropus import find_opus_files, read_opus, OPUSFile, Opus\n
\nAll other file functions or classes can be directly imported from the brukeropus.file
or brukeropus.control
\nsubmodules, e.g.:
from brukeropus.file import parse_file_and_print\n
\nIt is recommended that you do not import from the fully qualified namespace, e.g.:
\n\nfrom brukeropus.file.utils import parse_file_and_print\n
\nas that namespace is subject to change. Instead import directly from brukeropus
or its first level submodules.
from brukeropus import read_opus\nfrom matplotlib import pyplot as plt\n\nopus_file = read_opus('file.0') # Returns an OPUSFile class\n\nopus_file.print_parameters() # Pretty prints all metadata in the file to the console\n\nif 'a' in opus_file.data_keys: # If absorbance spectra was extracted from file\n plt.plot(opus_file.a.x, opus_file.a.y) # Plot absorbance spectra\n plt.title(opus_file.sfm + ' - ' + opus_file.snm) # Sets plot title to Sample Form - Sample Name\n plt.show() # Display plot\n
\nMore detailed documentation on the file submodule can be found in brukeropus.file
from brukeropus import opus, read_opus\nfrom matplotlib import pyplot as plt\n\nopus = Opus() # Connects to actively running OPUS software\n\napt_options = opus.get_param_options('apt') # Get all valid aperture settings\n\nfor apt in apt_options[2:-2]: # Loop over all but the two smallest and two largest aperature settings\n filepath = opus.measure_sample(apt=apt, nss=10, unload=True) # Perform measurement and unload file from OPUS\n data = read_opus(filepath) # Read OPUS file from measurement\n plt.plot(data.sm.x, data.sm.y, label=apt) # Plot single-channel sample spectra\nplt.legend()\nplt.show()\n
\nMore detailed documentation on the control submodule can be found in brukeropus.control
.
The brukeropus.control
submodule of brukeropus
includes the Opus
class for communicating with OPUS software. The\nOpus
class currently supports communication through the Dynamic Data Exchange (DDE) protocol. This class can be used\nto script measurement sweeps and perform various low-level operations (e.g. move mirrors, rotate polarizers, etc.). In\norder to communicate with OPUS, the software must be open, logged in, and running on the same PC as brukeropus
.
from brukeropus import Opus\n\nopus = Opus() # initialization of class automatically connects to open OPUS software\nprint(opus.get_version()) # prints the current OPUS software version\n
\nopus = Opus()\nparam = 'vel'\nprint(opus.get_param_label(param))\nprint(opus.get_param_options(param))\n
\nfrom brukeropus import opus, read_opus\nfrom matplotlib import pyplot as plt\n\nopus = Opus() # Connects to actively running OPUS software\n\napt_options = opus.get_param_options('apt') # Get all valid aperture settings\n\nfor apt in apt_options[2:-2]: # Loop over all but the two smallest and two largest aperature settings\n filepath = opus.measure_sample(apt=apt, nss=10, unload=True) # Perform measurement and unload file from OPUS\n data = read_opus(filepath) # Read OPUS file from measurement\n plt.plot(data.sm.x, data.sm.y, label=apt) # Plot single-channel sample spectra\nplt.legend()\nplt.show()\n
\nFor complete Opus
documentation, see: brukeropus.control.opus
Retrieve a function from a library, and set the data types.
\n", "signature": "(\tlibname,\tfuncname,\trestype=None,\targtypes=(),\t_libcache={'user32': <WinDLL 'user32', handle 7fffa9710000>}):", "funcdef": "def"}, {"fullname": "brukeropus.control.dde.DDECALLBACK", "modulename": "brukeropus.control.dde", "qualname": "DDECALLBACK", "kind": "variable", "doc": "\n", "default_value": "<class 'ctypes.WINFUNCTYPE.<locals>.WinFunctionType'>"}, {"fullname": "brukeropus.control.dde.DDE", "modulename": "brukeropus.control.dde", "qualname": "DDE", "kind": "class", "doc": "Object containing all the DDE functions
\n"}, {"fullname": "brukeropus.control.dde.DDE.AccessData", "modulename": "brukeropus.control.dde", "qualname": "DDE.AccessData", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.ClientTransaction", "modulename": "brukeropus.control.dde", "qualname": "DDE.ClientTransaction", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.Connect", "modulename": "brukeropus.control.dde", "qualname": "DDE.Connect", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.CreateStringHandle", "modulename": "brukeropus.control.dde", "qualname": "DDE.CreateStringHandle", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.Disconnect", "modulename": "brukeropus.control.dde", "qualname": "DDE.Disconnect", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.GetLastError", "modulename": "brukeropus.control.dde", "qualname": "DDE.GetLastError", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.Initialize", "modulename": "brukeropus.control.dde", "qualname": "DDE.Initialize", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.FreeDataHandle", "modulename": "brukeropus.control.dde", "qualname": "DDE.FreeDataHandle", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.FreeStringHandle", "modulename": "brukeropus.control.dde", "qualname": "DDE.FreeStringHandle", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.QueryString", "modulename": "brukeropus.control.dde", "qualname": "DDE.QueryString", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.UnaccessData", "modulename": "brukeropus.control.dde", "qualname": "DDE.UnaccessData", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.Uninitialize", "modulename": "brukeropus.control.dde", "qualname": "DDE.Uninitialize", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDEError", "modulename": "brukeropus.control.dde", "qualname": "DDEError", "kind": "class", "doc": "Exception raise when a DDE errpr occures.
\n", "bases": "builtins.RuntimeError"}, {"fullname": "brukeropus.control.dde.DDEError.__init__", "modulename": "brukeropus.control.dde", "qualname": "DDEError.__init__", "kind": "function", "doc": "\n", "signature": "(msg, idInst=None)"}, {"fullname": "brukeropus.control.dde.DDEClient", "modulename": "brukeropus.control.dde", "qualname": "DDEClient", "kind": "class", "doc": "The DDEClient class.
\n\nUse this class to create and manage a connection to a service/topic. To get\nclassbacks subclass DDEClient and overwrite callback.
\n"}, {"fullname": "brukeropus.control.dde.DDEClient.__init__", "modulename": "brukeropus.control.dde", "qualname": "DDEClient.__init__", "kind": "function", "doc": "Create a connection to a service/topic.
\n", "signature": "(service, topic)"}, {"fullname": "brukeropus.control.dde.DDEClient.advise", "modulename": "brukeropus.control.dde", "qualname": "DDEClient.advise", "kind": "function", "doc": "Request updates when DDE data changes.
\n", "signature": "(self, item, stop=False):", "funcdef": "def"}, {"fullname": "brukeropus.control.dde.DDEClient.execute", "modulename": "brukeropus.control.dde", "qualname": "DDEClient.execute", "kind": "function", "doc": "Execute a DDE command.
\n", "signature": "(self, command, timeout=5000):", "funcdef": "def"}, {"fullname": "brukeropus.control.dde.DDEClient.request", "modulename": "brukeropus.control.dde", "qualname": "DDEClient.request", "kind": "function", "doc": "Request data from DDE service.
\n", "signature": "(self, item, timeout=5000):", "funcdef": "def"}, {"fullname": "brukeropus.control.dde.DDEClient.callback", "modulename": "brukeropus.control.dde", "qualname": "DDEClient.callback", "kind": "function", "doc": "Calback function for advice.
\n", "signature": "(self, value, item=None):", "funcdef": "def"}, {"fullname": "brukeropus.control.dde.WinMSGLoop", "modulename": "brukeropus.control.dde", "qualname": "WinMSGLoop", "kind": "function", "doc": "Run the main windows message loop.
\n", "signature": "():", "funcdef": "def"}, {"fullname": "brukeropus.control.opus", "modulename": "brukeropus.control.opus", "kind": "module", "doc": "\n"}, {"fullname": "brukeropus.control.opus.ERROR_CODES", "modulename": "brukeropus.control.opus", "qualname": "ERROR_CODES", "kind": "variable", "doc": "\n", "default_value": "{1: 'Not an Opus Command', 2: 'Unknown Opus Command', 3: 'Missing Square Bracket in Command', 4: 'Function Not Available (Possible missing parameter)', 5: 'Parameter Name Is Incorrect', 6: 'Parameter Set Is Incomplete', 7: 'File Parameter Is Incorrectly Formatted', 8: 'File(s) Missing Or Corrupt', 9: 'Opus Could Not Complete The Command'}"}, {"fullname": "brukeropus.control.opus.Opus", "modulename": "brukeropus.control.opus", "qualname": "Opus", "kind": "class", "doc": "Class for communicating with currently running OPUS software using DDE interface. Class automatically attempts\nto connect to OPUS software upon initialization.
\n"}, {"fullname": "brukeropus.control.opus.Opus.dde", "modulename": "brukeropus.control.opus", "qualname": "Opus.dde", "kind": "variable", "doc": "\n", "default_value": "None"}, {"fullname": "brukeropus.control.opus.Opus.connected", "modulename": "brukeropus.control.opus", "qualname": "Opus.connected", "kind": "variable", "doc": "\n", "default_value": "False"}, {"fullname": "brukeropus.control.opus.Opus.error_string", "modulename": "brukeropus.control.opus", "qualname": "Opus.error_string", "kind": "variable", "doc": "\n", "default_value": "'Error'"}, {"fullname": "brukeropus.control.opus.Opus.connect", "modulename": "brukeropus.control.opus", "qualname": "Opus.connect", "kind": "function", "doc": "Connects class to OPUS software through the DDE interface. Sets the connected
attribute to True
if\nsuccessful. By default, initializing an Opus
class will automatically attempt to connect to OPUS.
Disconnects DDE client/server connection.
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.raw_query", "modulename": "brukeropus.control.opus", "qualname": "Opus.raw_query", "kind": "function", "doc": "Sends command/request string (req_str
) to OPUS and returns the response in byte format.
\n\n", "signature": "(self, req_str: str, timeout=10000):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.parse_response", "modulename": "brukeropus.control.opus", "qualname": "Opus.parse_response", "kind": "function", "doc": "response: response from OPUS software through DDE request in bytes format.
\n
Parses the byte response from a raw DDE request query. If an error is detected in the request, an Exception\nis raised. If successful, a boolean, string or list of strings will be returned as appropriate.
\n\n\n\n", "signature": "(self, byte_response: bytes, decode='ascii'):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.query", "modulename": "brukeropus.control.opus", "qualname": "Opus.query", "kind": "function", "doc": "response: parsed response from OPUS software (bool, string, or list of strings depending on request)
\n
Sends a command/request and returns the parsed response.
\n\n\n\n", "signature": "(self, req_str: str, timeout=10000, decode='ascii'):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.close_opus", "modulename": "brukeropus.control.opus", "qualname": "Opus.close_opus", "kind": "function", "doc": "response: parsed response from OPUS software (bool, string, or list of strings depending on request)
\n
Closes the OPUS application. Returns True
if successful.
Get the label for a three character parameter code (e.g. BMS, APT, DTC, etc...).
\n\n\n\n", "signature": "(self, param: str):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.get_param_options", "modulename": "brukeropus.control.opus", "qualname": "Opus.get_param_options", "kind": "function", "doc": "label: short descriptive label that defines the parameter
\n
Get the parameter setting options for a three character parameter code. Only valid for\nenum type parameters (e.g. BMS, APT, DTC, etc...).
\n\n\n\n", "signature": "(self, param: str):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.get_version", "modulename": "brukeropus.control.opus", "qualname": "Opus.get_version", "kind": "function", "doc": "options: list of valid options (strings) for the given parameter
\n
Get the OPUS software version information
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.get_opus_path", "modulename": "brukeropus.control.opus", "qualname": "Opus.get_opus_path", "kind": "function", "doc": "Get the absolute path to the OPUS software directory (where PARAMTEXT.bin and other instrument specific files\nare located)
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.send_command", "modulename": "brukeropus.control.opus", "qualname": "Opus.send_command", "kind": "function", "doc": "Used to send \"Direct Commands\" to the optics bench. Useful for manually moving motors, etc. from accessories\nand other low-level operations such as controlling the scanning mirror movement.
\n\n\n\n\nsend_command('VAC=5') # vents the sample compartment\n send_command('VAC=4') # evacuates sample compartment
\n
\n\n", "signature": "(self, text_command: str, timeout=10000):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.evacuate_sample", "modulename": "brukeropus.control.opus", "qualname": "Opus.evacuate_sample", "kind": "function", "doc": "response: parsed response from OPUS software (typically boolean confirmation)
\n
Evacuates the sample compartment
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.vent_sample", "modulename": "brukeropus.control.opus", "qualname": "Opus.vent_sample", "kind": "function", "doc": "Vents the sample compartment
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.close_flaps", "modulename": "brukeropus.control.opus", "qualname": "Opus.close_flaps", "kind": "function", "doc": "Closes vacumm flaps between optics bench and sample compartment
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.open_flaps", "modulename": "brukeropus.control.opus", "qualname": "Opus.open_flaps", "kind": "function", "doc": "Opens vacumm flaps between optics bench and sample compartment
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.unload_file", "modulename": "brukeropus.control.opus", "qualname": "Opus.unload_file", "kind": "function", "doc": "Unloads a file from the OPUS software from its filepath
\n\n", "signature": "(self, filepath: str):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.unload_all", "modulename": "brukeropus.control.opus", "qualname": "Opus.unload_all", "kind": "function", "doc": "response:
\nTrue
if successful.
Unloads all files from OPUS software
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.measure_ref", "modulename": "brukeropus.control.opus", "qualname": "Opus.measure_ref", "kind": "function", "doc": "Takes a reference measurement using the current settings from advanced experiment. Also\ntakes option **kwargs input which use the OPUS 3-letter parameter keys and values as input\nto customize the measurement. example:
\n\nmeasure_ref(nrs=100, res=4) # measures reference with current settings but overriding averages to 100 and\n resolution to 4\n
\n\n\n\n", "signature": "(self, timeout=1000000, **kwargs):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.measure_sample", "modulename": "brukeropus.control.opus", "qualname": "Opus.measure_sample", "kind": "function", "doc": "response:
\nTrue
if successful
Takes a reference measurement using the current settings from advanced experiment. Also\ntakes option **kwargs input which use the OPUS 3-letter parameter keys and values as input\nto customize the measurement. example:
\n\nmeasure_sample(nss=100, res=4) # measures sample with current settings but overriding averages to 100 and\n resolution to 4\n
\n\n\n\n", "signature": "(self, unload=False, timeout=1000000, **kwargs):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.check_signal", "modulename": "brukeropus.control.opus", "qualname": "Opus.check_signal", "kind": "function", "doc": "filepath: absolute filepath to measured sample file
\n
Performs a quick (typically 1 sample) measurement using the current FTIR settings. Current settings can be\noverridden using **kwargs. After measurement is finished, the file is unloaded from OPUS and deleted. The\nfunction returns an OPUSFile
object before it deletes the quick measurement file.
\n\n", "signature": "(self, nss=1, **kwargs):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.save_ref", "modulename": "brukeropus.control.opus", "qualname": "Opus.save_ref", "kind": "function", "doc": "opus_file:
\nOPUSFile
object generated by quick measurement
Saves current reference to file (according to current filename and path set in advanced experiment) and\nreturns the filename.
\n\n\n\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file", "modulename": "brukeropus.file", "kind": "module", "doc": "filepath: absolute path to saved reference file
\n
The brukeropus.file
submodule of brukeropus
includes all the functions and classes for reading and exploring OPUS\nfiles. This includes both high-level functions like read_opus
that returns an OPUSFile
class, as well as low-level\nparsing functions like parse_directory
that returns data extracted directly from the binary OPUS file bytes. This\noverview documentation will focus on the high-level functions which will be useful for most users. If you are\ninterested in using the low-level parsing functions, perhaps to make your own data class or customize how files are\nread, refer to: brukeropus.file.parser
which contains all the low-level parsing functions.
OPUS files are typically saved with a numeric file extension (e.g. file.0, file.1, file.1001). This makes searching for\na list of OPUS files in a directory a little more cumbersome than a traditional \"*.csv\" search. To address this,\nbrukeropus
includes a find_opus_files
function:
from brukeropus import find_opus_files\n\nfilepaths = find_opus_files(r'path\\to\\opus\\files', recursive=True)\n
\nWhich will assign a list of filepaths that match the numeric extension formatting of OPUS files. For full documentation,\nsee brukeropus.file.utils.find_opus_files
.
brukeropus
parses OPUS files and assembles them into an OPUSFile
object that contains the extracted data (and\nmetadata) within the file. You can generate an OPUSFile
object in one of two ways:
from brukeropus import read_opus, OPUSFile\n\nfilepath = r'path\\to\\opusfile.0'\n\ndata = read_opus(filepath)\nsame_data = OPUSFile(filepath)\n
\nIn the above code, data
and same_data
are both OPUSFile
objects with identical data.
OPUSFile
ClassOPUS files all start with the same first four magic bytes. If the file does not start with these bytes (i.e. is not\na valid OPUS file), the OPUSFile class will logically evaluate to false
:
data = read_opus('file.pdf')\nif data:\n print(data)\nelse:\n print(data.filepath, 'is not an OPUS file')\n
\nTo view all parameter metadata in the file, you can print to the console using the class method: print_parameters
.\nThis will let you view all the key, value parameter data extracted from the file with labels for what the parameter keys\nare referring to wherever known.
data = read_opus('file.0')\ndata.print_parameters()\n
\nExample
print_parameters
Output
\n
====================================================================================================\n Optical Parameters\nKey Label Value\nACC Accessory TRANS *010A984F\nAPR ATR Pressure 0\nAPT Aperture Setting 1 mm\nBMS Beamsplitter KBr-Broadband\nCHN Measurement Channel Sample Compartment\nDTC Detector RT-DLaTGS [Internal Pos.1]\nHPF High Pass Filter 0\nLPF Low Pass Filter 10.0\nLPV Variable Low Pass Filter (cm-1) 4000\nOPF Optical Filter Setting Open\nPGN Preamplifier Gain 3\nRDX Extended Ready Check 0\nSRC Source MIR\nVEL Scanner Velocity 10.0\nADC External Analog Signals 0\nSON External Sync Off\n\n====================================================================================================\n Fourier Transform Parameters\nKey Label Value\nAPF Apodization Function B3\nHFQ End Frequency Limit for File 500.0\nLFQ Start Frequency Limit for File 10000.0\nNLI Nonlinearity Correction 0\nPHR Phase Resolution 100.0\nPHZ Phase Correction Mode ML\nSPZ Stored Phase Mode NO\nZFF Zero Filling Factor 2\n\n====================================================================================================\n Acquisition Parameters\nKey Label Value\nADT Additional Data Treatment 0\nAQM Acquisition Mode DD\nCFE Low Intensity Power Mode with DTGS 0\nCOR Correlation Test Mode 0\nDEL Delay Before Measurement 0\nDLY Stabilization Delay 0\nHFW Wanted High Freq Limit 15000.0\nLFW Wanted Low Freq Limit 0.0\nNSS Number of Sample Scans 50\nPLF Result Spectrum Type AB\nRES Resolution (cm-1) 4.0\nSOT Sample Scans or Time 0\nTCL Command Line for Additional Data Tr...\nTDL To Do List 16777271\nSGN Sample Signal Gain 1\n\n====================================================================================================\n Sample Origin Parameters\nKey Label Value\nBLD Building\nCNM Operator Name Duran\nCPY Company\nDPM Department\nEXP Experiment MWIR-LWIR_Trans_FileNameFormat.XPM\nLCT Location\nSFM Sample Form Atm-MWIR (All A)\nSNM Sample Name File Test\nXPP Experiment Path C:\\Users\\Public\\Documents\\Bruker\\OPUS_8.1.29\\XPM\nIST Instrument Status OK\nCPG Character Encoding Code Page 1252\nUID Universally Unique Identifier 0d1348c2-3a2c-41c9-b521-bdaf0a23710c\n\n====================================================================================================\n Instrument Status Parameters\nKey Label Value\nHFL High Folding Limit 15795.820598\nLFL Low Folding Limit 0.0\nLWN Laser Wavenumber 15795.820598\nABP Absolute Peak Pos in Laser*2 52159\nSSP Sample Spacing Divisor 1\nASG Actual Signal Gain 1\nARG Actual Reference Gain 1\nASS Number of Sample Scans 50\nGFW Number of Good Forward Scans 25\nGBW Number of Good Backward Scans 25\nBFW Number of Bad Forward Scans 0\nBBW Number of Bad Backward Scans 0\nPKA Peak Amplitude 1409\nPKL Peak Location 7364\nPRA Backward Peak Amplitude 1356\nPRL Backward Peak Location 7363\nP2A Peak Amplitude Channel 2 1\nP2L Peak Location Channel 2 1\nP2R Backward Peak Amplitude Channel 2 1\nP2K Backward Peak Location Channel 2 1\nDAQ Data Acquisition Status 0\nAG2 Actual Signal Gain Channel 2 1\nHUM Relative Humidity Interferometer 14\nSSM Sample Spacing Multiplier 1\nRSN Running Sample Number 565\nCRR Correlation Rejection Reason 0\nSRT Start Time (sec) 1556890484.642\nDUR Duration (sec) 42.433990478515625\nTSC Scanner Temperature 27.8\nMVD Max Velocity Deviation 0.1158025860786438\nPRS Pressure Interferometer (hPa) 1009.9999700000001\nAN1 Analog Signal 1 0.22596596493037535\nAN2 Analog Signal 2 3.459206583321489\nVSN Firmware Version 2.450 Oct 10 2014\nSRN Instrument Serial Number 1135\nCAM Coaddition Mode 0\nINS Instrument Type VERTEX 80V\nFOC Focal Length 100.0\nRDY Ready Check 1\n\n====================================================================================================\n Reference Instrument Status Parameters\nKey Label Value\nHFL High Folding Limit 15795.820598\nLFL Low Folding Limit 0.0\nLWN Laser Wavenumber 15795.820598\nABP Absolute Peak Pos in Laser*2 52159\nSSP Sample Spacing Divisor 1\nARG Actual Reference Gain 1\nASG Actual Signal Gain 1\nASS Number of Sample Scans 1\nGFW Number of Good Forward Scans 1\nGBW Number of Good Backward Scans 0\nBFW Number of Bad Forward Scans 0\nBBW Number of Bad Backward Scans 0\nPKA Peak Amplitude 1644\nPKL Peak Location 7364\nPRA Backward Peak Amplitude 1\nPRL Backward Peak Location -1\nP2A Peak Amplitude Channel 2 1\nP2L Peak Location Channel 2 1\nP2R Backward Peak Amplitude Channel 2 1\nP2K Backward Peak Location Channel 2 1\nDAQ Data Acquisition Status 0\nAG2 Actual Signal Gain Channel 2 1\nHUM Relative Humidity Interferometer 0\nSSM Sample Spacing Multiplier 1\nRSN Running Sample Number 5816\nCRR Correlation Rejection Reason 0\nSRT Start Time (sec) 1556890282.358\nDUR Duration (sec) 0.7919998168945312\nTSC Scanner Temperature 27.8\nMVD Max Velocity Deviation 0.10553144663572311\nPRS Pressure Interferometer (hPa) 2.01999\nAN1 Analog Signal 1 0.22577181458473206\nAN2 Analog Signal 2 4.0960001945495605\nVSN Firmware Version 2.450 Oct 10 2014\nSRN Instrument Serial Number 1135\nCAM Coaddition Mode 0\nINS Instrument Type VERTEX 80V\nFOC Focal Length 100.0\nRDY Ready Check 1\nARS Number of Reference Scans 1\n\n====================================================================================================\n Reference Optical Parameters\nKey Label Value\nACC Accessory TRANS *010A984F\nAPR ATR Pressure 0\nAPT Aperture Setting 1 mm\nBMS Beamsplitter KBr-Broadband\nDTC Detector RT-DLaTGS [Internal Pos.1]\nHPF High Pass Filter 0\nLPF Low Pass Filter 10.0\nLPV Variable Low Pass Filter (cm-1) 4000\nOPF Optical Filter Setting Open\nPGR Reference Preamplifier Gain 3\nRCH Reference Measurement Channel Sample Compartment\nRDX Extended Ready Check 0\nSRC Source MIR\nVEL Scanner Velocity 10.0\nADC External Analog Signals 0\nSON External Sync Off\n\n====================================================================================================\n Reference Acquisition Parameters\nKey Label Value\nADT Additional Data Treatment 0\nAQM Acquisition Mode DD\nCFE Low Intensity Power Mode with DTGS 0\nCOR Correlation Test Mode 0\nDEL Delay Before Measurement 0\nDLY Stabilization Delay 0\nHFW Wanted High Freq Limit 15000.0\nLFW Wanted Low Freq Limit 0.0\nNSR Number of Background Scans 1\nPLF Result Spectrum Type TR\nRES Resolution (cm-1) 4.0\nRGN Reference Signal Gain 1\nSTR Scans or Time (Reference) 0\nTCL Command Line for Additional Data Tr...\nTDL To Do List 16777271\n\n====================================================================================================\n Reference Fourier Transform Parameters\nKey Label Value\nAPF Apodization Function B3\nHFQ End Frequency Limit for File 500.0\nLFQ Start Frequency Limit for File 10000.0\nNLI Nonlinearity Correction 0\nPHR Phase Resolution 100.0\nPHZ Phase Correction Mode ML\nSPZ Stored Phase Mode NO\nZFF Zero Filling Factor 2\n
\nYou can access a specific parameter simply by calling the key as a direct attribute of the class (case insensitive). You\ncan also get the human-readable label using the get_param_label
function:
from brukeropus.file import get_param_label\ndata = read_opus('file.0')\nprint(get_param_label('bms') + ':', data.bms)\nprint(get_param_label('src') + ':', data.src)\n
\nBeamsplitter: KBr-Broadband\nSource: MIR\n
\nYou will notice in the example output that some keys (e.g. zero filling factor zff
) may have two entries: one for the\nsample measurement and another for the reference. By default, the sample parameters are accessible directly from the\nOPUSFile
class, while the reference parameters can be accessed through the rf_params
attribute.
data = read_opus('file.0')\nprint('Sample ZFF:', data.zff, 'Reference ZFF:', data.rf_params.zff)\n
\nSample ZFF: 2 Reference ZFF: 2\n
\nYou can also iterate over the parameters using the familiar keys()
, values()
, and items()
functions using the\nparams
or rf_params
attributes:
data = read_opus('file.0')\nfor key, val in data.params.items():\n print(key + ':', val)\n
\nacc: TRANS *010A984F\napr: 0\napt: 1 mm\nbms: KBr-Broadband\nchn: Sample Compartment\ndtc: RT-DLaTGS [Internal Pos.1]\nhpf: 0\nlpf: 10.0\nlpv: 4000\nopf: Open\npgn: 3\n... continued ...\n
\nDepending on the settings used to save the OPUS file, different data blocks can be stored. To retrieve a list of data\nblocks stored in the OPUS File, use the data_keys
attribute:
data = read_opus('file.0')\nprint(data.data_keys)\n
\n['igsm', 'phsm', 'sm', 'a', 'igrf', 'rf']\n
\nEach key is also an attribute of the OPUSFile
instance that returns either a Data
or Data3D
class. You can get\nthe x
and y
array values (in the units they were saved in) as direct attributes to the Data
class:
data = read_opus('file.0')\nplt.plot(data.a.x, data.a.y)\nplt.ylim((0, 1))\nplt.show()\n
\nFor spectra with wavenumber as valid unit (e.g. single-channel or ratioed spectra), the x
array can be given in cm\u207b\u00b9
\nor \u00b5m
units by using the attributes wn
or wl
respectively:
data = read_opus('file.0')\nplt.plot(data.sm.wl, data.sm.y)\nplt.show()\n
\nYou can also iterate over all data spectra in the file using the iter_data()
method:
data = read_opus('file.0')\nfor d in data.iter_data():\n print(d.label, '(' + d.datetime.isoformat(' ') + ')')\n
\nSample Interferogram (2019-05-03 13:34:44.641000)\nSample Phase (2019-05-03 13:34:44.641000)\nSample Spectrum (2019-05-03 13:34:44.641000)\nAbsorbance (2019-05-03 13:34:44.641000)\nReference Interferogram (2019-05-03 13:31:22.358000)\nReference Spectrum (2019-05-03 13:31:22.358000)\n
\nEach data block in an OPUS file also contains a small parameter block with information such as the min/max y-value\n(mny, mxy), x-units (dxu), number of data points (npt), etc. These can be accessed as direct attributes to the Data
\nclass, or through the params
attribute:
data = read_opus('file.0')\nprint('Sample spectra y-min:', data.sm.mny, 'y-max:', data.sm.mxy)\n
\nSample spectra y-min: 1.2147593224653974e-05 y-max: 0.03543896973133087\n
\nFor full API documentation, see:
\nOPUSFile
: brukeropus.file.file.OPUSFile
\nData
: brukeropus.file.file.Data
\nData3D
: brukeropus.file.file.Data3D
Return an OPUSFile
object from an OPUS file filepath.
\n\n\n\n\n\ndata = read_opus(filepath)\ndata = OPUSFile(filepath)\n
\n\n", "signature": "(filepath):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.OPUSFile", "modulename": "brukeropus.file.file", "qualname": "OPUSFile", "kind": "class", "doc": "opus_file (
\nOPUSFile
): an instance of theOPUSFile
class containing all data/metadata extracted from the\n file.
Class that contains the data and metadata contained in a bruker OPUS file.
\n\nOPUSFile
object.bool
): True if filepath points to an OPUS file, False otherwise. Also returned for dunder \n__bool__()
Parameters
): class containing all general parameter metadata for the OPUS file. To save typing, the\nthree char parameters from params also become attributes of the OPUSFile
class (e.g. bms, apt, src) Parameters
): class containing all reference parameter metadata for the OPUS file. Data
or Data3D
.datetime
): Returns the most recent datetime of all the data blocks stored in the file (typically\nresult spectra)FileDirectory
): class containing information about all the various data blocks in the file.\n\n"}, {"fullname": "brukeropus.file.file.OPUSFile.__init__", "modulename": "brukeropus.file.file", "qualname": "OPUSFile.__init__", "kind": "function", "doc": "\n", "signature": "(filepath: str)"}, {"fullname": "brukeropus.file.file.OPUSFile.filepath", "modulename": "brukeropus.file.file", "qualname": "OPUSFile.filepath", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.OPUSFile.print_parameters", "modulename": "brukeropus.file.file", "qualname": "OPUSFile.print_parameters", "kind": "function", "doc": "sm: Single-channel sample spectra
\n
\n rf: Single-channel reference spectra
\n igsm: Sample interferogram
\n igrf: Reference interferogram
\n phsm: Sample phase
\n phrf: Reference phase
\n a: Absorbance
\n t: Transmittance
\n r: Reflectance
\n km: Kubelka-Munk
\n tr: Trace (Intensity over Time)
\n gcig: gc File (Series of Interferograms)
\n gcsc: gc File (Series of Spectra)
\n ra: Raman
\n e: Emission
\n dir: Directory
\n p: Power
\n logr: log(Reflectance)
\n atr: ATR
\n pas: Photoacoustic
Prints all the parameter metadata to the console (organized by block)
\n", "signature": "(self, key_width=7, label_width=40, value_width=53):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.OPUSFile.iter_data", "modulename": "brukeropus.file.file", "qualname": "OPUSFile.iter_data", "kind": "function", "doc": "Generator that yields the various Data classes from the OPUSFile
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo", "kind": "class", "doc": "Contains type, size and location information about an OPUS file block.
\n\nThis information is parsed from the directory block of an OPUS file and provides the information needed to parse the\nblock.
\n\nReturns False if FileBlockInfo is undefined (i.e. FileBlockInfo.type == (0, 0, 0, 0, 0, 0))
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.is_data_status", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.is_data_status", "kind": "function", "doc": "Returns True if FileBlockInfo is a data status parameter block
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.is_rf_param", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.is_rf_param", "kind": "function", "doc": "Returns True if FileBlockInfo is a parameter block associated with the reference measurement
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.is_param", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.is_param", "kind": "function", "doc": "Returns True if FileBlockInfo is a parameter block
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.is_directory", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.is_directory", "kind": "function", "doc": "Returns True if FileBlockInfo is the directory block
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.is_file_log", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.is_file_log", "kind": "function", "doc": "Returns True if FileBlockInfo is the file log block
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.is_data", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.is_data", "kind": "function", "doc": "Returns True if FileBlockInfo is a data block or 3D data block
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.is_3d_data", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.is_3d_data", "kind": "function", "doc": "Returns True if FileBlockInfo is a 3D data block (i.e. data series)
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.is_data_status_match", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.is_data_status_match", "kind": "function", "doc": "Returns True if FileBlockInfo is a data status block and a match to the data_block_info argument.
\n\nThis function is used to match a data status block (contains metadata for data block) with its associated data\nblock (contains array data).
\n\n\n\n", "signature": "(self, data_block_info):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.get_label", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.get_label", "kind": "function", "doc": "is_match (bool): True if FileBlockInfo is data status block and input argument is matching data block
\n
Returns a friendly string label that describes the block type
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.get_data_key", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.get_data_key", "kind": "function", "doc": "If block is a data block, this function will return an shorthand key to reference that data.
\n\ne.g. t: transmission, a: absorption, sm: sample, rf: reference, smph: sample phase etc. If the block is not\na data block, it will return None.
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.Data", "modulename": "brukeropus.file.file", "qualname": "Data", "kind": "class", "doc": "Class containing array data and associated parameter/metadata from an OPUS file.
\n\nread_opus_file_bytes
FileBlockInfo
instance of a data blockFileBlockInfo
instance of a data status block which contains metadata about the data_info\nblock. This block is a parameter block.Parameter
class with metadata associated with the data block such as first x point: fxp
, last x\npoint: lxp
, number of points: npt
, date: dat
, time: tim
etc.numpy
array containing y values of data blocknumpy
array containing x values of data block. Units of x array are given by dxu
parameter.\n\n"}, {"fullname": "brukeropus.file.file.Data.__init__", "modulename": "brukeropus.file.file", "qualname": "Data.__init__", "kind": "function", "doc": "\n", "signature": "(\tfilebytes: bytes,\tdata_info: brukeropus.file.file.FileBlockInfo,\tdata_status_info: brukeropus.file.file.FileBlockInfo)"}, {"fullname": "brukeropus.file.file.Data.params", "modulename": "brukeropus.file.file", "qualname": "Data.params", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data.y", "modulename": "brukeropus.file.file", "qualname": "Data.y", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data.x", "modulename": "brukeropus.file.file", "qualname": "Data.x", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data.label", "modulename": "brukeropus.file.file", "qualname": "Data.label", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data.vel", "modulename": "brukeropus.file.file", "qualname": "Data.vel", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data3D", "modulename": "brukeropus.file.file", "qualname": "Data3D", "kind": "class", "doc": "wn: Returns the x array in wavenumber (cm\u207b\u00b9) units regardless of what units the x array was originally\n saved in. This is only valid for spectral data blocks such as sample, reference, transmission, etc., not\n interferogram or phase blocks.
\n
\n wl: Returns the x array in wavelength (\u00b5m) units regardless of what units the x array was originally\n saved in. This is only valid for spectral data blocks such as sample, reference, transmission, etc., not\n interferogram or phase blocks.
\n f: Returns the x array in modulation frequency units (Hz) regardless of what units the x array was\n originally saved in. This is only valid for spectral data blocks such as sample, reference, transmission,\n etc., not interferogram or phase blocks.
\n datetime: Returns adatetime
class of when the data was taken (extracted from data status parameter block).
\n xxx: the various three char parameter keys from theparams
attribute can be directly called from the \nData
class for convenience. Common parameters includedxu
(x units),mxy
(max y value),mny
(min y\n value), etc.
Class containing 3D array data (series of spectra) and associated parameter/metadata from an OPUS file.
\n\n\n\n", "bases": "Data"}, {"fullname": "brukeropus.file.file.Data3D.__init__", "modulename": "brukeropus.file.file", "qualname": "Data3D.__init__", "kind": "function", "doc": "\n", "signature": "(\tfilebytes: bytes,\tdata_info: brukeropus.file.file.FileBlockInfo,\tdata_status_info: brukeropus.file.file.FileBlockInfo)"}, {"fullname": "brukeropus.file.file.Data3D.params", "modulename": "brukeropus.file.file", "qualname": "Data3D.params", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data3D.y", "modulename": "brukeropus.file.file", "qualname": "Data3D.y", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data3D.x", "modulename": "brukeropus.file.file", "qualname": "Data3D.x", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data3D.num_spectra", "modulename": "brukeropus.file.file", "qualname": "Data3D.num_spectra", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data3D.label", "modulename": "brukeropus.file.file", "qualname": "Data3D.label", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Parameters", "modulename": "brukeropus.file.file", "qualname": "Parameters", "kind": "class", "doc": "wn: Returns the x array in wavenumber (cm\u207b\u00b9) units regardless of what units the x array was originally saved\n in. This is only valid for spectral data blocks such as sample, reference, transmission, etc., not\n interferogram or phase blocks.
\n
\n wl: Returns the x array in wavelength (\u00b5m) units regardless of what units the x array was originally saved\n in. This is only valid for spectral data blocks such as sample, reference, transmission, etc., not\n interferogram or phase blocks.
\n datetime: Returns adatetime
class of when the data was taken (extracted from data status parameter\n block).
\n xxx: the various three char parameter keys from the \"params\" attribute can be directly called from the data\n class for convenience. Several of these parameters return arrays, rather than singular values because they\n are recorded for every spectra in the series, e.g.npt
,mny
,mxy
,tim
,nsn
.
Class containing parameter metadata of an OPUS file.
\n\nParameters of an OPUS file are stored as key, val pairs, where the key is always three chars. For example, the\nbeamsplitter is stored in the \"bms\" attribute, source in \"src\" etc. A list of known keys, with friendly label can\nbe found in brukeropus.file.constants.PARAM_LABELS
. The keys in an OPUS file are not case sensitive, and stored\nin all CAPS (i.e. BMS
, SRC
, etc.) but this class uses lower case keys to follow python convention. The class is\ninitialized from a list of parameter FileBlockInfo
. The key, val items in blocks of the list are combined into\none parameter class, so care must be taken not to pass blocks that will overwrite each others keys. Analagous to a\ndict, the keys, values, and (key, val) can be iterated over using the functions: keys()
, values()
, and items()
\nrespectively.
brukeropus.file.parser.read_opus_file_bytes
FileBlockInfo
; every block in the list should be classified as a parameter block.FileBlockInfo
that is used to initialize the class. If input list contains a single data status\nFileBlockInfo
, attributes will include: fxv
, lxv
, npt
(first x-val, last x-val, number of points),\netc. Other blocks produce attributes such as: bms
, src
, apt
(beamsplitter, source, aperture) etc. A\nfull list of keys available in a given Parameters instance are given by the keys()
method.dat
(date) and tim
(time), the datetime
attribute of this class will\nbe set to a python datetime
object. Currently, only data status blocks are known to have these keys. If\ndat
and tim
are not present in the class, the datetime
attribute will return None
.Returns a dict_keys
class of all valid keys in the class (i.e. dict.keys())
Returns a dict_values
class of all the values in the class (i.e. dict.values())
Returns a dict_items
class of all the values in the class (i.e. dict.items())
Contains type and pointer information for all blocks of data in an OPUS file.
\n\nFileDirectory
information is decoded from the raw file bytes of an OPUS file. First the header is read which\nprovides the start location of the directory block, number of blocks in file, and maximum number of blocks the file\nsupports. Then it decodes the block pointer information from each entry of the file's directory block. Rather than\nstore all file blocks in a single list (as it is done in the OPUS file directory), this class sorts the blocks into\ncategories: data
, data_status
, params
, rf_params
, directory
, and file_log
. It also pairs the data\nblocks with their corresponding data_status
block to simplify grouping y data with the parameters that are used to\ngenerate x data and other data block specific metadata.
brukeropus.file.parser.read_opus_file_bytes
FileBlockInfo
that contain array data (e.g. sample, reference, phase)FileBlockInfo
that contain metadata specific to a data block (units, etc.)FileBlockInfo
that contain metadata about the measurement sampleFileBlockInfo
that contain metatdata about the reference measurementFileBlockInfo
for directory block that contains all the block info in the fileFileBlockInfo
of the file log (changes, etc.)FileBlockInfo
, data_status: FileBlockInfo
) which pairs the data status\nparameter block (time, x units, y units, etc.) with the data block it informsReturns bytes
of an OPUS file specified by filepath
(or None
).
Function determines if filepath
points to an OPUS file by reading the first four bytes which are always the same\nfor OPUS files. If filepath
is not a file, or points to a non-OPUS file, the function returns None
. Otherwise\nthe function returns the entire file as raw bytes
.
\n\n", "signature": "(filepath):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.get_block_type", "modulename": "brukeropus.file.parser", "qualname": "get_block_type", "kind": "function", "doc": "filebytes (bytes): raw bytes of OPUS file or
\nNone
(if filepath does not point to an OPUS file)
Converts an int32 block type code to a six-integer tuple block_type
.
This function is used to decode the type_int
from the directory block of an OPUS file into a tuple of integers.\nEach integer in the tuple provides information about the associated data block.
\n\n", "signature": "(type_int: int):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.parse_header", "modulename": "brukeropus.file.parser", "qualname": "parse_header", "kind": "function", "doc": "block_type (tuple): six-integer tuple which specifies the block type
\n
Parses the OPUS file header.
\n\nThe header of an OPUS file contains some basic information about the file including the version number, location of\nthe directory block, and number of blocks in the file. This header is first to be parsed as it specifies how to\nread the file directory block (which contains information about each block in the file)
\n\n\n\n", "signature": "(filebytes: bytes):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.parse_directory", "modulename": "brukeropus.file.parser", "qualname": "parse_directory", "kind": "function", "doc": "header_info (tuple):
\n
\n (
\n version (float64): program version number as a floating-point date (later versions always greater)
\n directory_start (int32): pointer to start location of directory block (number of bytes)
\n max_blocks (int32): maximum number of blocks supported by the directory block (this should only be\n relevant when trying to edit an OPUS file, i.e. when adding data blocks to a file)
\n num_blocks (int32): total number of blocks in the opus file
\n )
Parses directory block of OPUS file and yields block info for all blocks in the file as a generator.
\n\nThe directory block of an OPUS file contains information about every block in the file. The block information is\nstored as three int32 values: type_int
, size_int
, start
. type_int
is an integer representation of the block\ntype. The bits of this type_int
have meaning and are parsed into a tuple using get_block_type
. The size_int
is\nthe size of the block in 32-bit words. start
is the starting location of the block (in number of bytes).
\n\n", "signature": "(filebytes: bytes, directory_start: int, num_blocks: int):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.parse_param_block", "modulename": "brukeropus.file.parser", "qualname": "parse_param_block", "kind": "function", "doc": "block_info (tuple):
\n
\n (
\n block_type (tuple): six-integer tuple which specifies the block type (see:get_block_type
)
\n size (int): size (number of bytes) of the block
\n start (int): pointer to start location of the block (number of bytes)
\n )
Parses the bytes in a parameter block and yields the key, value pairs as a generator.
\n\nParameter blocks are in the form: XXX
, dtype_code
, size
, val
. XXX
is a three char abbreviation of the\nparameter (key). The value of the parameter is decoded according to the dtype_code
and size integers to be either:\nint
, float
, or string
.
\n\n", "signature": "(filebytes: bytes, size: int, start: int):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.get_dpf_dtype_count", "modulename": "brukeropus.file.parser", "qualname": "get_dpf_dtype_count", "kind": "function", "doc": "items (tuple): (key, value) pairs where key is three char string (lowercase) and value can be
\nint
,float
\n orstring
.
Returns numpy dtype and array count from the data point format (dpf) and block size (in bytes).
\n\n\n\n", "signature": "(dpf: int, size: int):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.parse_data_block", "modulename": "brukeropus.file.parser", "qualname": "parse_data_block", "kind": "function", "doc": "dtype (numpy.dtype):
\nnumpy
dtype for defining anndarray
to store the data\n count (int): length of array calculated from the block size and byte size of the dtype.
Parses the bytes in a data block (specified by size
and start
pointers) and returns a numpy
array.
Data blocks contain no metadata, only the y-values of a data array. Data arrays include: single-channel sample,\nreference, phase, interferograms, and a variety of resultant data (transmission, absorption, etc.). Every data\nblock should have a corresponding data status parameter block which can be used to generate the x-array values for\nthe data block. The data status block also specifies the data type of the data array with the DPF
parameter. It\nappears that OPUS currently exclusively stores data blocks as 32-bit floats, but has a reservation for 32-bit\nintegers when DPF
= 2.
\n\n", "signature": "(filebytes: bytes, size: int, start: int, dpf=1):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.parse_3d_data_block", "modulename": "brukeropus.file.parser", "qualname": "parse_3d_data_block", "kind": "function", "doc": "y_array (numpy.ndarray):
\nnumpy
array of y values contained in the data block
Parses the bytes in a 3D data block (series of spectra) and returns a data dict
containing data and metadata.
3D data blocks are structured differently than standard data blocks. In addition to the series of spectra, they\ninclude metadata for each of the spectrum. This function returns a dict
containing all the extracted information\nfrom the data block. The series spectra is formed into a 2D array while metadata captured for each spectra is\nformed into a 1D array (length = number of spectral measurements in the series).
\n\n", "signature": "(filebytes: bytes, start: int, dpf: int = 1):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.parse_file_log", "modulename": "brukeropus.file.parser", "qualname": "parse_file_log", "kind": "function", "doc": "data_dict (dict):
\ndict
containing all extracted information from the data block
\n {
\n version: file format version number (should be 0)
\n num_blocks: number of sub blocks; each sub block features a data spectra and associated metadata
\n offset: offset in bytes to the first sub data block
\n data_size: size in bytes of each sub data block
\n info_size: size in bytes of the metadata info block immediately following the sub data block
\n store_table: run numbers of the first and last blocks to keep track of skipped spectra
\n y: 2Dnumpy
array containing all spectra (C-order)
\n metadata arrays: series of metadata arrays in 1D array format (e.g.npt
,mny
,mxy
,tim
).\n The most useful one is generallytim
, which can be used as the time axis for 3D data plots.
\n }
Parses the file log in an OPUS file and returns a list of strings contained in the log.
\n\nThe file log block of an OPUS file contains some information about how the file was generated and edits that have\nbeen performed on the file. This function parses the file log as a list of strings using b'\u0000' as a seperator,\nand does not take any steps to parameterizing what is contained in the log. This log is generally not needed to\nretrieve the file data and metadata, but might be useful for inspecting the file.
\n\n\n\n", "signature": "(filebytes: bytes, size: int, start: int):", "funcdef": "def"}, {"fullname": "brukeropus.file.utils", "modulename": "brukeropus.file.utils", "kind": "module", "doc": "\n"}, {"fullname": "brukeropus.file.utils.find_opus_files", "modulename": "brukeropus.file.utils", "qualname": "find_opus_files", "kind": "function", "doc": "strings (list): list of strings found in the file log.
\n
Finds all files in a directory with a strictly numeric extension (OPUS file convention).
\n\nReturns a list of all files in directory that end in .# (e.g. file.0, file.1, file.1001, etc.). Setting recursive\nto true will search directory and all sub directories recursively. No attempt is made to verify the files are\nactually OPUS files (requires opening the file); the function simply looks for files that match the naming pattern.
\n\n\n\n", "signature": "(directory, recursive: bool = False):", "funcdef": "def"}, {"fullname": "brukeropus.file.utils.get_param_label", "modulename": "brukeropus.file.utils", "qualname": "get_param_label", "kind": "function", "doc": "filepaths (list): list of filepaths that match OPUS naming convention (numeric extension)
\n
Returns a short but descriptive label for 3-letter parameters. For example, bms returns Beamsplitter.
\n\nThe 3-letter parameter input is not case sensitive. This package includes the majority of parameters that OPUS\nuses, but in the event a parameter label is not known, this function will return: \"Unknown XXX\" where XXX is the\nunknown 3-letter parameter.
\n\n\n\n", "signature": "(param: str):", "funcdef": "def"}, {"fullname": "brukeropus.file.utils.get_type_code_label", "modulename": "brukeropus.file.utils", "qualname": "get_type_code_label", "kind": "function", "doc": "label (str): Human-readable string label for the parameter.
\n
Returns the type code label of a file block given the position index and value of the type code.
\n\nThe file blocks on an OPUS file feature six-integer type codes, for example (3, 1, 1, 2, 0, 0), that categorize the\ncontents of the file block. The positional index defines the category, while the value at that index defines the\nspecific type of that category. For example, the first integer (pos_idx=0), describes the type of data in the\nblock, if applicable:
\n\n0: Undefined or N/A,\n1: Real Part of Complex Data,\n2: Imaginary Part of Complex Data,\n3: Amplitude\n
\n\nThis package includes the majority of type codes that OPUS uses, but in the event a type code label is not known,\nthis function will return: \"Unknown 0 4\" where the first number is the position index, and the second is the\nunknown value integer.
\n\n\n\n", "signature": "(pos_idx: int, val: int):", "funcdef": "def"}, {"fullname": "brukeropus.file.utils.get_block_type_label", "modulename": "brukeropus.file.utils", "qualname": "get_block_type_label", "kind": "function", "doc": "label (str): human-readable string label that describes the type code.
\n
Converts a six-integer tuple block type into a human readable label.
\n\n\n\n", "signature": "(block_type: tuple):", "funcdef": "def"}, {"fullname": "brukeropus.file.utils.get_data_key", "modulename": "brukeropus.file.utils", "qualname": "get_data_key", "kind": "function", "doc": "label (str): human-readable string label
\n
Returns a shorthand key for a given data block type: sm, rf, igsm, a, t, r, etc.
\n\nDetermines if the data block type is an interferogram, single-channel, absorption, etc. and whether it is associated\nwith the sample or reference channel and returns a shortand key-like label: sm, rf, igsm, igrf, a, t, r, etc. For\nthe full data label (e.g. Sample Spectrum, Absorbance) use: get_block_type_label.\nThis package includes the majority of type codes that OPUS uses, but in the event a type code label is not known,\nthis function will return: \"_33\" or \"sm_33\" where 33 will change to the unkown block_type integer value.
\n\n\n\n", "signature": "(block_type: tuple):", "funcdef": "def"}, {"fullname": "brukeropus.file.utils.parse_file_and_print", "modulename": "brukeropus.file.utils", "qualname": "parse_file_and_print", "kind": "function", "doc": "key (str): shorthand string label that can be utilized as a data key (e.g. \"sm\", \"igrf\", \"a\")
\n
Parses an OPUS file and prints the block information as it goes along to the console.
\n\nThis function demonstrates the basic usage and interaction of the parsing functions. It\ncan also be used to diagnose a file parsing issue if one comes up.
\n\nbrukeropus
is a Python package for interacting with Bruker's OPUS spectroscopy software. Currently, the package can\nread OPUS data files and communicate/control OPUS software using the DDE communication protocol)
brukeropus
requires python 3.6+
and numpy
, but matplotlib
is needed to run the plotting examples. You can\ninstall with pip:
pip install brukeropus\n
\nbrukeropus
provides direct imports to the following:
from brukeropus import find_opus_files, read_opus, OPUSFile, Opus\n
\nAll other file functions or classes can be directly imported from the brukeropus.file
or brukeropus.control
\nsubmodules, e.g.:
from brukeropus.file import parse_file_and_print\n
\nIt is recommended that you do not import from the fully qualified namespace, e.g.:
\n\nfrom brukeropus.file.utils import parse_file_and_print\n
\nas that namespace is subject to change. Instead import directly from brukeropus
or its first level submodules.
from brukeropus import read_opus\nfrom matplotlib import pyplot as plt\n\nopus_file = read_opus('file.0') # Returns an OPUSFile class\n\nopus_file.print_parameters() # Pretty prints all metadata in the file to the console\n\nif 'a' in opus_file.data_keys: # If absorbance spectra was extracted from file\n plt.plot(opus_file.a.x, opus_file.a.y) # Plot absorbance spectra\n plt.title(opus_file.sfm + ' - ' + opus_file.snm) # Sets plot title to Sample Form - Sample Name\n plt.show() # Display plot\n
\nMore detailed documentation on the file submodule can be found in brukeropus.file
from brukeropus import opus, read_opus\nfrom matplotlib import pyplot as plt\n\nopus = Opus() # Connects to actively running OPUS software\n\napt_options = opus.get_param_options('apt') # Get all valid aperture settings\n\nfor apt in apt_options[2:-2]: # Loop over all but the two smallest and two largest aperature settings\n filepath = opus.measure_sample(apt=apt, nss=10, unload=True) # Perform measurement and unload file from OPUS\n data = read_opus(filepath) # Read OPUS file from measurement\n plt.plot(data.sm.x, data.sm.y, label=apt) # Plot single-channel sample spectra\nplt.legend()\nplt.show()\n
\nMore detailed documentation on the control submodule can be found in brukeropus.control
.
The brukeropus.control
submodule of brukeropus
includes the Opus
class for communicating with OPUS software. The\nOpus
class currently supports communication through the Dynamic Data Exchange (DDE) protocol. This class can be used\nto script measurement sweeps and perform various low-level operations (e.g. move mirrors, rotate polarizers, etc.). In\norder to communicate with OPUS, the software must be open, logged in, and running on the same PC as brukeropus
.
from brukeropus import Opus\n\nopus = Opus() # initialization of class automatically connects to open OPUS software\nprint(opus.get_version()) # prints the current OPUS software version\n
\nopus = Opus()\nparam = 'vel'\nprint(opus.get_param_label(param))\nprint(opus.get_param_options(param))\n
\nfrom brukeropus import opus, read_opus\nfrom matplotlib import pyplot as plt\n\nopus = Opus() # Connects to actively running OPUS software\n\napt_options = opus.get_param_options('apt') # Get all valid aperture settings\n\nfor apt in apt_options[2:-2]: # Loop over all but the two smallest and two largest aperature settings\n filepath = opus.measure_sample(apt=apt, nss=10, unload=True) # Perform measurement and unload file from OPUS\n data = read_opus(filepath) # Read OPUS file from measurement\n plt.plot(data.sm.x, data.sm.y, label=apt) # Plot single-channel sample spectra\nplt.legend()\nplt.show()\n
\nFor complete Opus
documentation, see: brukeropus.control.opus
Retrieve a function from a library, and set the data types.
\n", "signature": "(\tlibname,\tfuncname,\trestype=None,\targtypes=(),\t_libcache={'user32': <WinDLL 'user32', handle 7fff631d0000>}):", "funcdef": "def"}, {"fullname": "brukeropus.control.dde.DDECALLBACK", "modulename": "brukeropus.control.dde", "qualname": "DDECALLBACK", "kind": "variable", "doc": "\n", "default_value": "<class 'ctypes.WINFUNCTYPE.<locals>.WinFunctionType'>"}, {"fullname": "brukeropus.control.dde.DDE", "modulename": "brukeropus.control.dde", "qualname": "DDE", "kind": "class", "doc": "Object containing all the DDE functions
\n"}, {"fullname": "brukeropus.control.dde.DDE.AccessData", "modulename": "brukeropus.control.dde", "qualname": "DDE.AccessData", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.ClientTransaction", "modulename": "brukeropus.control.dde", "qualname": "DDE.ClientTransaction", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.Connect", "modulename": "brukeropus.control.dde", "qualname": "DDE.Connect", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.CreateStringHandle", "modulename": "brukeropus.control.dde", "qualname": "DDE.CreateStringHandle", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.Disconnect", "modulename": "brukeropus.control.dde", "qualname": "DDE.Disconnect", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.GetLastError", "modulename": "brukeropus.control.dde", "qualname": "DDE.GetLastError", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.Initialize", "modulename": "brukeropus.control.dde", "qualname": "DDE.Initialize", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.FreeDataHandle", "modulename": "brukeropus.control.dde", "qualname": "DDE.FreeDataHandle", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.FreeStringHandle", "modulename": "brukeropus.control.dde", "qualname": "DDE.FreeStringHandle", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.QueryString", "modulename": "brukeropus.control.dde", "qualname": "DDE.QueryString", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.UnaccessData", "modulename": "brukeropus.control.dde", "qualname": "DDE.UnaccessData", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDE.Uninitialize", "modulename": "brukeropus.control.dde", "qualname": "DDE.Uninitialize", "kind": "variable", "doc": "\n", "default_value": "<_FuncPtr object>"}, {"fullname": "brukeropus.control.dde.DDEError", "modulename": "brukeropus.control.dde", "qualname": "DDEError", "kind": "class", "doc": "Exception raise when a DDE errpr occures.
\n", "bases": "builtins.RuntimeError"}, {"fullname": "brukeropus.control.dde.DDEError.__init__", "modulename": "brukeropus.control.dde", "qualname": "DDEError.__init__", "kind": "function", "doc": "\n", "signature": "(msg, idInst=None)"}, {"fullname": "brukeropus.control.dde.DDEClient", "modulename": "brukeropus.control.dde", "qualname": "DDEClient", "kind": "class", "doc": "The DDEClient class.
\n\nUse this class to create and manage a connection to a service/topic. To get\nclassbacks subclass DDEClient and overwrite callback.
\n"}, {"fullname": "brukeropus.control.dde.DDEClient.__init__", "modulename": "brukeropus.control.dde", "qualname": "DDEClient.__init__", "kind": "function", "doc": "Create a connection to a service/topic.
\n", "signature": "(service, topic)"}, {"fullname": "brukeropus.control.dde.DDEClient.advise", "modulename": "brukeropus.control.dde", "qualname": "DDEClient.advise", "kind": "function", "doc": "Request updates when DDE data changes.
\n", "signature": "(self, item, stop=False):", "funcdef": "def"}, {"fullname": "brukeropus.control.dde.DDEClient.execute", "modulename": "brukeropus.control.dde", "qualname": "DDEClient.execute", "kind": "function", "doc": "Execute a DDE command.
\n", "signature": "(self, command, timeout=5000):", "funcdef": "def"}, {"fullname": "brukeropus.control.dde.DDEClient.request", "modulename": "brukeropus.control.dde", "qualname": "DDEClient.request", "kind": "function", "doc": "Request data from DDE service.
\n", "signature": "(self, item, timeout=5000):", "funcdef": "def"}, {"fullname": "brukeropus.control.dde.DDEClient.callback", "modulename": "brukeropus.control.dde", "qualname": "DDEClient.callback", "kind": "function", "doc": "Calback function for advice.
\n", "signature": "(self, value, item=None):", "funcdef": "def"}, {"fullname": "brukeropus.control.dde.WinMSGLoop", "modulename": "brukeropus.control.dde", "qualname": "WinMSGLoop", "kind": "function", "doc": "Run the main windows message loop.
\n", "signature": "():", "funcdef": "def"}, {"fullname": "brukeropus.control.opus", "modulename": "brukeropus.control.opus", "kind": "module", "doc": "\n"}, {"fullname": "brukeropus.control.opus.ERROR_CODES", "modulename": "brukeropus.control.opus", "qualname": "ERROR_CODES", "kind": "variable", "doc": "\n", "default_value": "{1: 'Not an Opus Command', 2: 'Unknown Opus Command', 3: 'Missing Square Bracket in Command', 4: 'Function Not Available (Possible missing parameter)', 5: 'Parameter Name Is Incorrect', 6: 'Parameter Set Is Incomplete', 7: 'File Parameter Is Incorrectly Formatted', 8: 'File(s) Missing Or Corrupt', 9: 'Opus Could Not Complete The Command'}"}, {"fullname": "brukeropus.control.opus.Opus", "modulename": "brukeropus.control.opus", "qualname": "Opus", "kind": "class", "doc": "Class for communicating with currently running OPUS software using DDE interface. Class automatically attempts\nto connect to OPUS software upon initialization.
\n"}, {"fullname": "brukeropus.control.opus.Opus.dde", "modulename": "brukeropus.control.opus", "qualname": "Opus.dde", "kind": "variable", "doc": "\n", "default_value": "None"}, {"fullname": "brukeropus.control.opus.Opus.connected", "modulename": "brukeropus.control.opus", "qualname": "Opus.connected", "kind": "variable", "doc": "\n", "default_value": "False"}, {"fullname": "brukeropus.control.opus.Opus.error_string", "modulename": "brukeropus.control.opus", "qualname": "Opus.error_string", "kind": "variable", "doc": "\n", "default_value": "'Error'"}, {"fullname": "brukeropus.control.opus.Opus.connect", "modulename": "brukeropus.control.opus", "qualname": "Opus.connect", "kind": "function", "doc": "Connects class to OPUS software through the DDE interface. Sets the connected
attribute to True
if\nsuccessful. By default, initializing an Opus
class will automatically attempt to connect to OPUS.
Disconnects DDE client/server connection.
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.raw_query", "modulename": "brukeropus.control.opus", "qualname": "Opus.raw_query", "kind": "function", "doc": "Sends command/request string (req_str
) to OPUS and returns the response in byte format.
\n\n", "signature": "(self, req_str: str, timeout=10000):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.parse_response", "modulename": "brukeropus.control.opus", "qualname": "Opus.parse_response", "kind": "function", "doc": "response: response from OPUS software through DDE request in bytes format.
\n
Parses the byte response from a raw DDE request query. If an error is detected in the request, an Exception\nis raised. If successful, a boolean, string or list of strings will be returned as appropriate.
\n\n\n\n", "signature": "(self, byte_response: bytes, decode='ascii'):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.query", "modulename": "brukeropus.control.opus", "qualname": "Opus.query", "kind": "function", "doc": "response: parsed response from OPUS software (bool, string, or list of strings depending on request)
\n
Sends a command/request and returns the parsed response.
\n\n\n\n", "signature": "(self, req_str: str, timeout=10000, decode='ascii'):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.close_opus", "modulename": "brukeropus.control.opus", "qualname": "Opus.close_opus", "kind": "function", "doc": "response: parsed response from OPUS software (bool, string, or list of strings depending on request)
\n
Closes the OPUS application. Returns True
if successful.
Get the label for a three character parameter code (e.g. BMS, APT, DTC, etc...).
\n\n\n\n", "signature": "(self, param: str):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.get_param_options", "modulename": "brukeropus.control.opus", "qualname": "Opus.get_param_options", "kind": "function", "doc": "label: short descriptive label that defines the parameter
\n
Get the parameter setting options for a three character parameter code. Only valid for\nenum type parameters (e.g. BMS, APT, DTC, etc...).
\n\n\n\n", "signature": "(self, param: str):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.get_version", "modulename": "brukeropus.control.opus", "qualname": "Opus.get_version", "kind": "function", "doc": "options: list of valid options (strings) for the given parameter
\n
Get the OPUS software version information
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.get_opus_path", "modulename": "brukeropus.control.opus", "qualname": "Opus.get_opus_path", "kind": "function", "doc": "Get the absolute path to the OPUS software directory (where PARAMTEXT.bin and other instrument specific files\nare located)
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.send_command", "modulename": "brukeropus.control.opus", "qualname": "Opus.send_command", "kind": "function", "doc": "Used to send \"Direct Commands\" to the optics bench. Useful for manually moving motors, etc. from accessories\nand other low-level operations such as controlling the scanning mirror movement.
\n\n\n\n\nsend_command('VAC=5') # vents the sample compartment\n send_command('VAC=4') # evacuates sample compartment
\n
\n\n", "signature": "(self, text_command: str, timeout=10000):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.evacuate_sample", "modulename": "brukeropus.control.opus", "qualname": "Opus.evacuate_sample", "kind": "function", "doc": "response: parsed response from OPUS software (typically boolean confirmation)
\n
Evacuates the sample compartment
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.vent_sample", "modulename": "brukeropus.control.opus", "qualname": "Opus.vent_sample", "kind": "function", "doc": "Vents the sample compartment
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.close_flaps", "modulename": "brukeropus.control.opus", "qualname": "Opus.close_flaps", "kind": "function", "doc": "Closes vacumm flaps between optics bench and sample compartment
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.open_flaps", "modulename": "brukeropus.control.opus", "qualname": "Opus.open_flaps", "kind": "function", "doc": "Opens vacumm flaps between optics bench and sample compartment
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.unload_file", "modulename": "brukeropus.control.opus", "qualname": "Opus.unload_file", "kind": "function", "doc": "Unloads a file from the OPUS software from its filepath
\n\n", "signature": "(self, filepath: str):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.unload_all", "modulename": "brukeropus.control.opus", "qualname": "Opus.unload_all", "kind": "function", "doc": "response:
\nTrue
if successful.
Unloads all files from OPUS software
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.measure_ref", "modulename": "brukeropus.control.opus", "qualname": "Opus.measure_ref", "kind": "function", "doc": "Takes a reference measurement using the current settings from advanced experiment. Also\ntakes option **kwargs input which use the OPUS 3-letter parameter keys and values as input\nto customize the measurement. example:
\n\nmeasure_ref(nrs=100, res=4) # measures reference with current settings but overriding averages to 100 and\n resolution to 4\n
\n\n\n\n", "signature": "(self, timeout=1000000, **kwargs):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.measure_sample", "modulename": "brukeropus.control.opus", "qualname": "Opus.measure_sample", "kind": "function", "doc": "response:
\nTrue
if successful
Takes a reference measurement using the current settings from advanced experiment. Also\ntakes option **kwargs input which use the OPUS 3-letter parameter keys and values as input\nto customize the measurement. example:
\n\nmeasure_sample(nss=100, res=4) # measures sample with current settings but overriding averages to 100 and\n resolution to 4\n
\n\n\n\n", "signature": "(self, unload=False, timeout=1000000, **kwargs):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.check_signal", "modulename": "brukeropus.control.opus", "qualname": "Opus.check_signal", "kind": "function", "doc": "filepath: absolute filepath to measured sample file
\n
Performs a quick (typically 1 sample) measurement using the current FTIR settings. Current settings can be\noverridden using **kwargs. After measurement is finished, the file is unloaded from OPUS and deleted. The\nfunction returns an OPUSFile
object before it deletes the quick measurement file.
\n\n", "signature": "(self, nss=1, **kwargs):", "funcdef": "def"}, {"fullname": "brukeropus.control.opus.Opus.save_ref", "modulename": "brukeropus.control.opus", "qualname": "Opus.save_ref", "kind": "function", "doc": "opus_file:
\nOPUSFile
object generated by quick measurement
Saves current reference to file (according to current filename and path set in advanced experiment) and\nreturns the filename.
\n\n\n\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file", "modulename": "brukeropus.file", "kind": "module", "doc": "filepath: absolute path to saved reference file
\n
The brukeropus.file
submodule of brukeropus
includes all the functions and classes for reading and exploring OPUS\nfiles. This includes both high-level functions like read_opus
that returns an OPUSFile
class, as well as low-level\nparsing functions like parse_directory
that returns data extracted directly from the binary OPUS file bytes. This\noverview documentation will focus on the high-level functions which will be useful for most users. If you are\ninterested in using the low-level parsing functions, perhaps to make your own data class or customize how files are\nread, refer to: brukeropus.file.parser
which contains all the low-level parsing functions.
OPUS files are typically saved with a numeric file extension (e.g. file.0, file.1, file.1001). This makes searching for\na list of OPUS files in a directory a little more cumbersome than a traditional \"*.csv\" search. To address this,\nbrukeropus
includes a find_opus_files
function:
from brukeropus import find_opus_files\n\nfilepaths = find_opus_files(r'path\\to\\opus\\files', recursive=True)\n
\nWhich will assign a list of filepaths that match the numeric extension formatting of OPUS files. For full documentation,\nsee brukeropus.file.utils.find_opus_files
.
brukeropus
parses OPUS files and assembles them into an OPUSFile
object that contains the extracted data (and\nmetadata) within the file. You can generate an OPUSFile
object in one of two ways:
from brukeropus import read_opus, OPUSFile\n\nfilepath = r'path\\to\\opusfile.0'\n\ndata = read_opus(filepath)\nsame_data = OPUSFile(filepath)\n
\nIn the above code, data
and same_data
are both OPUSFile
objects with identical data.
OPUSFile
ClassOPUS files all start with the same first four magic bytes. If the file does not start with these bytes (i.e. is not\na valid OPUS file), the OPUSFile class will logically evaluate to false
:
data = read_opus('file.pdf')\nif data:\n print(data)\nelse:\n print(data.filepath, 'is not an OPUS file')\n
\nTo view all parameter metadata in the file, you can print to the console using the class method: print_parameters
.\nThis will let you view all the key, value parameter data extracted from the file with labels for what the parameter keys\nare referring to wherever known.
data = read_opus('file.0')\ndata.print_parameters()\n
\nExample
print_parameters
Output
\n
====================================================================================================\n Optical Parameters\nKey Label Value\nACC Accessory TRANS *010A984F\nAPR ATR Pressure 0\nAPT Aperture Setting 1 mm\nBMS Beamsplitter KBr-Broadband\nCHN Measurement Channel Sample Compartment\nDTC Detector RT-DLaTGS [Internal Pos.1]\nHPF High Pass Filter 0\nLPF Low Pass Filter 10.0\nLPV Variable Low Pass Filter (cm-1) 4000\nOPF Optical Filter Setting Open\nPGN Preamplifier Gain 3\nRDX Extended Ready Check 0\nSRC Source MIR\nVEL Scanner Velocity 10.0\nADC External Analog Signals 0\nSON External Sync Off\n\n====================================================================================================\n Fourier Transform Parameters\nKey Label Value\nAPF Apodization Function B3\nHFQ End Frequency Limit for File 500.0\nLFQ Start Frequency Limit for File 10000.0\nNLI Nonlinearity Correction 0\nPHR Phase Resolution 100.0\nPHZ Phase Correction Mode ML\nSPZ Stored Phase Mode NO\nZFF Zero Filling Factor 2\n\n====================================================================================================\n Acquisition Parameters\nKey Label Value\nADT Additional Data Treatment 0\nAQM Acquisition Mode DD\nCFE Low Intensity Power Mode with DTGS 0\nCOR Correlation Test Mode 0\nDEL Delay Before Measurement 0\nDLY Stabilization Delay 0\nHFW Wanted High Freq Limit 15000.0\nLFW Wanted Low Freq Limit 0.0\nNSS Number of Sample Scans 50\nPLF Result Spectrum Type AB\nRES Resolution (cm-1) 4.0\nSOT Sample Scans or Time 0\nTCL Command Line for Additional Data Tr...\nTDL To Do List 16777271\nSGN Sample Signal Gain 1\n\n====================================================================================================\n Sample Origin Parameters\nKey Label Value\nBLD Building\nCNM Operator Name Duran\nCPY Company\nDPM Department\nEXP Experiment MWIR-LWIR_Trans_FileNameFormat.XPM\nLCT Location\nSFM Sample Form Atm-MWIR (All A)\nSNM Sample Name File Test\nXPP Experiment Path C:\\Users\\Public\\Documents\\Bruker\\OPUS_8.1.29\\XPM\nIST Instrument Status OK\nCPG Character Encoding Code Page 1252\nUID Universally Unique Identifier 0d1348c2-3a2c-41c9-b521-bdaf0a23710c\n\n====================================================================================================\n Instrument Status Parameters\nKey Label Value\nHFL High Folding Limit 15795.820598\nLFL Low Folding Limit 0.0\nLWN Laser Wavenumber 15795.820598\nABP Absolute Peak Pos in Laser*2 52159\nSSP Sample Spacing Divisor 1\nASG Actual Signal Gain 1\nARG Actual Reference Gain 1\nASS Number of Sample Scans 50\nGFW Number of Good Forward Scans 25\nGBW Number of Good Backward Scans 25\nBFW Number of Bad Forward Scans 0\nBBW Number of Bad Backward Scans 0\nPKA Peak Amplitude 1409\nPKL Peak Location 7364\nPRA Backward Peak Amplitude 1356\nPRL Backward Peak Location 7363\nP2A Peak Amplitude Channel 2 1\nP2L Peak Location Channel 2 1\nP2R Backward Peak Amplitude Channel 2 1\nP2K Backward Peak Location Channel 2 1\nDAQ Data Acquisition Status 0\nAG2 Actual Signal Gain Channel 2 1\nHUM Relative Humidity Interferometer 14\nSSM Sample Spacing Multiplier 1\nRSN Running Sample Number 565\nCRR Correlation Rejection Reason 0\nSRT Start Time (sec) 1556890484.642\nDUR Duration (sec) 42.433990478515625\nTSC Scanner Temperature 27.8\nMVD Max Velocity Deviation 0.1158025860786438\nPRS Pressure Interferometer (hPa) 1009.9999700000001\nAN1 Analog Signal 1 0.22596596493037535\nAN2 Analog Signal 2 3.459206583321489\nVSN Firmware Version 2.450 Oct 10 2014\nSRN Instrument Serial Number 1135\nCAM Coaddition Mode 0\nINS Instrument Type VERTEX 80V\nFOC Focal Length 100.0\nRDY Ready Check 1\n\n====================================================================================================\n Reference Instrument Status Parameters\nKey Label Value\nHFL High Folding Limit 15795.820598\nLFL Low Folding Limit 0.0\nLWN Laser Wavenumber 15795.820598\nABP Absolute Peak Pos in Laser*2 52159\nSSP Sample Spacing Divisor 1\nARG Actual Reference Gain 1\nASG Actual Signal Gain 1\nASS Number of Sample Scans 1\nGFW Number of Good Forward Scans 1\nGBW Number of Good Backward Scans 0\nBFW Number of Bad Forward Scans 0\nBBW Number of Bad Backward Scans 0\nPKA Peak Amplitude 1644\nPKL Peak Location 7364\nPRA Backward Peak Amplitude 1\nPRL Backward Peak Location -1\nP2A Peak Amplitude Channel 2 1\nP2L Peak Location Channel 2 1\nP2R Backward Peak Amplitude Channel 2 1\nP2K Backward Peak Location Channel 2 1\nDAQ Data Acquisition Status 0\nAG2 Actual Signal Gain Channel 2 1\nHUM Relative Humidity Interferometer 0\nSSM Sample Spacing Multiplier 1\nRSN Running Sample Number 5816\nCRR Correlation Rejection Reason 0\nSRT Start Time (sec) 1556890282.358\nDUR Duration (sec) 0.7919998168945312\nTSC Scanner Temperature 27.8\nMVD Max Velocity Deviation 0.10553144663572311\nPRS Pressure Interferometer (hPa) 2.01999\nAN1 Analog Signal 1 0.22577181458473206\nAN2 Analog Signal 2 4.0960001945495605\nVSN Firmware Version 2.450 Oct 10 2014\nSRN Instrument Serial Number 1135\nCAM Coaddition Mode 0\nINS Instrument Type VERTEX 80V\nFOC Focal Length 100.0\nRDY Ready Check 1\nARS Number of Reference Scans 1\n\n====================================================================================================\n Reference Optical Parameters\nKey Label Value\nACC Accessory TRANS *010A984F\nAPR ATR Pressure 0\nAPT Aperture Setting 1 mm\nBMS Beamsplitter KBr-Broadband\nDTC Detector RT-DLaTGS [Internal Pos.1]\nHPF High Pass Filter 0\nLPF Low Pass Filter 10.0\nLPV Variable Low Pass Filter (cm-1) 4000\nOPF Optical Filter Setting Open\nPGR Reference Preamplifier Gain 3\nRCH Reference Measurement Channel Sample Compartment\nRDX Extended Ready Check 0\nSRC Source MIR\nVEL Scanner Velocity 10.0\nADC External Analog Signals 0\nSON External Sync Off\n\n====================================================================================================\n Reference Acquisition Parameters\nKey Label Value\nADT Additional Data Treatment 0\nAQM Acquisition Mode DD\nCFE Low Intensity Power Mode with DTGS 0\nCOR Correlation Test Mode 0\nDEL Delay Before Measurement 0\nDLY Stabilization Delay 0\nHFW Wanted High Freq Limit 15000.0\nLFW Wanted Low Freq Limit 0.0\nNSR Number of Background Scans 1\nPLF Result Spectrum Type TR\nRES Resolution (cm-1) 4.0\nRGN Reference Signal Gain 1\nSTR Scans or Time (Reference) 0\nTCL Command Line for Additional Data Tr...\nTDL To Do List 16777271\n\n====================================================================================================\n Reference Fourier Transform Parameters\nKey Label Value\nAPF Apodization Function B3\nHFQ End Frequency Limit for File 500.0\nLFQ Start Frequency Limit for File 10000.0\nNLI Nonlinearity Correction 0\nPHR Phase Resolution 100.0\nPHZ Phase Correction Mode ML\nSPZ Stored Phase Mode NO\nZFF Zero Filling Factor 2\n
\nYou can access a specific parameter simply by calling the key as a direct attribute of the class (case insensitive). You\ncan also get the human-readable label using the get_param_label
function:
from brukeropus.file import get_param_label\ndata = read_opus('file.0')\nprint(get_param_label('bms') + ':', data.bms)\nprint(get_param_label('src') + ':', data.src)\n
\nBeamsplitter: KBr-Broadband\nSource: MIR\n
\nYou will notice in the example output that some keys (e.g. zero filling factor zff
) may have two entries: one for the\nsample measurement and another for the reference. By default, the sample parameters are accessible directly from the\nOPUSFile
class, while the reference parameters can be accessed through the rf_params
attribute.
data = read_opus('file.0')\nprint('Sample ZFF:', data.zff, 'Reference ZFF:', data.rf_params.zff)\n
\nSample ZFF: 2 Reference ZFF: 2\n
\nYou can also iterate over the parameters using the familiar keys()
, values()
, and items()
functions using the\nparams
or rf_params
attributes:
data = read_opus('file.0')\nfor key, val in data.params.items():\n print(key + ':', val)\n
\nacc: TRANS *010A984F\napr: 0\napt: 1 mm\nbms: KBr-Broadband\nchn: Sample Compartment\ndtc: RT-DLaTGS [Internal Pos.1]\nhpf: 0\nlpf: 10.0\nlpv: 4000\nopf: Open\npgn: 3\n... continued ...\n
\nDepending on the settings used to save the OPUS file, different data blocks can be stored. To retrieve a list of data\nblocks stored in the OPUS File, use the data_keys
attribute:
data = read_opus('file.0')\nprint(data.data_keys)\n
\n['igsm', 'phsm', 'sm', 'a', 'igrf', 'rf']\n
\nEach key is also an attribute of the OPUSFile
instance that returns either a Data
or Data3D
class. You can get\nthe x
and y
array values (in the units they were saved in) as direct attributes to the Data
class:
data = read_opus('file.0')\nplt.plot(data.a.x, data.a.y)\nplt.ylim((0, 1))\nplt.show()\n
\nFor spectra with wavenumber as valid unit (e.g. single-channel or ratioed spectra), the x
array can be given in cm\u207b\u00b9
\nor \u00b5m
units by using the attributes wn
or wl
respectively:
data = read_opus('file.0')\nplt.plot(data.sm.wl, data.sm.y)\nplt.show()\n
\nYou can also iterate over all data spectra in the file using the iter_data()
method:
data = read_opus('file.0')\nfor d in data.iter_data():\n print(d.label, '(' + d.datetime.isoformat(' ') + ')')\n
\nSample Interferogram (2019-05-03 13:34:44.641000)\nSample Phase (2019-05-03 13:34:44.641000)\nSample Spectrum (2019-05-03 13:34:44.641000)\nAbsorbance (2019-05-03 13:34:44.641000)\nReference Interferogram (2019-05-03 13:31:22.358000)\nReference Spectrum (2019-05-03 13:31:22.358000)\n
\nEach data block in an OPUS file also contains a small parameter block with information such as the min/max y-value\n(mny, mxy), x-units (dxu), number of data points (npt), etc. These can be accessed as direct attributes to the Data
\nclass, or through the params
attribute:
data = read_opus('file.0')\nprint('Sample spectra y-min:', data.sm.mny, 'y-max:', data.sm.mxy)\n
\nSample spectra y-min: 1.2147593224653974e-05 y-max: 0.03543896973133087\n
\nFor full API documentation, see:
\nOPUSFile
: brukeropus.file.file.OPUSFile
\nData
: brukeropus.file.file.Data
\nData3D
: brukeropus.file.file.Data3D
Return an OPUSFile
object from an OPUS file filepath.
\n\n\n\n\n\ndata = read_opus(filepath)\ndata = OPUSFile(filepath)\n
\n\n", "signature": "(filepath):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.OPUSFile", "modulename": "brukeropus.file.file", "qualname": "OPUSFile", "kind": "class", "doc": "opus_file (
\nOPUSFile
): an instance of theOPUSFile
class containing all data/metadata extracted from the\n file.
Class that contains the data and metadata contained in a bruker OPUS file.
\n\nOPUSFile
object.bool
): True if filepath points to an OPUS file, False otherwise. Also returned for dunder \n__bool__()
Parameters
): class containing all general parameter metadata for the OPUS file. To save typing, the\nthree char parameters from params also become attributes of the OPUSFile
class (e.g. bms, apt, src) Parameters
): class containing all reference parameter metadata for the OPUS file. Data
or Data3D
.datetime
): Returns the most recent datetime of all the data blocks stored in the file (typically\nresult spectra)FileDirectory
): class containing information about all the various data blocks in the file.\n\n"}, {"fullname": "brukeropus.file.file.OPUSFile.__init__", "modulename": "brukeropus.file.file", "qualname": "OPUSFile.__init__", "kind": "function", "doc": "\n", "signature": "(filepath: str)"}, {"fullname": "brukeropus.file.file.OPUSFile.filepath", "modulename": "brukeropus.file.file", "qualname": "OPUSFile.filepath", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.OPUSFile.print_parameters", "modulename": "brukeropus.file.file", "qualname": "OPUSFile.print_parameters", "kind": "function", "doc": "sm: Single-channel sample spectra
\n
\n rf: Single-channel reference spectra
\n igsm: Sample interferogram
\n igrf: Reference interferogram
\n phsm: Sample phase
\n phrf: Reference phase
\n a: Absorbance
\n t: Transmittance
\n r: Reflectance
\n km: Kubelka-Munk
\n tr: Trace (Intensity over Time)
\n gcig: gc File (Series of Interferograms)
\n gcsc: gc File (Series of Spectra)
\n ra: Raman
\n e: Emission
\n dir: Directory
\n p: Power
\n logr: log(Reflectance)
\n atr: ATR
\n pas: Photoacoustic
Prints all the parameter metadata to the console (organized by block)
\n", "signature": "(self, key_width=7, label_width=40, value_width=53):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.OPUSFile.iter_data", "modulename": "brukeropus.file.file", "qualname": "OPUSFile.iter_data", "kind": "function", "doc": "Generator that yields the various Data classes from the OPUSFile
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo", "kind": "class", "doc": "Contains type, size and location information about an OPUS file block.
\n\nThis information is parsed from the directory block of an OPUS file and provides the information needed to parse the\nblock.
\n\nReturns True if FileBlockInfo is a data status parameter block
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.is_rf_param", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.is_rf_param", "kind": "function", "doc": "Returns True if FileBlockInfo is a parameter block associated with the reference measurement
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.is_param", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.is_param", "kind": "function", "doc": "Returns True if FileBlockInfo is a parameter block
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.is_directory", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.is_directory", "kind": "function", "doc": "Returns True if FileBlockInfo is the directory block
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.is_file_log", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.is_file_log", "kind": "function", "doc": "Returns True if FileBlockInfo is the file log block
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.is_data", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.is_data", "kind": "function", "doc": "Returns True if FileBlockInfo is a data block or 3D data block
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.is_3d_data", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.is_3d_data", "kind": "function", "doc": "Returns True if FileBlockInfo is a 3D data block (i.e. data series)
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.is_data_status_match", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.is_data_status_match", "kind": "function", "doc": "Returns True if FileBlockInfo is a data status block and a match to the data_block_info argument.
\n\nThis function is used to match a data status block (contains metadata for data block) with its associated data\nblock (contains array data).
\n\n\n\n", "signature": "(self, data_block_info):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.get_label", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.get_label", "kind": "function", "doc": "is_match (bool): True if FileBlockInfo is data status block and input argument is matching data block
\n
Returns a friendly string label that describes the block type
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.get_data_key", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.get_data_key", "kind": "function", "doc": "If block is a data block, this function will return an shorthand key to reference that data.
\n\ne.g. t: transmission, a: absorption, sm: sample, rf: reference, smph: sample phase etc. If the block is not\na data block, it will return None.
\n", "signature": "(self):", "funcdef": "def"}, {"fullname": "brukeropus.file.file.FileBlockInfo.bytes", "modulename": "brukeropus.file.file", "qualname": "FileBlockInfo.bytes", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data", "modulename": "brukeropus.file.file", "qualname": "Data", "kind": "class", "doc": "Class containing array data and associated parameter/metadata from an OPUS file.
\n\nread_opus_file_bytes
FileBlockInfo
instance of a data blockFileBlockInfo
instance of a data status block which contains metadata about the data_info\nblock. This block is a parameter block.Parameter
class with metadata associated with the data block such as first x point: fxp
, last x\npoint: lxp
, number of points: npt
, date: dat
, time: tim
etc.numpy
array containing y values of data blocknumpy
array containing x values of data block. Units of x array are given by dxu
parameter.\n\n"}, {"fullname": "brukeropus.file.file.Data.__init__", "modulename": "brukeropus.file.file", "qualname": "Data.__init__", "kind": "function", "doc": "\n", "signature": "(\tfilebytes: bytes,\tdata_info: brukeropus.file.file.FileBlockInfo,\tdata_status_info: brukeropus.file.file.FileBlockInfo)"}, {"fullname": "brukeropus.file.file.Data.params", "modulename": "brukeropus.file.file", "qualname": "Data.params", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data.y", "modulename": "brukeropus.file.file", "qualname": "Data.y", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data.x", "modulename": "brukeropus.file.file", "qualname": "Data.x", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data.label", "modulename": "brukeropus.file.file", "qualname": "Data.label", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data.vel", "modulename": "brukeropus.file.file", "qualname": "Data.vel", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data3D", "modulename": "brukeropus.file.file", "qualname": "Data3D", "kind": "class", "doc": "wn: Returns the x array in wavenumber (cm\u207b\u00b9) units regardless of what units the x array was originally\n saved in. This is only valid for spectral data blocks such as sample, reference, transmission, etc., not\n interferogram or phase blocks.
\n
\n wl: Returns the x array in wavelength (\u00b5m) units regardless of what units the x array was originally\n saved in. This is only valid for spectral data blocks such as sample, reference, transmission, etc., not\n interferogram or phase blocks.
\n f: Returns the x array in modulation frequency units (Hz) regardless of what units the x array was\n originally saved in. This is only valid for spectral data blocks such as sample, reference, transmission,\n etc., not interferogram or phase blocks.
\n datetime: Returns adatetime
class of when the data was taken (extracted from data status parameter block).
\n xxx: the various three char parameter keys from theparams
attribute can be directly called from the \nData
class for convenience. Common parameters includedxu
(x units),mxy
(max y value),mny
(min y\n value), etc.
Class containing 3D array data (series of spectra) and associated parameter/metadata from an OPUS file.
\n\n\n\n", "bases": "Data"}, {"fullname": "brukeropus.file.file.Data3D.__init__", "modulename": "brukeropus.file.file", "qualname": "Data3D.__init__", "kind": "function", "doc": "\n", "signature": "(\tfilebytes: bytes,\tdata_info: brukeropus.file.file.FileBlockInfo,\tdata_status_info: brukeropus.file.file.FileBlockInfo)"}, {"fullname": "brukeropus.file.file.Data3D.params", "modulename": "brukeropus.file.file", "qualname": "Data3D.params", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data3D.y", "modulename": "brukeropus.file.file", "qualname": "Data3D.y", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data3D.x", "modulename": "brukeropus.file.file", "qualname": "Data3D.x", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data3D.num_spectra", "modulename": "brukeropus.file.file", "qualname": "Data3D.num_spectra", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Data3D.label", "modulename": "brukeropus.file.file", "qualname": "Data3D.label", "kind": "variable", "doc": "\n"}, {"fullname": "brukeropus.file.file.Parameters", "modulename": "brukeropus.file.file", "qualname": "Parameters", "kind": "class", "doc": "wn: Returns the x array in wavenumber (cm\u207b\u00b9) units regardless of what units the x array was originally saved\n in. This is only valid for spectral data blocks such as sample, reference, transmission, etc., not\n interferogram or phase blocks.
\n
\n wl: Returns the x array in wavelength (\u00b5m) units regardless of what units the x array was originally saved\n in. This is only valid for spectral data blocks such as sample, reference, transmission, etc., not\n interferogram or phase blocks.
\n datetime: Returns adatetime
class of when the data was taken (extracted from data status parameter\n block).
\n xxx: the various three char parameter keys from the \"params\" attribute can be directly called from the data\n class for convenience. Several of these parameters return arrays, rather than singular values because they\n are recorded for every spectra in the series, e.g.npt
,mny
,mxy
,tim
,nsn
.
Class containing parameter metadata of an OPUS file.
\n\nParameters of an OPUS file are stored as key, val pairs, where the key is always three chars. For example, the\nbeamsplitter is stored in the \"bms\" attribute, source in \"src\" etc. A list of known keys, with friendly label can\nbe found in brukeropus.file.constants.PARAM_LABELS
. The keys in an OPUS file are not case sensitive, and stored\nin all CAPS (i.e. BMS
, SRC
, etc.) but this class uses lower case keys to follow python convention. The class is\ninitialized from a list of parameter FileBlockInfo
. The key, val items in blocks of the list are combined into\none parameter class, so care must be taken not to pass blocks that will overwrite each others keys. Analagous to a\ndict, the keys, values, and (key, val) can be iterated over using the functions: keys()
, values()
, and items()
\nrespectively.
brukeropus.file.parser.read_opus_file_bytes
FileBlockInfo
; every block in the list should be classified as a parameter block.FileBlockInfo
that is used to initialize the class. If input list contains a single data status\nFileBlockInfo
, attributes will include: fxv
, lxv
, npt
(first x-val, last x-val, number of points),\netc. Other blocks produce attributes such as: bms
, src
, apt
(beamsplitter, source, aperture) etc. A\nfull list of keys available in a given Parameters instance are given by the keys()
method.dat
(date) and tim
(time), the datetime
attribute of this class will\nbe set to a python datetime
object. Currently, only data status blocks are known to have these keys. If\ndat
and tim
are not present in the class, the datetime
attribute will return None
.Returns a dict_keys
class of all valid keys in the class (i.e. dict.keys())
Returns a dict_values
class of all the values in the class (i.e. dict.values())
Returns a dict_items
class of all the values in the class (i.e. dict.items())
Contains type and pointer information for all blocks of data in an OPUS file.
\n\nFileDirectory
information is decoded from the raw file bytes of an OPUS file. First the header is read which\nprovides the start location of the directory block, number of blocks in file, and maximum number of blocks the file\nsupports. Then it decodes the block pointer information from each entry of the file's directory block. Rather than\nstore all file blocks in a single list (as it is done in the OPUS file directory), this class sorts the blocks into\ncategories: data
, data_status
, params
, rf_params
, directory
, and file_log
. It also pairs the data\nblocks with their corresponding data_status
block to simplify grouping y data with the parameters that are used to\ngenerate x data and other data block specific metadata.
brukeropus.file.parser.read_opus_file_bytes
FileBlockInfo
that contain array data (e.g. sample, reference, phase)FileBlockInfo
that contain metadata specific to a data block (units, etc.)FileBlockInfo
that contain metadata about the measurement sampleFileBlockInfo
that contain metatdata about the reference measurementFileBlockInfo
for directory block that contains all the block info in the fileFileBlockInfo
of the file log (changes, etc.)FileBlockInfo
, data_status: FileBlockInfo
) which pairs the data status\nparameter block (time, x units, y units, etc.) with the data block it informsFileBlockInfo
with an unrecognized type (i.e. not sure how to parse)Returns bytes
of an OPUS file specified by filepath
(or None
).
Function determines if filepath
points to an OPUS file by reading the first four bytes which are always the same\nfor OPUS files. If filepath
is not a file, or points to a non-OPUS file, the function returns None
. Otherwise\nthe function returns the entire file as raw bytes
.
\n\n", "signature": "(filepath):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.get_block_type", "modulename": "brukeropus.file.parser", "qualname": "get_block_type", "kind": "function", "doc": "filebytes (bytes): raw bytes of OPUS file or
\nNone
(if filepath does not point to an OPUS file)
Converts an int32 block type code to a six-integer tuple block_type
.
This function is used to decode the type_int
from the directory block of an OPUS file into a tuple of integers.\nEach integer in the tuple provides information about the associated data block.
\n\n", "signature": "(type_int: int):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.parse_header", "modulename": "brukeropus.file.parser", "qualname": "parse_header", "kind": "function", "doc": "block_type (tuple): six-integer tuple which specifies the block type
\n
Parses the OPUS file header.
\n\nThe header of an OPUS file contains some basic information about the file including the version number, location of\nthe directory block, and number of blocks in the file. This header is first to be parsed as it specifies how to\nread the file directory block (which contains information about each block in the file)
\n\n\n\n", "signature": "(filebytes: bytes):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.parse_directory", "modulename": "brukeropus.file.parser", "qualname": "parse_directory", "kind": "function", "doc": "header_info (tuple):
\n
\n (
\n version (float64): program version number as a floating-point date (later versions always greater)
\n directory_start (int32): pointer to start location of directory block (number of bytes)
\n max_blocks (int32): maximum number of blocks supported by the directory block (this should only be\n relevant when trying to edit an OPUS file, i.e. when adding data blocks to a file)
\n num_blocks (int32): total number of blocks in the opus file
\n )
Parses directory block of OPUS file and yields block info for all blocks in the file as a generator.
\n\nThe directory block of an OPUS file contains information about every block in the file. The block information is\nstored as three int32 values: type_int
, size_int
, start
. type_int
is an integer representation of the block\ntype. The bits of this type_int
have meaning and are parsed into a tuple using get_block_type
. The size_int
is\nthe size of the block in 32-bit words. start
is the starting location of the block (in number of bytes).
\n\n", "signature": "(filebytes: bytes, directory_start: int, num_blocks: int):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.parse_param_block", "modulename": "brukeropus.file.parser", "qualname": "parse_param_block", "kind": "function", "doc": "block_info (tuple):
\n
\n (
\n block_type (tuple): six-integer tuple which specifies the block type (see:get_block_type
)
\n size (int): size (number of bytes) of the block
\n start (int): pointer to start location of the block (number of bytes)
\n )
Parses the bytes in a parameter block and yields the key, value pairs as a generator.
\n\nParameter blocks are in the form: XXX
, dtype_code
, size
, val
. XXX
is a three char abbreviation of the\nparameter (key). The value of the parameter is decoded according to the dtype_code
and size integers to be either:\nint
, float
, or string
.
\n\n", "signature": "(filebytes: bytes, size: int, start: int):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.get_dpf_dtype_count", "modulename": "brukeropus.file.parser", "qualname": "get_dpf_dtype_count", "kind": "function", "doc": "items (tuple): (key, value) pairs where key is three char string (lowercase) and value can be
\nint
,float
\n orstring
.
Returns numpy dtype and array count from the data point format (dpf) and block size (in bytes).
\n\n\n\n", "signature": "(dpf: int, size: int):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.parse_data_block", "modulename": "brukeropus.file.parser", "qualname": "parse_data_block", "kind": "function", "doc": "dtype (numpy.dtype):
\nnumpy
dtype for defining anndarray
to store the data\n count (int): length of array calculated from the block size and byte size of the dtype.
Parses the bytes in a data block (specified by size
and start
pointers) and returns a numpy
array.
Data blocks contain no metadata, only the y-values of a data array. Data arrays include: single-channel sample,\nreference, phase, interferograms, and a variety of resultant data (transmission, absorption, etc.). Every data\nblock should have a corresponding data status parameter block which can be used to generate the x-array values for\nthe data block. The data status block also specifies the data type of the data array with the DPF
parameter. It\nappears that OPUS currently exclusively stores data blocks as 32-bit floats, but has a reservation for 32-bit\nintegers when DPF
= 2.
\n\n", "signature": "(filebytes: bytes, size: int, start: int, dpf=1):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.parse_3d_data_block", "modulename": "brukeropus.file.parser", "qualname": "parse_3d_data_block", "kind": "function", "doc": "y_array (numpy.ndarray):
\nnumpy
array of y values contained in the data block
Parses the bytes in a 3D data block (series of spectra) and returns a data dict
containing data and metadata.
3D data blocks are structured differently than standard data blocks. In addition to the series of spectra, they\ninclude metadata for each of the spectrum. This function returns a dict
containing all the extracted information\nfrom the data block. The series spectra is formed into a 2D array while metadata captured for each spectra is\nformed into a 1D array (length = number of spectral measurements in the series).
\n\n", "signature": "(filebytes: bytes, start: int, dpf: int = 1):", "funcdef": "def"}, {"fullname": "brukeropus.file.parser.parse_file_log", "modulename": "brukeropus.file.parser", "qualname": "parse_file_log", "kind": "function", "doc": "data_dict (dict):
\ndict
containing all extracted information from the data block
\n {
\n version: file format version number (should be 0)
\n num_blocks: number of sub blocks; each sub block features a data spectra and associated metadata
\n offset: offset in bytes to the first sub data block
\n data_size: size in bytes of each sub data block
\n info_size: size in bytes of the metadata info block immediately following the sub data block
\n store_table: run numbers of the first and last blocks to keep track of skipped spectra
\n y: 2Dnumpy
array containing all spectra (C-order)
\n metadata arrays: series of metadata arrays in 1D array format (e.g.npt
,mny
,mxy
,tim
).\n The most useful one is generallytim
, which can be used as the time axis for 3D data plots.
\n }
Parses the file log in an OPUS file and returns a list of strings contained in the log.
\n\nThe file log block of an OPUS file contains some information about how the file was generated and edits that have\nbeen performed on the file. This function parses the file log as a list of strings using b'\u0000' as a seperator,\nand does not take any steps to parameterizing what is contained in the log. This log is generally not needed to\nretrieve the file data and metadata, but might be useful for inspecting the file.
\n\n\n\n", "signature": "(filebytes: bytes, size: int, start: int):", "funcdef": "def"}, {"fullname": "brukeropus.file.utils", "modulename": "brukeropus.file.utils", "kind": "module", "doc": "\n"}, {"fullname": "brukeropus.file.utils.find_opus_files", "modulename": "brukeropus.file.utils", "qualname": "find_opus_files", "kind": "function", "doc": "strings (list): list of strings found in the file log.
\n
Finds all files in a directory with a strictly numeric extension (OPUS file convention).
\n\nReturns a list of all files in directory that end in .# (e.g. file.0, file.1, file.1001, etc.). Setting recursive\nto true will search directory and all sub directories recursively. No attempt is made to verify the files are\nactually OPUS files (requires opening the file); the function simply looks for files that match the naming pattern.
\n\n\n\n", "signature": "(directory, recursive: bool = False):", "funcdef": "def"}, {"fullname": "brukeropus.file.utils.get_param_label", "modulename": "brukeropus.file.utils", "qualname": "get_param_label", "kind": "function", "doc": "filepaths (list): list of filepaths that match OPUS naming convention (numeric extension)
\n
Returns a short but descriptive label for 3-letter parameters. For example, bms returns Beamsplitter.
\n\nThe 3-letter parameter input is not case sensitive. This package includes the majority of parameters that OPUS\nuses, but in the event a parameter label is not known, this function will return: \"Unknown XXX\" where XXX is the\nunknown 3-letter parameter.
\n\n\n\n", "signature": "(param: str):", "funcdef": "def"}, {"fullname": "brukeropus.file.utils.get_type_code_label", "modulename": "brukeropus.file.utils", "qualname": "get_type_code_label", "kind": "function", "doc": "label (str): Human-readable string label for the parameter.
\n
Returns the type code label of a file block given the position index and value of the type code.
\n\nThe file blocks on an OPUS file feature six-integer type codes, for example (3, 1, 1, 2, 0, 0), that categorize the\ncontents of the file block. The positional index defines the category, while the value at that index defines the\nspecific type of that category. For example, the first integer (pos_idx=0), describes the type of data in the\nblock, if applicable:
\n\n0: Undefined or N/A,\n1: Real Part of Complex Data,\n2: Imaginary Part of Complex Data,\n3: Amplitude\n
\n\nThis package includes the majority of type codes that OPUS uses, but in the event a type code label is not known,\nthis function will return: \"Unknown 0 4\" where the first number is the position index, and the second is the\nunknown value integer.
\n\n\n\n", "signature": "(pos_idx: int, val: int):", "funcdef": "def"}, {"fullname": "brukeropus.file.utils.get_block_type_label", "modulename": "brukeropus.file.utils", "qualname": "get_block_type_label", "kind": "function", "doc": "label (str): human-readable string label that describes the type code.
\n
Converts a six-integer tuple block type into a human readable label.
\n\n\n\n", "signature": "(block_type: tuple):", "funcdef": "def"}, {"fullname": "brukeropus.file.utils.get_data_key", "modulename": "brukeropus.file.utils", "qualname": "get_data_key", "kind": "function", "doc": "label (str): human-readable string label
\n
Returns a shorthand key for a given data block type: sm, rf, igsm, a, t, r, etc.
\n\nDetermines if the data block type is an interferogram, single-channel, absorption, etc. and whether it is associated\nwith the sample or reference channel and returns a shortand key-like label: sm, rf, igsm, igrf, a, t, r, etc. For\nthe full data label (e.g. Sample Spectrum, Absorbance) use: get_block_type_label.\nThis package includes the majority of type codes that OPUS uses, but in the event a type code label is not known,\nthis function will return: \"_33\" or \"sm_33\" where 33 will change to the unkown block_type integer value.
\n\n\n\n", "signature": "(block_type: tuple):", "funcdef": "def"}, {"fullname": "brukeropus.file.utils.parse_file_and_print", "modulename": "brukeropus.file.utils", "qualname": "parse_file_and_print", "kind": "function", "doc": "key (str): shorthand string label that can be utilized as a data key (e.g. \"sm\", \"igrf\", \"a\")
\n
Parses an OPUS file and prints the block information as it goes along to the console.
\n\nThis function demonstrates the basic usage and interaction of the parsing functions. It\ncan also be used to diagnose a file parsing issue if one comes up.
\n\n