[Pkg-exppsy-pynifti] Image, design, usecases
Michael Hanke
michael.hanke at gmail.com
Tue May 12 08:26:46 UTC 2009
On Mon, May 11, 2009 at 03:24:17PM -0700, Matthew Brett wrote:
> Me again, a second time.
>
> As a result of discussions with Fernando, how about:
>
> import StringIO as StringIO
> import numpy as np
> data = np.zeros((2,3,4))
> affine = np.eye(4)
>
> img1 = Nifti1Image(data, affine, filespec='my_image')
> assert img1.get_filename() == 'my_image.nii'
> img1.save() # no error, files already set
> str_io = StringIO()
> files = {'image': str_io, 'header': str_io}
>
> img2 = Nifti1Image(data, affine, filespec=files)
> assert img2.get_filename() is None
> img2.save() # no error, files already set
>
> img3 = Nifti1Image(data, affine)
> img3.save() # raises runtime error of some sort
>
> img3.save('my_image') # OK
> img3.save(files) # OK
> img3.set_filespec('my_image')
> assert img3.get_filename() == 'my_image.nii'
> img3.save() # obviously OK
>
> Underneath all this we might have a FileSpec object or function that
> accepted filenames, dictionaries, tuples, and file-like objects in
> some standard way, and that would deal with the Image.__init__ case,
> and set_filespec, and save.
Looks good to me.
> > The question to me is really whether we want to handle cases like
> > 'somefile.hdr + crazyblob.exe', although that would technically be
> > possible.
>
> No, right, I'm not that interested in that rather opaque use-case, but
> I am interested in the ability to pass in file-like objects. I seem
> to remember that's already been a feature request for pynifti - no?
> And it's useful for testing. And it opens up an interfacey way to
> work with non-filesystem targets like databases.
Yeah, indeed. Maybe my proposal in that other message could be enhanced
so that writers would also support StringIO input?
Michael
--
GPG key: 1024D/3144BE0F Michael Hanke
http://apsy.gse.uni-magdeburg.de/hanke
ICQ: 48230050
More information about the Pkg-exppsy-pynifti
mailing list