[SciPy-dev] Please stress-test SVN version pf matlab reader
Ariel Rokem
arokem at berkeley.edu
Thu Jan 7 22:58:55 EST 2010
Hi Matthew,
further - if I set both squeeze_me and struct_as_record to True (does that
make sense?), I get into some rather nasty situations, where I can't use the
variables in the matfile:
For example:
In [40]: m =
sio.loadmat('C-RA_Adapt.mat',squeeze_me=True,struct_as_record=True)
In [41]: h = m['history']
In [42]: h1 = h[0]
In [43]: q = h1['q']
Yes - I know it's a bit convoluted, but that's how it is.
Now - I can't do anything with 'q':
In [44]: q[0]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
/Users/arokem/Projects/SchizoSpread/OrientationTuningBehavior/DATA/<ipython
console> in <module>()
IndexError: 0-d arrays can't be indexed
In [45]: q.dtype
Out[45]: dtype('object')
There's supposed to be an array called 'x' in there:
In [46]: q['x']
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/Users/arokem/Projects/SchizoSpread/OrientationTuningBehavior/DATA/<ipython
console> in <module>()
ValueError: field named x not found.
Am I doing something unreasonable?
Cheers,
Ariel
On Thu, Jan 7, 2010 at 7:26 PM, Ariel Rokem <arokem at berkeley.edu> wrote:
> Hi Matthew,
>
> I updated my scipy from the repo and I am still getting the following
> behavior (also reported a couple of days ago on scipy-user), when dealing
> with the attached file:
>
> In [6]: m =
> sio.loadmat('/Users/arokem/Projects/SchizoSpread/OrientationTuningBehavior/DATA/C-RA_Adapt.mat')
>
> /Library/Frameworks/Python.framework/Versions/6.0.0/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)
>
> So far, so good - this is to be expected. But, for obvious reasons, I want
> to set the kwarg squeeze_me to True:
>
> In [7]: m =
> sio.loadmat('/Users/arokem/Projects/SchizoSpread/OrientationTuningBehavior/DATA/C-RA_Adapt.mat',squeeze_me=True)
> ---------------------------------------------------------------------------
> TypeError Traceback (most recent call last)
>
> /Users/arokem/<ipython console> in <module>()
>
> /Library/Frameworks/Python.framework/Versions/6.0.0/lib/python2.6/site-packages/scipy/io/matlab/mio.pyc
> in loadmat(file_name, mdict, appendmat, **kwargs)
> 132 '''
> 133 MR = mat_reader_factory(file_name, appendmat, **kwargs)
> --> 134 matfile_dict = MR.get_variables()
> 135 if mdict is not None:
> 136 mdict.update(matfile_dict)
>
> /Library/Frameworks/Python.framework/Versions/6.0.0/lib/python2.6/site-packages/scipy/io/matlab/mio5.pyc
> in get_variables(self, variable_names)
> 411 continue
> 412 try:
> --> 413 res = self.read_var_array(hdr, process)
> 414 except MatReadError, err:
> 415 warnings.warn(
>
> /Library/Frameworks/Python.framework/Versions/6.0.0/lib/python2.6/site-packages/scipy/io/matlab/mio5.pyc
> in read_var_array(self, header, process)
> 380 `process`.
> 381 '''
> --> 382 return self._matrix_reader.array_from_header(header,
> process)
> 383
> 384 def get_variables(self, variable_names=None):
>
> /Library/Frameworks/Python.framework/Versions/6.0.0/lib/python2.6/site-packages/scipy/io/matlab/mio5_utils.so
> in scipy.io.matlab.mio5_utils.VarReader5.array_from_header
> (scipy/io/matlab/mio5_utils.c:4718)()
>
> /Library/Frameworks/Python.framework/Versions/6.0.0/lib/python2.6/site-packages/scipy/io/matlab/mio5_utils.so
> in scipy.io.matlab.mio5_utils.VarReader5.array_from_header
> (scipy/io/matlab/mio5_utils.c:4367)()
>
> /Library/Frameworks/Python.framework/Versions/6.0.0/lib/python2.6/site-packages/scipy/io/matlab/mio5_utils.so
> in scipy.io.matlab.mio5_utils.VarReader5.read_struct
> (scipy/io/matlab/mio5_utils.c:6771)()
>
> /Library/Frameworks/Python.framework/Versions/6.0.0/lib/python2.6/site-packages/scipy/io/matlab/mio5_utils.so
> in scipy.io.matlab.mio5_utils.VarReader5.read_mi_matrix
> (scipy/io/matlab/mio5_utils.c:3995)()
>
> /Library/Frameworks/Python.framework/Versions/6.0.0/lib/python2.6/site-packages/scipy/io/matlab/mio5_utils.so
> in scipy.io.matlab.mio5_utils.VarReader5.array_from_header
> (scipy/io/matlab/mio5_utils.c:4610)()
>
> /Library/Frameworks/Python.framework/Versions/6.0.0/lib/python2.6/site-packages/scipy/io/matlab/mio_utils.so
> in scipy.io.matlab.mio_utils.process_element
> (scipy/io/matlab/mio_utils.c:1272)()
>
> /Library/Frameworks/Python.framework/Versions/6.0.0/lib/python2.6/site-packages/scipy/io/matlab/mio_utils.so
> in scipy.io.matlab.mio_utils.process_element
> (scipy/io/matlab/mio_utils.c:1149)()
>
> TypeError: Cannot convert mat_struct to numpy.ndarray
>
>
> This doesn't happen when I set struct_as_record to True as well, but then I
> need to deal with all these record arrays that I get. And yes - it does seem
> to work faster, when it works, though I haven't done any thorough testing of
> that.
>
> Any ideas?
>
> Cheers,
>
> Ariel
>
>
>
>
>
--
Ariel Rokem
Helen Wills Neuroscience Institute
University of California, Berkeley
http://argentum.ucbso.berkeley.edu/ariel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20100107/07161599/attachment.html>
More information about the SciPy-Dev
mailing list