load_labone_mat#
- load_labone_mat(filename: str) Dict [source]#
Load a mat file generated from LabOne.
A wrapper function for loading a MAT file as saved by the LabOne User Interface with scipy.io’s loadmat() function. This function is included mainly to document how to work with the data structure return by scipy.io.loadmat().
- Parameters:
filename (str) – the name of the MAT file to load.
- Returns:
A nested dictionary containing the instrument data as specified in the LabOne User Interface. The nested structure of
data
corresponds to the path of the data’s node in the instrument’s node hierarchy.- Return type:
Dict
- Further comments:
The MAT file saved by the LabOne User Interface (UI) is a Matlab V5.0 data file. The LabOne UI saves the specified data using native Matlab data structures in the same format as are returned by commands in the LabOne Matlab API. More specifically, these data structures are nested Matlab structs, the nested structure of which correspond to the location of the data in the instrument’s node hierarchy.
Matlab structs are returned by scipy.io.loadmat() as dictionaries, the name of the struct becomes a key in the dictionary. However, as for all objects in MATLAB, structs are in fact arrays of structs, where a single struct is an array of shape (1, 1). This means that each (nested) dictionary that is returned (corresponding to a node in node hierarchy) is loaded by scipy.io.loadmat as a 1-by-1 array and must be indexed as such. See the
Example
section below.For more information please refer to the following link: http://docs.scipy.org/doc/scipy/reference/tutorial/io.html#matlab-structs
Example
>>> device = 'dev88' >>> # See ``Further explanation`` above for a comment on the indexing: >>> timestamp = data[device][0,0]['demods'][0,0]['sample'][0,0]['timestamp'][0] >>> x = data[device][0,0]['demods'][0,0]['sample'][0,0]['x'][0] >>> y = data[device][0,0]['demods'][0,0]['sample'][0,0]['y'][0] >>> import matplotlib.pyplot as plt >>> import numpy as np >>> plt.plot(timestamp, np.abs(x + 1j*y)) >>> # If multiple demodulator's are saved, data from the second demodulator, >>> # e.g., is accessed as following: >>> x = data[device][0,0]['demods'][0,1]['sample'][0,0]['x'][0]