[SciPy-User] scipy.io.matlab.loadmat error

1,160 views
Skip to first unread message

Fernando Guimarães Ferreira

unread,
May 31, 2010, 6:54:17 PM5/31/10
to scipy...@scipy.org
Hi,

I'm using scipy under MacOS Snow Leopard v:0.7.2 with python 2.6.2

For some reason, I can't load matlab files using scipy.io.matlab.loadmat:

scipy.io.matlab.loadmat('all_data.mat')
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/io/matlab/mio.py:84: FutureWarning: Using struct_as_record default value (False) This will change to True in future versions
  return MatFile5Reader(byte_stream, **kwargs)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Users/fguimara/Documents/UFRJ/mestrado/CPE782_-_ICA/time_series_ica/script/<ipython console> in <module>()

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/io/matlab/mio.pyc in loadmat(file_name, mdict, appendmat, **kwargs)
    109     '''
    110     MR = mat_reader_factory(file_name, appendmat, **kwargs)
--> 111     matfile_dict = MR.get_variables()
    112     if mdict is not None:
    113         mdict.update(matfile_dict)

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/io/matlab/miobase.pyc in get_variables(self, variable_names)
    444         mdict['__globals__'] = []
    445         while not self.end_of_stream():
--> 446             getter = self.matrix_getter_factory()
    447             name = getter.name
    448             if variable_names and name not in variable_names:

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/io/matlab/mio5.pyc in matrix_getter_factory(self)
    694 
    695     def matrix_getter_factory(self):
--> 696         return self._array_reader.matrix_getter_factory()
    697 
    698     def guess_byte_order(self):

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/io/matlab/mio5.pyc in matrix_getter_factory(self)
    313         elif not mdtype == miMATRIX:
    314             raise TypeError, \
--> 315                   'Expecting miMATRIX type here, got %d' %  mdtype
    316         else:
    317             getter = self.current_getter(byte_count)

TypeError: Expecting miMATRIX type here, got 1296630016


Can't understand why...

This is the info about the file
% > file all_data.mat 
all_data.mat: Matlab v5 mat-file (little endian) version 0x0100


Anything?

Cheers
Fernando


Matthew Brett

unread,
May 31, 2010, 7:08:13 PM5/31/10
to SciPy Users List
Hi,

2010/5/31 Fernando Guimarães Ferreira <fernando...@poli.ufrj.br>:


> Hi,
> I'm using scipy under MacOS Snow Leopard v:0.7.2 with python 2.6.2
> For some reason, I can't load matlab files using scipy.io.matlab.loadmat:
> scipy.io.matlab.loadmat('all_data.mat')

...


>     317             getter = self.current_getter(byte_count)
> TypeError: Expecting miMATRIX type here, got 1296630016
>
> Can't understand why...

I don't know either I'm afraid. Can you try the latest version? Is
there some way you can get me the .mat file so I can debug the problem
in more detail?

Best,

Matthew
_______________________________________________
SciPy-User mailing list
SciPy...@scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user

Fernando Guimarães Ferreira

unread,
May 31, 2010, 9:10:55 PM5/31/10
to SciPy Users List
In the last email I meant python 2.6.5

The mat file is attached... This is a test, there is just an array 'x' with few elements..
Didn't work either


Thanks,
Fernando
teste.mat

Vincent Davis

unread,
May 31, 2010, 10:09:32 PM5/31/10
to SciPy Users List
Just as a note, this probably is not it but I recently ran into this
with a csv file saved using excel on a mac. I guess it saves it as a
unicode format, the error reported is a EOL when opening with
genfromtxt but thats not quite right. Anyway if the file is saved
using matlab on you mac this unicode might be the problem. Of course I
am seeing this through skewed glasses I just couldn't not mention it.

Vincent

Skipper Seabold

unread,
May 31, 2010, 10:16:53 PM5/31/10
to SciPy Users List
2010/5/31 Fernando Guimarães Ferreira <fernando...@poli.ufrj.br>:
> In the last email I meant python 2.6.5
> The mat file is attached... This is a test, there is just an array 'x' with
> few elements..
> Didn't work either

Works for me with a recent trunk of scipy.

In [1]: from scipy import io

In [2]: dta = io.loadmat('./teste.mat')

In [3]: dta['x']
Out[3]: array([[0, 1, 3, 0, 1, 3, 4, 5, 7, 7]], dtype=uint8)

In [4]: from scipy import __version__ as v

In [5]: v
Out[5]: '0.9.0.dev6447'

Skipper

Matthew Brett

unread,
May 31, 2010, 10:36:04 PM5/31/10
to SciPy Users List
Hi,

2010/5/31 Fernando Guimarães Ferreira <fernando...@poli.ufrj.br>:

> In the last email I meant python 2.6.5
> The mat file is attached... This is a test, there is just an array 'x' with
> few elements..

It works for me with 0.7.2. I wonder what's going on?

[mb312@blair ~/tmp]$ uname -a
Darwin blair 10.3.0 Darwin Kernel Version 10.3.0: Fri Feb 26 11:58:09
PST 2010; root:xnu-1504.3.12~1/RELEASE_I386 i386
[mb312@blair ~/tmp]$ ipython
Python 2.6.4 (r264:75706, Dec 22 2009, 14:55:30)
Type "copyright", "credits" or "license" for more information.

IPython 0.11.alpha1.bzr.r1223 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import scipy

In [2]: scipy.__version__
Out[2]: '0.7.2'

In [3]: import scipy.io.matlab

In [4]: scipy.io.matlab.loadmat('/Users/mb312/Downloads/teste.mat')
/Users/mb312/usr/local/lib/python2.6/site-packages/scipy/io/matlab/mio.py:84:


FutureWarning: Using struct_as_record default value (False) This will
change to True in future versions
return MatFile5Reader(byte_stream, **kwargs)

Out[4]:
{'__globals__': [],
'__header__': 'MATLAB 5.0 MAT-file, Platform: MACI, Created on: Mon
May 31 21:06:09 2010',
'__version__': '1.0',
'x': array([[0, 1, 3, 0, 1, 3, 4, 5, 7, 7]], dtype=uint8)}

Pierre GM

unread,
May 31, 2010, 10:38:55 PM5/31/10
to SciPy Users List
On May 31, 2010, at 10:09 PM, Vincent Davis wrote:
> Just as a note, this probably is not it but I recently ran into this
> with a csv file saved using excel on a mac. I guess it saves it as a
> unicode format, the error reported is a EOL when opening with
> genfromtxt but thats not quite right.

But I thought I had fixed that on the SVN ???

Fernando Guimarães Ferreira

unread,
May 31, 2010, 10:43:40 PM5/31/10
to SciPy Users List
14 [fguimara] script > uname -a
Darwin warley.local 10.3.0 Darwin Kernel Version 10.3.0: Fri Feb 26 11:58:09 PST 2010; root:xnu-1504.3.12~1/RELEASE_I386 i386
15 [fguimara] script > ipython
Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55) 
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import scipy

In [2]: scipy.__version__
Out[2]: '0.7.2'

In [3]: import scipy.io.matlab

In [4]: scipy.io.matlab.loadmat('teste.mat')
    317             getter = self.current_getter(byte_count)

TypeError: Expecting miMATRIX type here, got 1296630016

In [5]: 


Same file.... But it doesnot work at all...


Cheers, 
Fernando

Matthew Brett

unread,
May 31, 2010, 10:58:24 PM5/31/10
to SciPy Users List
Hi,
...

> TypeError: Expecting miMATRIX type here, got 1296630016
> In [5]:
>
> Same file.... But it does not work at all...

What version of numpy do you have? I can't imagine it makes a
difference, but still.

Did you run the scipy tests? Did the scipy.io.matlab tests pass?

Best,

Matthew

Vincent Davis

unread,
May 31, 2010, 11:53:34 PM5/31/10
to SciPy Users List
On Mon, May 31, 2010 at 8:38 PM, Pierre GM <pgmde...@gmail.com> wrote:
> On May 31, 2010, at 10:09 PM, Vincent Davis wrote:
>> Just as a note, this probably is not it  but I recently ran into this
>> with a csv file saved using excel on a mac. I guess it saves it as a
>> unicode format, the error reported is a EOL when opening with
>> genfromtxt but thats not quite right.
>
>  But I thought I had fixed that on the SVN ???

You did but I assume that only applied to csv (type?) files.
I was thinking that they may have a "similar" problem with this mat
file. But I tried to clearly say I have no idea.
Vincent

Matthew Brett

unread,
May 31, 2010, 11:58:21 PM5/31/10
to SciPy Users List
Hi,

>>  But I thought I had fixed that on the SVN ???
>
> You did but I assume that only applied to csv (type?) files.
> I was thinking that they may have a "similar" problem with this mat
> file. But I tried to clearly say I have no idea.

Actually the .mat files are a custom binary format by matlab - we
don't use the genfromtxt stuff to load them...

Matthew

Vincent Davis

unread,
Jun 1, 2010, 10:00:07 AM6/1/10
to SciPy Users List
Work on ( I guess, never used it) Mac Osx 10.6 running python 2.6

In [7]: mt.loadmat('teste.mat')
/Library/Frameworks/EPD64.framework/Versions/6.1/lib/python2.6/site-packages/scipy/io/matlab/mio.py:99:


FutureWarning: Using struct_as_record default value (False) This will
change to True in future versions
return MatFile5Reader(byte_stream, **kwargs)

Out[7]:


{'__globals__': [],
'__header__': 'MATLAB 5.0 MAT-file, Platform: MACI, Created on: Mon
May 31 21:06:09 2010',
'__version__': '1.0',
'x': array([[0, 1, 3, 0, 1, 3, 4, 5, 7, 7]], dtype=uint8)}

Fernando Guimarães Ferreira

unread,
Jun 4, 2010, 7:30:21 PM6/4/10
to SciPy Users List
So,

Things have change... I rebuilt numpy and scipy. It turns out that scipy.io.matlab.loadmat is working again....
However scipy.test('1', '10') is still failing

I attached the output... i can't understand why...

I installed the dmg package from the sourceForge repository.

Any idea?

Cheers,
Fernando
scipy_test_output.txt

Nils Wagner

unread,
Jun 9, 2010, 2:53:55 AM6/9/10
to SciPy Users List
On Fri, 4 Jun 2010 20:30:21 -0300
Fernando Guimarães
Ferreira <fernando...@poli.ufrj.br> wrote:
> So,
>
> Things have change... I rebuilt numpy and scipy. It
>turns out that
> scipy.io.matlab.loadmat is working again....
> However scipy.test('1', '10') is still failing
>
> I attached the output... i can't understand why...
>
> I installed the dmg package from the sourceForge
>repository.
>
> Any idea?
>
> Cheers,
>Fernando
>
>
I cannot reproduce the problem here.
>>> numpy.__version__
'2.0.0.dev8460'
>>> scipy.__version__
'0.9.0.dev6495'

======================================================================
ERROR: test_decomp.test_lapack_misaligned(<function solve
at 0x2cc5410>, (array([[ 1.734e-255, 8.189e-217,
4.025e-178, 1.903e-139, 9.344e-101,
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/data/home/nwagner/local/lib/python2.5/site-packages/nose-0.11.1-py2.5.egg/nose/case.py",
line 183, in runTest
self.test(*self.arg)
File
"/data/home/nwagner/local/lib/python2.5/site-packages/scipy/linalg/tests/test_decomp.py",
line 1071, in check_lapack_misaligned
func(*a,**kwargs)
File
"/data/home/nwagner/local/lib/python2.5/site-packages/scipy/linalg/basic.py",
line 49, in solve
a1, b1 = map(asarray_chkfinite,(a,b))
File
"/data/home/nwagner/local/lib/python2.5/site-packages/numpy/lib/function_base.py",
line 528, in asarray_chkfinite
"array must not contain infs or NaNs")
ValueError: array must not contain infs or NaNs

======================================================================
ERROR: Ticket #1124.
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/data/home/nwagner/local/lib/python2.5/site-packages/scipy/signal/tests/test_signaltools.py",
line 287, in test_none
signal.medfilt(None)
File
"/data/home/nwagner/local/lib/python2.5/site-packages/scipy/signal/signaltools.py",
line 317, in medfilt
return sigtools._order_filterND(volume,domain,order)
ValueError: order_filterND not available for this type

======================================================================
ERROR: test_mpmath.test_expi_complex
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/data/home/nwagner/local/lib/python2.5/site-packages/nose-0.11.1-py2.5.egg/nose/case.py",
line 183, in runTest
self.test(*self.arg)
File
"/data/home/nwagner/local/lib/python2.5/site-packages/numpy/testing/decorators.py",
line 146, in skipper_func
return f(*args, **kwargs)
File
"/data/home/nwagner/local/lib/python2.5/site-packages/scipy/special/tests/test_mpmath.py",
line 46, in test_expi_complex
dataset = np.array(dataset, dtype=np.complex_)
TypeError: a float is required

----------------------------------------------------------------------
Ran 4625 tests in 166.157s

FAILED (KNOWNFAIL=12, SKIP=17, errors=3)
<nose.result.TextTestResult run=4625 errors=3 failures=0>

Reply all
Reply to author
Forward
0 new messages