Hi, On Wed, Oct 08, 2008 at 12:05:39PM +0200, Michael Hanke wrote: > On Wed, Oct 08, 2008 at 11:26:43AM +0200, Gael Varoquaux wrote: > > On Wed, Oct 08, 2008 at 11:14:14AM +0200, Michael Hanke wrote: > > > The file should be correct, but the way you access the array causes > > > trouble. getDataArray() simply returns a pointer to the data allocated > > > by the nifti library. As you do not store the nifti image itself, that > > > data is destroyed immediately, hence segfault when accessing it. > > > > Ha, OK. It did seem that the data was being derefenced, but it wasn't > > clear to me that this was the expected behavior. > > > > > Just replace getDataArray() (or simply .data) with asarray(), which has > > > a parameter 'copy' that is True by default. > > > > Why is the copy necessary? It seems that this should simply be a refcount > > increment, rather than the copy. Travis Oliphant has a nice blog post on > > a cool way to do this: > > http://blog.enthought.com/?p=62 > Good pointer! I guess the reason why it is not implemented like this is > that the blog post is dated "September 9th, 2008" ;-) I have released a new version of PyNIfTI. Together with some minor updates it now also handles the refcount issue properly. If I got it right, there should be no need for unnecessary copying anymore and it should be safe to simply use .data instead of asarray().
Thanks again for the pointer, Michael -- GPG key: 1024D/3144BE0F Michael Hanke http://apsy.gse.uni-magdeburg.de/hanke ICQ: 48230050 _______________________________________________ Pkg-ExpPsy-PyMVPA mailing list [email protected] http://lists.alioth.debian.org/mailman/listinfo/pkg-exppsy-pymvpa

