[Neuroimaging] Nibabel API change - always read as float

Alexandre ABRAHAM abraham.alexandre at gmail.com
Mon Jul 6 18:38:27 CEST 2015


Hi list,

For all the reasons mentioned above, I also think that it's a bad idea. As
a regular user of nibabel for big data, this would be a burden for me
espacially because, when we cast to float, we chose float32 to save as
memory as possible (most of the time, float64 precision is not needed and
it costs a lot).

Speaking of beginners, I think that it is better to warn them, rather to
set up guards everywhere. This problem is not nibabel specific: it is numpy
(and even python) specific. I think that teaching them to _always_ cast
their data to float unless they know what they're doing is a good idea.
Better, np.seterr() is here to help you set overflow as errors.

Alex.


On Mon, Jul 6, 2015 at 6:24 PM, vanessa sochat <vsochat at stanford.edu> wrote:

> I don't like the modification, because there are plenty of images that
> should be returned as int16. It's much more reasonable to have a workflow
> like:
>
> data = img.get_data()
>
> *look at, think about, your data*
> *make decisions* (cast as float, don't, etc)
>
> Possibly we can have an intermediate solution of leaving the default
> behavior and adding a to_float parameter, as Christopher suggested. But I'm
> not sure how that is any better or different than float(data).
>
>
> On Mon, Jul 6, 2015 at 9:13 AM, Matthew Brett <matthew.brett at gmail.com>
> wrote:
>
>> 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
>> _______________________________________________
>> Neuroimaging mailing list
>> Neuroimaging at python.org
>> https://mail.python.org/mailman/listinfo/neuroimaging
>>
>
>
>
> --
> Vanessa Villamia Sochat
> Stanford University
> (603) 321-0676
>
> _______________________________________________
> 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/20150706/1f747aa9/attachment.html>


More information about the Neuroimaging mailing list