Quantum Detector#
The mib file format is the format from the Quantum Detector software to
acquired with the Quantum Detector Merlin camera. It is typically used to
store a series of diffraction patterns from scanning transmission electron
diffraction measurements. It supports reading data from camera with one or
four quadrants.
If a hdr file with the same file name was saved along the mib file,
it will be used to infer the navigation shape of the providing that the option
“line trigger” was used for the acquisition. Alternatively, the navigation
shape can be specified as an argument:
>>> from rsciio.quantumdetector import file_reader
>>> s_dict = file_reader("file.mib", navigation_shape=(256, 256))
API functions#
- rsciio.quantumdetector.file_reader(filename, lazy=False, chunks='auto', mmap_mode=None, navigation_shape=None, first_frame=None, last_frame=None, print_info=False)#
Read a Quantum Detectors
mibfile.- Parameters:
- filename
str,pathlib.Path Filename of the file to read or corresponding pathlib.Path.
- lazybool, default=False
Whether to open the file lazily or not.
- chunks
tupleofintorNone, default=”auto” The chunks used when reading the data lazily. This argument is passed to the
chunksof thedask.array.from_array()function.- mmap_mode{
None, “r+”, “r”, “w+”, “c”}, default=None Argument passed to
numpy.memmap. A memory-mapped array is stored on disk, and not directly loaded into memory. However, it can be accessed and sliced like any ndarray. Lazy loading does not support in-place writing (i.e lazy loading and the"r+"mode are incompatible). IfNone(default), the value is"r"whenlazy=True, otherwise it is"c".- navigation_shape
tupleorNone, default=None Specify the shape of the navigation space. If
None, the navigation shape will be infer from metadata and if not possible, the data will be loaded as a stack with a navigation dimension equal to one.- first_frame, last_frame
intorNone, default=None The first/last frame to load. It follows python indexing syntax, i.e. negative integer means reverse indexing. If
None, it uses first/last index.- print_infobool
Display information about the mib file.
- filename
- Returns:
listofdictList of dictionaries containing the following fields:
‘data’ – multidimensional
numpy.ndarrayordask.array.Array‘axes’ – list of dictionaries describing the axes containing the fields ‘name’, ‘units’, ‘index_in_array’, and either ‘size’, ‘offset’, and ‘scale’ or a numpy array ‘axis’ containing the full axes vector
‘metadata’ – dictionary containing the parsed metadata
‘original_metadata’ – dictionary containing the full metadata tree from the input file
Notes
In case of interrupted acquisition, only the completed lines are read and the incomplete line are discarded.
- rsciio.quantumdetector.load_mib_data(path, lazy=False, chunks='auto', mmap_mode=None, navigation_shape=None, first_frame=None, last_frame=None, mib_prop=None, return_headers=False, print_info=False, return_mmap=True)#
Load Quantum Detectors MIB file from a path or a memory buffer.
- Parameters:
- path
strorbytes The path to the
mibfile, otherwise the memory buffer of themibfile. Lazy loading is not supported with memory buffer.- lazybool, default=False
Whether to open the file lazily or not.
- chunks
tupleofintorNone, default=”auto” The chunks used when reading the data lazily. This argument is passed to the
chunksof thedask.array.from_array()function.- mmap_mode{
None, “r+”, “r”, “w+”, “c”}, default=None Argument passed to
numpy.memmap. A memory-mapped array is stored on disk, and not directly loaded into memory. However, it can be accessed and sliced like any ndarray. Lazy loading does not support in-place writing (i.e lazy loading and the"r+"mode are incompatible). IfNone(default), the value is"r"whenlazy=True, otherwise it is"c".- navigation_shape
tupleorNone, default=None Specify the shape of the navigation space. If
None, the navigation shape will be infer from metadata and if not possible, the data will be loaded as a stack with a navigation dimension equal to one.- first_frame, last_frame
intorNone, default=None The first/last frame to load. It follows python indexing syntax, i.e. negative integer means reverse indexing. If
None, it uses first/last index.- mib_prop
MIBProperties, default=None The
MIBPropertiesinstance of the file. If None, it will be parsed from the file.- return_headersbool, default=False
If True, also return headers.
- print_infobool, default=False
If True, display information when loading the file.
- return_mmapbool
If True, return the py:func:numpy.memmap object. Default is True.
- path
- Returns:
numpy.ndarrayordask.array.Arrayornumpy.memmapThe data from the mib reshaped according to the
navigation_shapeargument.
- rsciio.quantumdetector.parse_exposures(headers, max_index=10000)#
Parse the exposure time from the header of each frames.
- Parameters:
- Returns:
listThe exposure in ms of each frame.
Examples
Use
load_mib_datafunction to the headers and parse the exposures from the headers. By default, reads only the first 10 000 frames.>>> from rsciio.quantumdetector import load_mib_data, parse_exposures >>> data, headers = load_mib_data(path, return_header=True, return_mmap=True) >>> exposures = parse_exposures(headers)
All frames can be parsed by using
max_index=-1:>>> data, headers = load_mib_data(path, return_headers=True) >>> timestamps = parse_exposures(headers, max_index=-1) >>> len(timestamps) 65536
- rsciio.quantumdetector.parse_timestamps(headers, max_index=10000)#
Parse the timestamp time from the header of each frames.
- Parameters:
- Returns:
listThe timestamp of each frame.
Examples
Use
load_mib_datafunction to get the headers and parse the timestamps from the headers. By default, reads only the first 10 000 frames.>>> from rsciio.quantumdetector import load_mib_data, parse_exposures >>> data, header = load_mib_data(path, return_headers=True) >>> timestamps = parse_timestamps(headers) >>> len(timestamps) 10000
All frames can be parsed by using
max_index=-1:>>> data, headers = load_mib_data(path, return_headers=True) >>> timestamps = parse_timestamps(headers, max_index=-1) >>> len(timestamps) 65536