[Nipy-devel] attributes error

Jonathan Taylor jonathan.taylor at stanford.edu
Tue May 30 15:37:14 CDT 2006


i know what you mean about the copy -- actually, it was setting it on a 
copy, but
it was a copy of the fMRI image's iterator.

---------
            value = copy.copy(self.grid.itervalue)
            value.slice = value.slice[1]
-----------

i suppose there might be a better way to do the copy, though.

-- jonathan

Brian Hawthorne wrote:

> jonathan,
> for the declaration of the slice attribute, set implements=list,slice.
>  
> regarding modifying the value of slice, i highly recommend simply 
> constructing
> a new SliceIteratorNext with the new slice value instead of modifying 
> the existing one.
> in general, it's a good idea to modify objects as little as possible 
> and favor copying.
> a good bit of the work i've done one the codebase so far is oriented 
> toward shifting from a modify to a copy pattern.  modification can 
> generate hidden dependencies which are
> hard to debug and untangle, making the code harder to scale and maintain.
>  
> -brian 
>
>  
> On 5/28/06, *Jonathan Taylor* <jonathan.taylor at stanford.edu 
> <mailto:jonathan.taylor at stanford.edu>> wrote:
>
>     I wanted to change a read-only attribute (the slice attribute of
>     SliceIteratorNext) to
>     not read-only but "untyped". I changed "readonly" to "attribute"
>     and got
>     the following message:
>
>     --------------
>     Traceback (most recent call last):
>     File "run.py", line 173, in ?
>        FIACrun(subj=subj, run=run)
>     File "run.py", line 134, in FIACrun
>        OLS.fit ()
>     File
>     "/home/jtaylo/python/lib/python2.4/site-packages/neuroimaging/fmri/fmristat/__init__.py",
>     line 107, in fit
>        LinearModelIterator.fit(self, **keywords)
>     File
>     "/home/jtaylo/python/lib/python2.4/site-packages/neuroimaging/statistics/regression.py",
>
>     line 48, in fit
>        output.next(data=out)
>     File
>     "/home/jtaylo/python/lib/python2.4/site-packages/neuroimaging/fmri/regression.py",
>     line 40, in next
>        value.slice = value.slice[1]
>     File "/home/jtaylo/python/lib/python2.4/site-packages/attributes.py",
>     line 256, in set
>        self.validate(value)
>     File "/home/jtaylo/python/lib/python2.4/site-packages/attributes.py",
>     line 211, in validate
>        if not self.isvalid(value): raise ProtocolOmission(
>     protocols.ProtocolOmission : attribute slice implements ([slice(0,
>     191,
>     1), slice(0, 1, 1)],), value slice(0, 1, 1) of type <type 'slice'>
>     does
>     not implement: ('__getslice__', 'pop', 'remove', '__rmul__', '__lt__',
>     'append', 'index', '__delslice__', '__getitem__', '__contains__',
>     '__len__', 'sort', '__ne__', 'extend', 'insert', '__iter__',
>     '__add__',
>     '__gt__', '__eq__', 'reverse', 'count', '__delitem__', '__reversed__',
>     '__imul__', '__setslice__', '__setitem__', '__iadd__', '__le__',
>     '__mul__', '__ge__')
>
>     ---------------------------
>
>     I am not sure how to get this to work. I want it to behave like a
>     slice or a list of slices.
>
>     There is a very good example when you want to be able to change
>     its value later: when the "iterator" driving the voxelwise
>     analysis comes from an fMRI image, it spits out
>     slices of time series, but if you want to output slices of floats
>     (i.e. a 3d image of means), you want to ignore the first part of
>     this (python) slice but you can still use the same
>     "SliceIteratorNext" instance to drive the next method of the
>     images....
>
>     Thanks,
>
>     Jonathan
>
>     --
>     ------------------------------------------------------------------------
>     I'm part of the Team in Training: please support our efforts for the
>     Leukemia and Lymphoma Society!
>
>     http://www.active.com/donate/tntsvmb/tntsvmbJTaylor
>
>     GO TEAM !!!
>
>     ------------------------------------------------------------------------
>
>     Jonathan Taylor                           Tel:   650.723.9230
>     Dept. of Statistics                       Fax:   650.725.8977
>     Sequoia Hall, 137                        
>     www-stat.stanford.edu/~jtaylo <http://www-stat.stanford.edu/%7Ejtaylo>
>     390 Serra Mall
>     Stanford, CA 94305
>
>     _______________________________________________
>     Nipy-devel mailing list
>     Nipy-devel at neuroimaging.scipy.org
>     <mailto:Nipy-devel at neuroimaging.scipy.org>
>     http://neuroimaging.scipy.org/mailman/listinfo/nipy-devel
>
>

-- 
------------------------------------------------------------------------
I'm part of the Team in Training: please support our efforts for the
Leukemia and Lymphoma Society!

http://www.active.com/donate/tntsvmb/tntsvmbJTaylor

GO TEAM !!!

------------------------------------------------------------------------
Jonathan Taylor                           Tel:   650.723.9230
Dept. of Statistics                       Fax:   650.725.8977
Sequoia Hall, 137                         www-stat.stanford.edu/~jtaylo
390 Serra Mall
Stanford, CA 94305




More information about the Nipy-devel mailing list