python - Error opening file in H5PY (File signature not found) -
i've been using following bit of code open hdf5 files, produced in matlab, in python using h5py:
import h5py h5 data='dataset.mat' f=h5.file(data, 'r')
however i'm getting following error:
oserror: unable open file (file signature not found)
i've checked files i'm trying open version 7.3 mat-files , hdf5 format. in fact i've used h5py open same files before. i've confirmed files exist , accessible i'm not sure error coming from. advice appreciated, in advance : )
usually message file signature not found
indicates either:
1. file corrupted.
... think likely. said you've opened files before. maybe forgot closing file-handle can corrupt file. try checking file hdf5 utility h5debug
(available on command line if you've installed hdf5 lib on os, check dpkg -s libhdf5-dev
on linux).
2. file not in hdf5 format.
this known cause error message. since said made sure, case , you've opened files before, i'm giving reference others may stumble here:
since december 2015 (as of version 7.3), matlab files use hdf5 based format in mat-file level 5 containers (more doc). earlier version mat-files (v4 (level 1.0), v6 , v7 7.2) supported , can read scipy
library:
import scipy.io f = scipy.io.loadmat('dataset.mat')
otherwise may try other methods , see whether error persists:
pytables alternative h5py , found here.
import tables file = tables.openfile('test.mat')
python matlab engine alternative read mat files, if have matlab installed. documentation found here: matlab engine api python.
import matlab.engine mat = matlab.engine.start_matlab() f = mat.load("dataset.mat", nargout=1)
Comments
Post a Comment