PYME.IO.FileUtils.obf_support module

Pure Python read only support for OBF files. The OBF file format originates from the Department of NanoBiophotonics of the Max Planck Institute for Biophysical Chemistry in Göttingen, Germany. A specification can be found at https://github.com/AbberiorInstruments/ImspectorDocs/blob/master/docs/fileformat.rst This implementation is similar to the File and Stack API of specpy (https://pypi.org/project/specpy/). Can also read MSR files (the OBF part of it).

Documentation:

Include in your project as “import obf_support”

File - Open an OBF file with “obf = obf_support.File(path_to_file)”, that will read all meta data (including stack meta data) - Access the following attributes: format_version, description, stacks - Close with “obf.close()” (optional, is also closed automatically on deletion of the File object)

Stack - Each Stack has attributes: format_version, name, description, shape, lengths, offsets, data_type, data - data returns a NumPy array containing the stack data (the stack data is loaded from the file lazily, i.e. when the

attribute is accessed the first time)

Example: see obf_support_example.py

Implementation notes:

  • Relies on the struct module (https://docs.python.org/3.9/library/struct.html).

  • In particular see the format characters of the struct module (https://docs.python.org/3.9/library/struct.html#format-characters).

  • Opened issue at https://github.com/AbberiorInstruments/ImspectorDocs/issues/9 about + Constant OMAS_BF_MAX_DIMENSIONS is not explained, the value is 15. + Data type of OMAS_DT is not specified, it’s an enum type in C++, which is stored as uint32.

  • In the future maybe: + Writing to OBF would in principle be possible (using the struct module) + Read part (slice) of data (use flush points), currently data is read all at once (impractical for very large files) + may still crash if not all data is written in a stack (haven’t seen such a stack yet) + if there is a problem with a stack (like unknown data type), we could simply ignore the stack and print a warning instead

Author: Jan Keller-Findeisen (https://github.com/jkfindeisen), May-July 2021, MIT licensed (see LICENSE)

class PYME.IO.FileUtils.obf_support.File(file_path: str)

Bases: object

OBF file access.

Reads the file header, stack header and stack footer of all stacks contained in the file.

Attributes:
  • format_version

  • description

  • stacks (list of Stack)

Create a new OBF file access object by providing a file path: obf = File(file_path)

Parameters

file_path – path of the OBF file

close()

Closes the file if it isn’t closed already.

find_stack_by_name(name_part: str) list[Stack]

Small convenience method. Will return all stacks in this OBF file where string is contained in the stack name.

class PYME.IO.FileUtils.obf_support.Fraction(numerator, denominator)

Bases: tuple

Create new instance of Fraction(numerator, denominator)

property denominator

Alias for field number 1

property numerator

Alias for field number 0

class PYME.IO.FileUtils.obf_support.SIUnit(values)

Bases: object

OMAS_SIUNIT reimplementation exponents = Meters (M), Kilograms (KG), Seconds (S), Amperes (A), Kelvin (K), Moles (MOL), Candela (CD), Radian (R), Steradian (SR)

Initialize with 19 double values.

unitnames = ['m', 'kg', 's', 'A', 'K', 'mol', 'CD', 'R', 'SR']
class PYME.IO.FileUtils.obf_support.Stack(file: File)

Bases: object

A Stack class, holds attributes about stacks

Initialize with a File object.

PYME.IO.FileUtils.obf_support.file_header_unpack(/, buffer, offset=0)

Return a tuple containing unpacked values.

Values are unpacked according to the format string Struct.format.

The buffer’s size in bytes, minus offset, must be at least Struct.size.

See help(struct) for more on format strings.

PYME.IO.FileUtils.obf_support.long_unpack(/, buffer, offset=0)

Return a tuple containing unpacked values.

Values are unpacked according to the format string Struct.format.

The buffer’s size in bytes, minus offset, must be at least Struct.size.

See help(struct) for more on format strings.

Return a tuple containing unpacked values.

Values are unpacked according to the format string Struct.format.

The buffer’s size in bytes, minus offset, must be at least Struct.size.

See help(struct) for more on format strings.

Return a tuple containing unpacked values.

Values are unpacked according to the format string Struct.format.

The buffer’s size in bytes, minus offset, must be at least Struct.size.

See help(struct) for more on format strings.

Return a tuple containing unpacked values.

Values are unpacked according to the format string Struct.format.

The buffer’s size in bytes, minus offset, must be at least Struct.size.

See help(struct) for more on format strings.

Return a tuple containing unpacked values.

Values are unpacked according to the format string Struct.format.

The buffer’s size in bytes, minus offset, must be at least Struct.size.

See help(struct) for more on format strings.

Return a tuple containing unpacked values.

Values are unpacked according to the format string Struct.format.

The buffer’s size in bytes, minus offset, must be at least Struct.size.

See help(struct) for more on format strings.

Return a tuple containing unpacked values.

Values are unpacked according to the format string Struct.format.

The buffer’s size in bytes, minus offset, must be at least Struct.size.

See help(struct) for more on format strings.

Return a tuple containing unpacked values.

Values are unpacked according to the format string Struct.format.

The buffer’s size in bytes, minus offset, must be at least Struct.size.

See help(struct) for more on format strings.

Return a tuple containing unpacked values.

Values are unpacked according to the format string Struct.format.

The buffer’s size in bytes, minus offset, must be at least Struct.size.

See help(struct) for more on format strings.

PYME.IO.FileUtils.obf_support.stack_header_unpack(/, buffer, offset=0)

Return a tuple containing unpacked values.

Values are unpacked according to the format string Struct.format.

The buffer’s size in bytes, minus offset, must be at least Struct.size.

See help(struct) for more on format strings.