NiBabel

Access a cacophony of neuro-imaging file formats

Previous topic

nibabel.volumeutils.finite_range

Next topic

nibabel.volumeutils.make_dt_codes

Reggie -- the one

nibabel.volumeutils.int_scinter_ftype

nibabel.volumeutils.int_scinter_ftype(ifmt, slope=1.0, inter=0.0, default=<type 'numpy.float32'>)

float type containing int type ifmt * slope + inter

Return float type that can represent the max and the min of the ifmt type after multiplication with slope and addition of inter with something like np.array([imin, imax], dtype=ifmt) * slope + inter.

Note that slope and inter get promoted to 1D arrays for this purpose to avoid the numpy scalar casting rules, which prevent scalars upcasting the array.

Parameters :

ifmt : object

numpy integer type (e.g. np.int32)

slope : float, optional

slope, default 1.0

inter : float, optional

intercept, default 0.0

default_out : object, optional

numpy floating point type, default is np.float32

Returns :

ftype : object

numpy floating point type

Notes

It is difficult to make floats overflow with just addition because the deltas are so large at the extremes of floating point. For example:

>>> arr = np.array([np.finfo(np.float32).max], dtype=np.float32)
>>> res = arr + np.iinfo(np.int16).max
>>> arr == res
array([ True], dtype=bool)

Examples

>>> int_scinter_ftype(np.int8, 1.0, 0.0) == np.float32
True
>>> int_scinter_ftype(np.int8, 1e38, 0.0) == np.float64
True