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
mib
file- 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
tuple
ofint
orNone
, default=”auto” The chunks used when reading the data lazily. This argument is passed to the
chunks
of 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
tuple
orNone
, 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
int
orNone
, 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:
list
ofdict
List of dictionaries containing the following fields:
‘data’ – multidimensional
numpy.ndarray
ordask.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
- 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
str
orbytes
The path to the
mib
file, otherwise the memory buffer of themib
file. Lazy loading is not supported with memory buffer- lazybool, default=False
Whether to open the file lazily or not.
- chunks
tuple
ofint
orNone
, default=”auto” The chunks used when reading the data lazily. This argument is passed to the
chunks
of 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
tuple
orNone
, 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
int
orNone
, 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.- return_mmapbool
If True, return the py:func:numpy.memmap object. Default is True.
- path
- Returns:
- data
numpy.ndarray
ordask.array.Array
ofnumpy.memmap
The data from the mib reshaped according to the
navigation_shape
argument.
- data
- rsciio.quantumdetector.parse_exposures(headers, max_index=10000)#
Parse the exposure time from the header of each frames.
- Parameters:
- Returns:
- exposures
list
The exposure in ms of each frame.
- exposures
Examples
Use
load_mib_data
function 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:
- timestamps
list
The timestamp of each frame.
- timestamps
Examples
Use
load_mib_data
function 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