deepmr.io.read_matfile

Contents

deepmr.io.read_matfile#

deepmr.io.read_matfile(filepath, return_fullpath=False)[source]#

Read matfile as a Python dictionary.

Automatically handle legacy and HDF5 (i.e., -v7.3) formats.

Parameters:
  • filepath (str) – Path of the file on disk.

  • return_fullpath (bool, optional) – If True, also return expanded file path. The default is False.

Returns:

Deserialized matfile.

Return type:

dict

Example

>>> from os.path import dirname, join as pjoin
>>> import scipy.io as sio

Get the filename for an example .mat file from the tests/data directory.

>>> dir = pjoin(dirname(sio.__file__), 'matlab', 'tests', 'data')
>>> filepath = pjoin(dir, 'testdouble_7.4_GLNX86.mat')

Load the .mat file contents.

>>> import deepmr.io
>>> matfile = deepmr.io.read_matfile(filepath)

The result is a dictionary, one key/value pair for each variable:

>>> matfile.keys()
['testdouble']
>>> matfile['testdouble']
array([[0.        , 0.78539816, 1.57079633, 2.35619449, 3.14159265,
        3.92699082, 4.71238898, 5.49778714, 6.28318531]])

Contrary to scipy.io, this will load matlab v7.3 files as well, using mat73 library [1]. In addition, __global__, __header__ and __version__ fields are automatically discarded.

References

[1]: skjerns/mat7.3