[Neuroimaging] trouble with fileslice

Matthew Brett matthew.brett at gmail.com
Wed Aug 31 13:36:25 EDT 2016


On Wed, Aug 31, 2016 at 10:20 AM, Matthew Brett <matthew.brett at gmail.com> wrote:
> Hi,
>
> On Tue, Aug 30, 2016 at 10:05 AM, Natalia Mesa
> <v-nataliam at alleninstitute.org> wrote:
>> Hi,
>>
>>
>>
>> I’m trying to extract an ROI from a large binary file. Whenever I run
>> nibabel.fileslice.fileslice, I’m getting the following error:
>>
>>
>>
>>
>>
>> C:\Anaconda2\lib\site-packages\nibabel\fileslice.pyc in
>> optimize_read_slicers(sliceobj, in_shape, itemsize, heuristic)
>>
>>     560         if not isinstance(read_slicer, Integral):
>>
>>     561             post_slicers.append(post_slicer)
>>
>> --> 562         stride*=dim_len
>>
>>     563
>>
>>     564     return tuple(read_slicers), tuple(post_slicers)
>>
>>
>>
>> TypeError: unsupported operand type(s) for *=: 'getset_descriptor' and 'int'
>>
>>
>>
>> I’m calling this function with the following:
>>
>> filepath = filepath
>>
>> dtype = 'uint16'
>>
>> chunksize = int((npix*nframes))
>>
>>
>>
>> sliceobj=slice((0,20,None),(0,20,None))
>>
>>
>>
>> f = open(filepath, 'r')
>>
>>
>>
>> dat=nibabel.fileslice.fileslice(f, sliceobj=sliceobj, shape=(2048,2048,100),
>> dtype=np.uint16)
>>
>>
>>
>> The binary file I’m trying to analyze is imaging data, and thus the final
>> shape of the array is 3D. The slice object I’m inputting is a 20 by 20 pixel
>> ROI.
>
> I think you actually want:
>
> sliceobj = (slice(0,20,None), slice(0,20,None))
>
> This gives you the equivalent of slicing like `arr[:20, :20]`.
>
> I also see that you'll need to do:
>
> import numpy as np
> dtype = np.dtype('uint16')
>
> The function could be smarter about working that out, I'll fix that up.

Here's the fix-up:

https://github.com/nipy/nibabel/pull/485

Matthew


More information about the Neuroimaging mailing list