[SciPy-user] mat file problem in linux

Ryan Krauss ryanlists at gmail.com
Fri Oct 14 15:52:41 CDT 2005


Thanks Fernando.  I was able to get things up and running from the
tarball you posted.
I ran into one or two other things that had to be switched from
windows code to linux code.  This may not be relevant after the new
core is released, but one problem that had me confused is that in
windows I can use scipy.zeros((n,n),'f') to get a floating point
(double) matrix.  In linux (at least on FC3), I have to make sure that
n is an int (it was 2.0) and the type code needs to be 'd'.  The 'f'
flag seems to create the right matrix in linux but if you look at the
type on an individual element, it is still an array with shape (). 
This caused errors about not being able to cast types when doing slice
assignments.

I do have one ipython question that came up while trying to run my
code: I found the command "ipython -pylab -p scipy" in my in my bash
history.  If I use that to start ipython, my code runs fine.  If I
leave off the -p scipy flag I get another problem with the *.mat file:
[ryan at localhost e]$ ipython -pylab
Python 2.3.4 (#1, Oct 26 2004, 16:42:40)
Type "copyright", "credits" or "license" for more information.

IPython 0.6.15 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

  Welcome to pylab, a matplotlib-based Python environment.
  For more information, type 'help(pylab)'.

In [1]: pwd
Out[1]: '/mnt/e'

In [2]: cd /home/ryan/datafit/
/home/ryan/datafit

In [3]: run bodetest.py
---------------------------------------------------------------------------
exceptions.TypeError                                 Traceback (most
recent call last)

/home/ryan/datafit/bodetest.py
     12 #load matlab data
     13 #bob=scipy.io.read_array('iobodetest.txt')
---> 14 modeldict=scipy.io.loadmat('tmm_mat_model_params.mat')
     15 bodedict=scipy.io.loadmat('bodetest.mat')
     16 freq=bodedict['freq']

/usr/lib/python2.3/site-packages/scipy/io/mio.py in loadmat(name,
dict, appendmat, basename)
    745     if not (0 in test_vals):       # MATLAB version 5 format
    746         fid.rewind()
--> 747         thisdict = _loadv5(fid,basename)
    748         if dict is not None:
    749             dict.update(thisdict)

/usr/lib/python2.3/site-packages/scipy/io/mio.py in _loadv5(fid, basename)
    688             dict[varname] = el
    689         except EOFError:
--> 690             break
    691     return dict
    692

/usr/lib/python2.3/site-packages/scipy/io/mio.py in _get_element(fid)
    671
    672     # handle miMatrix type
--> 673     el, name = _parse_mimatrix(fid,numbytes)
    674     return el, name
    675

/usr/lib/python2.3/site-packages/scipy/io/mio.py in _parse_mimatrix(fid, bytes)
    551 def _parse_mimatrix(fid,bytes):
    552     dclass, cmplx, nzmax =_parse_array_flags(fid)
--> 553     dims = _get_element(fid)[0]
    554     name = asarray(_get_element(fid)[0]).tostring()
    555     tupdims = tuple(dims[::-1])

/usr/lib/python2.3/site-packages/scipy/io/mio.py in _get_element(fid)
    663             outarr = fid.read(numbytes,miDataTypes[dtype][2],c_is_b=1)
    664         except KeyError:
--> 665             raise ValueError, "Unknown data type"
    666         mod8 = numbytes%8
    667         if mod8:       # skip past padding

TypeError: unhashable type
WARNING: Failure executing file: <bodetest.py>

In [4]: scipy.__version__
Out[4]: '0.3.3_309.4626'


What does the -p scipy command line argument do?  (I must have found
it somewhere but haven't been able to find it using google).  And why
does it save me from the error with the *.mat file?  Both start up
methods lead to the same version of scipy being loaded:

Other method:
[ryan at localhost e]$ ipython -pylab -p scipy
Welcome to the SciPy Scientific Computing Environment.
Python 2.3.4 (#1, Oct 26 2004, 16:42:40)
Type "copyright", "credits" or "license" for more information.

IPython 0.6.15 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

IPython profile: scipy

  Welcome to pylab, a matplotlib-based Python environment.
  For more information, type 'help(pylab)'.

In [1]: cd /home/ryan/datafit/
/home/ryan/datafit

In [2]: run bodetest.py
...runs without error...
In [3]: scipy.__version__
Out[3]: '0.3.3_309.4626'

Thanks,

Ryan
On 10/14/05, Fernando Perez <Fernando.Perez at colorado.edu> wrote:
> Ryan Krauss wrote:
> > I have a *.mat file created by Matlab in Windows.  Scipy in windows
> > can open this file without a problem.  I am now trying to run the same
> > code in linux and I get this error:
> >
> > /home/ryan/datafit/bodetest.py
> >      12 #load matlab data
> >      13 #bob=scipy.io.read_array('iobodetest.txt')
> > ---> 14 modeldict=scipy.io.loadmat('tmm_mat_model_params.mat')
> >      15 bodedict=scipy.io.loadmat('bodetest.mat')
> >      16 freq=bodedict['freq']
>
> [...]
>
> > TypeError: sequence item 0: expected string, array (scipy) found
> > WARNING: Failure executing file: <bodetest.py>
> >
> > In [4]: scipy.__version__
> > Out[4]: '0.3.2'
>
> Whatever it was, it's been fixed in the last CVS before the SVN transition:
>
> In [2]: import scipy
> numerix Numeric 23.7
>
> In [3]: modeldict=scipy.io.loadmat('tmm_mat_model_params.mat')
>
> In [4]: scipy.__version__
> Out[4]: '0.3.3_309.4624'
>
> You can either update to that code base, for which I'm keeping this tarball
> available until we've fully moved over to newscipy/core:
>
> http://ipython.scipy.org/tmp/scipy_cvs_2005-07-29.tgz
>
> or try to directly update to newscipy/core, since the new codebase obviously
> has all the fixes up to that date (but may still be too alpha for your needs).
>
> Cheers,
>
> f
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user
>



More information about the SciPy-user mailing list