Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to read MAT file with scipy

I am trying to read a matlab file using scipy

import scipy.io as sio

data = sio.loadmat(filepath)

but I get the error

ValueError: Did not fully consume compressed contents of an miCOMPRESSED element. This can indicate that the .mat file is corrupted.

In Matlab I can open this file without any problem. I also tried to save it again, but nothing changed... Can you help me?

Here: https://drive.google.com/drive/folders/0B3vXKJ_zYaCJanZfOUVIcGJyR0E you can find 2 files saved in the same way..

I can open part_000, but not part_001.... why? :(

like image 651
gabboshow Avatar asked Mar 05 '17 10:03

gabboshow


2 Answers

The problem seems to be caused by the compression. .mat files are compressed automatically from version 7 onward.

Therefore, I suggest trying to save the file in the earlier, uncompressed .mat file version 6:

save(filename, 'data', '-v6');
like image 155
Richard Avatar answered Nov 06 '22 14:11

Richard


The problem is with scipy.io.loadmat's verify_compressed_data_integrity keyword argument, which defaults to True. It's trying to do some error checking of the headers, but can raise an error even when the data is extracted just fine. See this related GitHub issue. I'm unsure of the implications of switching this off full-time, but if you use the following, it should resolve your issue in the meantime (I can't check it against your data, it's no longer available at the provided URL).

import scipy.io as sio

data = sio.loadmat(filepath, verify_compressed_data_integrity=False)
like image 2
billyjmc Avatar answered Nov 06 '22 14:11

billyjmc