[Neuroimaging] Nibabel API change - always read as float

Michael Waskom mwaskom at stanford.edu
Mon Jul 6 18:33:42 CEST 2015


But that logic equally applies when the default behavior of get_data() is
to cast the data to float. You should still look at your data and then
decide what the right way to handle it is (with one option being "read
again with as_float=False). But I think Matthew's point is that the
possible risks of getting int data and treating it like float are greater
and less obvious than the possible risks of getting float data and treating
it like int. Do you disagree with that?

On Mon, Jul 6, 2015 at 9:24 AM, 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/05b2e781/attachment-0001.html>


More information about the Neuroimaging mailing list