[Neuroimaging] Nibabel API change - always read as float

Matthew Brett matthew.brett at gmail.com
Mon Jul 6 18:05:53 CEST 2015


Hi,

On Mon, Jul 6, 2015 at 4:55 PM, Gael Varoquaux
<gael.varoquaux at normalesup.org> wrote:
> I think that this is a very bad idea. First because it's "magic": changing
> things behind the back of the user. People will be surprised and it will
> lead to bugs in their code.  Second because it is a loss of semantics.
> Something like a mask or a label image is stored as integers for a good
> reason.

Sure - but if the mask or label image is stored in anything less than
(u)int64, then float64 can encode the values exactly (float64 encodes
integers up to 2 ** 53 exactly).  So it will be less efficient, but
unless the user was relying on integer overflow, I think bugs will be
unusual.

At the moment the user is in a bad situation, because the output data
type can be arbitrary, depending on whether the author of the image
felt like writing the scalefactors in or not.   If they did, then you
get a float image, if they didn't you get an integer image, and
usually, an int16 image for which it is very easy to hit integer
overflow.

> The right solution to the problem is to teach people to use float data when
> relevant, but not to force this decision in them.

I don't think this is magic - it's just a sensible default.  So, the
users who don't want the decision forced on them can very easily opt
out.

Cheers,

Matthew


More information about the Neuroimaging mailing list