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.
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, **kwargs)#
Read a Quantum Detectors
mibfile.If a
hdrfile with the same file name was saved along themibfile, it will be used to read the metadata.- 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. The file will stay open until closed in
compute()or closed manually.get_file_handle()can be used to access the file handler and close it manually.- chunks
tuple,int,dictorstr, default=”auto” The chunks used when reading the data lazily. This argument is passed to the
dask.array.core.normalize_chunks()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.
- **kwargs
dict Keyword arguments are passed to
load_mib_data().
- 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
When the file contains several datasets, each dataset will be loaded as separate dictionary.
Notes
In case of interrupted acquisition, only the completed lines are read and the incomplete line are discarded.
When the scanning shape (i. e. navigation shape) is not available from the metadata (for example with acquisition using pixel trigger), the timestamps will be used to guess the navigation shape.
Examples
In case, the navigation shape can’t read from the data itself (for example, type of acquisition unsupported), the
navigation_shapecan be specified:>>> from rsciio.quantumdetector import file_reader >>> s_dict = file_reader("file.mib", navigation_shape=(256, 256))
- 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. The file will stay open until closed in
compute()or closed manually.get_file_handle()can be used to access the file handler and close it manually.- chunks
tuple,int,dictorstr, default=”auto” The chunks used when reading the data lazily. This argument is passed to the
dask.array.core.normalize_chunks()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. Only when
return_mmapis True.- print_infobool, default=False
If True, display information when loading the file.
- return_mmapbool
If True, return the
numpy.memmapobject. 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_headers=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