[SciPy-user] io.loadmat

Ryan Krauss ryanlists at gmail.com
Wed Feb 1 09:15:38 CST 2006


Thanks Travis.  I was able to get the latest SVN and that one now
loads.  I have one more (I think this will be the last).  Same place:
http://www.imdl.gatech.edu/ryan/python/

I replaced the other link with a file called matfile2.tar.gz
It should unpack a mat file called vertical1_11_24_04_lowfreq.mat

This is the format that my experimental setup on campus saves.  It is
supposed to be mat compliant.  I was able to load this exact same data
file using old scipy in windows on my wife's computer last night.

With the latest SVN I get the following:
In [3]: temp=io.loadmat('vertical2_11_24_04_lowfreq.mat')
---------------------------------------------------------------------------
exceptions.ValueError                                Traceback (most
recent call last)

/home/ryan/thesis/actuator_modeling/torque_testing/data_Nov2004/vertical_data/<ipython
console>

/usr/lib/python2.4/site-packages/scipy/io/mio.py in loadmat(name,
dict, appendmat, basename)
    790         if (M > 1):
    791             fid.close()
--> 792             raise ValueError, "Unsupported binary format."
    793         if (O != 0):
    794             fid.close()

ValueError: Unsupported binary format.

Just to try and get some more information, I hacked up mio.py starting
around line 790:
        M,rest = divmod(header[0],1000)
        O,rest = divmod(rest,100)
        P,rest = divmod(rest,10)
        T = rest

        print('M='+str(M))
        print('O='+str(O))
        print('P='+str(P))
        print('T='+str(T))
        if (M > 1):
            print('Bad M')
#            fid.close()
#            raise ValueError, "Unsupported binary format."
        if (O != 0):
            print('Bad O')
#            fid.close()
#            raise ValuError, "Hundreds digit of first integer should be zero."

        if (T not in [0,1]):
            print('Bad T')
#            fid.close()
#            raise ValueError, "Cannot handle sparse matrices, yet."


And then I get this:
In [1]: temp=io.loadmat('vertical2_11_24_04_lowfreq.mat')
M=0
O=0
P=1
T=0
M=1818583
O=9
P=0
T=7
Bad M
Bad O
Bad T
---------------------------------------------------------------------------
exceptions.MemoryError                               Traceback (most
recent call last)

/home/ryan/thesis/actuator_modeling/torque_testing/data_Nov2004/vertical_data/<ipython
console>

/usr/lib/python2.4/site-packages/scipy/io/mio.py in loadmat(name,
dict, appendmat, basename)
    808         storage = {0:'d',1:'f',2:'i',3:'h',4:'H',5:'B'}[P]
    809
--> 810         varname = fid.fread(header[-1],'char')[:-1]
    811         varname = varname.tostring()
    812         defnames.append(varname)

/usr/lib/python2.4/site-packages/scipy/io/mio.py in read(self, count,
stype, rtype, bs, c_is_b)
    283         if count == 0:
    284             return zeros(0,rtype)
--> 285         retval = numpyio.fread(self, count, stype, rtype, bs)
    286         if len(retval) == 1:
    287             retval = retval[0]

MemoryError:

So that it looks like it is passing through with valid values for
M,T,O,and P once and then getting bad values on a second pass.  I
don't know what any of this means.

I believe this is a matlab v4 file.  Old scipy and octave can both open it.

Thanks,

Ryan

On 2/1/06, Travis Oliphant <oliphant.travis at ieee.org> wrote:
> Ryan Krauss wrote:
>
> >I am having trouble loading Matlab .mat files that loaded just fine
> >under the old scipy.  Here is the error message:
> >
> >
> Hi Ryan.  With latest SVN of scipy, I'm able to load your matfile just
> fine.
>
> I'm not sure what the issue was, but I did change the getsize_type
> function in mio.py to make sure that the second argument returned is
> always a character.   There was a chance it could be returned as a
> type-object.
>
> If  you can't get the latest SVN version, let me know what version of
> numpy you are using and I can give you a couple-line edit to the mio.py
> file that should work.
>
> -Travis
>
>
>
> _______________________________________________
> 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