[Neuroimaging] indexed access to gziped files
pauldmccarthy at gmail.com
Mon Mar 14 17:12:21 EDT 2016
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.
On 14 March 2016 at 17:50, Matthew Brett <matthew.brett at gmail.com> wrote:
> On Mon, Mar 14, 2016 at 3:51 AM, paul mccarthy <pauldmccarthy at gmail.com>
> > 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
> > through the code, but I couldn't get anything to work - it looks like
> > is no "from_fileobj" method defined in the Nifti1Image class (or any of
> > 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 : import nibabel as nib
> In : fobj = open('my_mri.nii', 'rb')
> In : fm = nib.Nifti1Image.make_file_map()
> In : fm['image'].fileobj = fobj
> In : img = nib.Nifti1Image.from_file_map(fm)
> In : img.shape
> Out: (2, 3, 4, 4)
> > If this is (or will be possible), then then the problem is solved, isn't
> > Users of nibabel can just create IndexedGzipFile instances themselves,
> > 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?
> Neuroimaging mailing list
> Neuroimaging at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Neuroimaging