[Neuroimaging] Nibabel API change - always read as float

Matthew Brett matthew.brett at gmail.com
Mon Jul 6 18:13:00 CEST 2015


Hi,

On Mon, Jul 6, 2015 at 5:03 PM, Ben Cipollini <bcipolli at ucsd.edu> wrote:
> I agree with Gael.
>
> I would also add, it also seems to be solving a problem that doesn't seem to
> exist in the wild. There's never a report of hitting this issue, right?
> Users using sum() or other raw operations are likely familiar with numpy,
> and more ready/capable to debug their error.

Basically any numpy operation on the returned array can give you weird errors.

I did precisely run into this when teaching the students.  I was
teaching them to run diagnostics, and the script I wrote used the sum.
This worked fine on one set of functional images, but gave a
completely wrong answer on another set of images, and it took me a
little while to work out what had gone wrong.  Part of the problem is
that nifti images are often int16, so it's easy to run into silent
horrors just by adding or subtracting.  My feeling is that dealing
with any operations on int16 arrays is for advanced users.  Advanced
users will know to do `to_float=False`.

> Adding complexity can potentially introduce confusion for all users,
> including relatively numpy-naive ones. Then we potentially have to support
> new questions, and I'm not sure there's any practical benefit.

I think this is reducing complexity for basic use (you don't have to
think about your data types, until you want to think about your data
types).  At the moment, when you see this:

data = img.get_data()

you have to think 'oh wait, at the moment I can't easily predict what
data type this is.  If I want to do stuff with this array, I will
probably have to cast to float for safety'.

Cheers,

Matthew


More information about the Neuroimaging mailing list