5

I have some important data (structured array) in Matlab with .mat extension which I want to open in python, I tried almost every blog from stack-overflow to access my data but still unsuccessful I need not just to load the data in python but to work on them after making numpy arrays. I loaded them in Windows but unable to access sub-arrays.

I used the following command:

    import numpy as np, h5py, scipy.io
    scipy.io.loadmat('/media/sibte/DATA and SOFTWARE/DATA/recovery/GENERAL SOFTWARE/MATLAB/2_Programming Files/MATLAB Files/ASTRONOMICAL DATA and WORKING on it/NVSS.mat')

this result in the following error:

    Traceback (most recent call last):
    File "<pyshell#1>", line 1, in <module>
    scipy.io.loadmat('/media/sibte/DATA and SOFTWARE/DATA/recovery/GENERAL SOFTWARE/MATLAB/2_Programming Files/MATLAB Files/ASTRONOMICAL DATA and WORKING on it/NVSS.mat')
    File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio.py", line 126, in loadmat
matfile_dict = MR.get_variables(variable_names)
    File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio4.py", line 394, in get_variables
hdr, next_position = self.read_var_header()
    File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio4.py", line 350, in read_var_header
hdr = self._matrix_reader.read_header()
    File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio4.py", line 121, in read_header
    raise ValueError('O in MOPT integer should be 0, wrong format?')
    ValueError: O in MOPT integer should be 0, wrong format?

Then I used the h5py command to load:

    f = h5py.File('/media/sibte/DATA and SOFTWARE/DATA/recovery/GENERAL SOFTWARE/MATLAB/2_Programming Files/MATLAB Files/ASTRONOMICAL DATA and WORKING on it/NVSS.mat','r+')

this results in following error:

    Traceback (most recent call last):
    File "<pyshell#2>", line 1, in <module>
    f = h5py.File('/media/sibte/DATA and SOFTWARE/DATA/recovery/GENERAL SOFTWARE/MATLAB/2_Programming Files/MATLAB Files/ASTRONOMICAL DATA and WORKING on it/NVSS.mat','r+')
    File "/usr/lib/python2.7/dist-packages/h5py/_hl/files.py", line 207, in __init__
fid = make_fid(name, mode, userblock_size, fapl)
    File "/usr/lib/python2.7/dist-packages/h5py/_hl/files.py", line 81, in make_fid
fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl)
    File "h5f.pyx", line 71, in h5py.h5f.open (h5py/h5f.c:1806)
    IOError: unable to open file (File accessibilty: Unable to open file)

I have spent several days in loading this data, I have many other data in .mat format to access but fed up with this deadlock

NOTE: I am using IDLE-Python-2.7.6 shell on UBUNTU-14.04

I had worked on these file in Matlab-R2010a v7.1 on Windows-7

Any help regarding this issue?

Sibte Raza
  • 187
  • 1
  • 3
  • 7
  • 3
    I think your `.mat` files are crashed! It can read the entire files. Try to download it again or open it with `Matlab` to see whether it is correct or crashed!? Can you upload your `.mat` files? – Hadi Aug 24 '14 at 08:44

1 Answers1

0

I suspect that you are trying to load V7.3+ hdf5 .mat files with a reader that expects to see old style 7.2 .mat files. I have not used h5py so I am not sure why that module is not working.

Try using the hdf5storage python module to load your .mat files:

import hdf5storage
hdf5storage.loadmat(...)

The hdf5storage module is modeled after scipy.io and has helped me avoid compatability problems. If hdf5storage doesn't work, your .mat files may be corrupt.

Michael Graczyk
  • 4,905
  • 2
  • 22
  • 34