[Neuroimaging] indexed access to gziped files

paul mccarthy pauldmccarthy at gmail.com
Mon Mar 14 17:12:21 EDT 2016


Hi Matthew,

Thanks for clarifying the flieobj 'dance'!

I had meant to ask you about cython - it looks like a good option (and is
recommended in the official docs -
https://docs.python.org/3/howto/cporting.html), so I'll look into it.
Perhaps the best way forward would be for me to drop the mailing list a
line when I've got something in a more useable state.

Cheers,

Paul

On 14 March 2016 at 17:50, Matthew Brett <matthew.brett at gmail.com> wrote:

> Hi,
>
> On Mon, Mar 14, 2016 at 3:51 AM, paul mccarthy <pauldmccarthy at gmail.com>
> wrote:
> > Hi all,
> >
> >
> >> This isn't so if you create an image via the fileobject itself.
> >
> >
> > Matthew, is this currently possible in nibabel? I had a quick play, and
> poke
> > through the code, but I couldn't get anything to work - it looks like
> there
> > is no "from_fileobj" method defined in the Nifti1Image class (or any of
> its
> > bases).
>
> There isn't a `from_fileobj` because some images need more than one
> file (like nifti .img / .hdr pairs).
>
> It might be worth adding `from_fileobj` to image types that do need
> only one file (like .nii files) - I can't think of any big problems
> with that offhand.
>
> At the moment, you have do do this dance:
>
> In [1]: import nibabel as nib
> In [2]: fobj = open('my_mri.nii', 'rb')
> In [3]: fm = nib.Nifti1Image.make_file_map()
> In [6]: fm['image'].fileobj = fobj
> In [7]: img = nib.Nifti1Image.from_file_map(fm)
> In [8]: img.shape
> Out[8]: (2, 3, 4, 4)
>
> > If this is (or will be possible), then then the problem is solved, isn't
> it?
> > Users of nibabel can just create IndexedGzipFile instances themselves,
> and
> > pass the handle to nibabel. No need for nibabel to be dependent upon
> > indexed_gzip - the choice would be up to the caller. Or am I missing
> > something here?
>
> Sure - that could work, and be easier with a `from_fileobj` method.
> But it would involve the user having to use some boilerplate rather
> than having it happen automatically via `nib.load`.
>
> Did you have a chance to look into Cython for the wrapping problem?
>
> Cheers,
>
> Matthew
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20160314/fbc5c341/attachment.html>


More information about the Neuroimaging mailing list