I tried to import and read .mat file from Python. I have tried two ways but been unsuccessful.
Method 1 (In Python):
import scipy.io as sio
mat = sio.loadmat('path/tmpPBworkspace.mat')
I get a message similar to:
{'None': MatlabOpaque([ (b'rateQualityOutTrim', b'MCOS', b'dataset', array([[3707764736],
[ 2],
[ 1],
[ 1],
[ 1],
[ 1]], dtype=uint32))],
dtype=[('s0', 'O'), ('s1', 'O'), ('s2', 'O'), ('arr', 'O')]),
'__function_workspace__': array([[ 0, 1, 73, ..., 0, 0, 0]], dtype=uint8),
'__globals__': [],
'__header__': b'MATLAB 5.0 MAT-file, Platform: GLNXA64, Created on: Thu May 10 07:11:52 2018',
'__version__': '1.0'}
I am not sure what went wrong there? I was hoping to see a data frame. Also to add, in Method 1, I have saved the .mat in a version compatible with SciPy.
In Matlab:
save('path/tmpPBworkspace.mat','rateQualityOutTrim','-v7')
Also tried the other way:
Method 2: h5py
In Matlab:
save('path/tmpPBworkspaceH5.mat','rateQualityOutTrim','-v7.3')
In Python:
import numpy as np
import h5py
f = h5py.File('/GAAR/ustr/projects/PBF/tmpPBworkspaceH5.mat','r')
data = f.get('rateQualityOutTrim/date')
data = np.array(data)
I get
f
Out[154]: <HDF5 file "tmpPBworkspaceH5.mat" (mode r)>
data
array(None, dtype=object)
The array is empty. Not sure how I can access the data here as well.