[Neuroimaging] Nibabel API change - always read as float

Brendan Moloney moloney at ohsu.edu
Tue Jul 7 00:11:40 CEST 2015


Argh, replace 'nibabel.load' with 'img.get_data'.

________________________________
From: Neuroimaging [neuroimaging-bounces+moloney=ohsu.edu at python.org] on behalf of Brendan Moloney [moloney at ohsu.edu]
Sent: Monday, July 06, 2015 3:04 PM
To: Neuroimaging analysis in Python
Subject: Re: [Neuroimaging] Nibabel API change - always read as float


> For example, if the first column is an index, casting it to float makes no sense.

And if the first row provides indices the given result makes no sense. If you are
going to appeal to the authority of numpy you should recognize that their
default policy appears to be "when in doubt use floats".

> Yes. So they could have casted all data to float if they wanted to, but they didn't.

This is not analogous at all.

> Well the context is also obvious when you load MRI data, just cast it to float in
> all cases. And no, it's not simple to pass a dtype when loading a mask. If an
> image is contains float values between 0 and 2, casting it to int will round the
> values to 0 and 1, ie a valid mask. But clearly, the file loaded was not meant to
> be used as a mask in the first place.

So every time you load a mask you check if the values are strictly zeros and ones?
I don't. I find it useful to allow a label image to be used as a mask. What if
someone passes in the image and it is just zeros and ones?  Do you raise an
exception because you are guessing they accidentally passed in a mask instead
of the image?

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.

If this proposal goes through, and the default for 'dtype' becomes float, the only
time you will need to pass the 'dtype' will be:

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

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

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).


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


More information about the Neuroimaging mailing list