[Neuroimaging] Nibabel API change - always read as float
Matthew Brett
matthew.brett at gmail.com
Mon Jul 20 22:35:01 CEST 2015
Hi,
On Mon, Jul 20, 2015 at 9:14 PM, Alexis Roche <alexis.roche at gmail.com> wrote:
> Exactly - but I think that what makes the situation ambiguous is to consider
> the "intent" of whoever created the nifti file. It may not be relevant
> because the nifti norm does not allow to make such intent explicit anyway...
Right.
> Having said that, I would be totally happy if the load function would take a
> dtype keyword argument, which could default to float (fair enough), but
> would leave me the possibility to load my data as unsingned int16 if I want
> to (of course, without loading a float array first) and would issue a
> warning if that entails information loss (e.g. because of a non-integer
> slope).
At the moment, that would look like:
Loading in on-disk dtype
data = img.dataobj.get_unscaled()
if (img.dataobj.slope, img.dataobj.inter) != (1, 0):
print('I did not use your scaling')
data = data.astype(np.int16)
That is as small as the image can go in memory, so `dtype=` couldn't
do better than that.
Can you think of a common use of an arbitrary dtype here? I mean
dtype not equal to the on-disk dtype or the scaled dtype? It seems
as if that use might be rather specialized - could it be done in the
user code that starts with the code above?
> Even better, have the option to pass in `dtype='native'` or
> something like that, and get the array in the same format as on disk if
> slope and offset permit, an error otherwise.
I guess that is the same as:
if (img.dataobj.slope, img.dataobj.inter) != (1, 0):
raise RuntimeError('There is scaling')
data = img.dataobj.get_unscaled()
?
Cheers,
Matthew
More information about the Neuroimaging
mailing list