[Neuroimaging] Nibabel API change - always read as float

Brendan Moloney moloney at ohsu.edu
Tue Jul 7 01:08:30 CEST 2015


> You just compared loading of Nifti files, which are binary, to loading
> of text files. So I consider my comparison of npy binary files to Nifti
> files as analagous.

I was comparing two situations where the intended data type is unclear.
The only time this comes up for data loading in numpy is text files. But
you could also look at all the numpy array creation routines which
default to float64 (at least for most people). Clearly the numpy
developers prefer to avoid overflow issues rather than improve
efficiency by default.

> Yes, this is basic error handling for non-technical users.

So I guess you have some function like 'check_mask' that enforces this
check? You could add a check for the scale factors in there too.

> If you passed an integer dtype to 'nibabel.load' and the file has scaling factors, we
> could raise an exception. So your use case might actually be an argument for this
> proposal rather than against it.

> I don't see your point here.

I am not 100% sure it is the right thing to do, but we could raise an
exception when someone asks for integer output and the file is clearly
meant to contain floating point data (i.e. the intercept/scale factors are
not 0/1). After all, they could still access the raw values through the
'dataobj'. This avoids the issue you mentioned, although you could
easily add some extra checks yourself (as mentioned above).

> 1) You know the image is providing a mask or labels from context

> As said before, implicit cast won't work in that case.

It would be an explicit cast and I am not convinced there is any issue
here. Again, see above.

> 2) You want to save memory and know what you are doing

> Agreed.

To be even more specific: You want to save memory, you know what
you are doing, and you know the operations you are going to perform
will not overflow the requested dtype.

> Without this proposal you need to cast everything to float except for the above
> cases, which seems worse to me (ignoring the argument for novices).

> No, I don't have to cast everything to float. I only cast MRI images
> to float when it is needed.

I think people need float data more often than not, but obviously that
depends on what you do with nibabel. Any default will be annoying to
some users. I tend to pass 'dtype=np.float32' into a lot of numpy routines
because I don't need the extra precision but do need to speed up
calculations and save RAM. This might even be the case for the majority
of numpy users, but I recognize that it is still a good default (premature
optimization and all that...).

> Honestly, I don't see the point in convincing people that your choice is
> the good one. In my usecases, it is clearly not. Whatever choice is made,
> I will just deal with it.

Sorry, I could be a bit more diplomatic some times. I don't mean to
discourage anyone from participating in the conversation.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20150706/29163ae5/attachment-0001.html>


More information about the Neuroimaging mailing list