Open
Description
There is often confusion about the meaning of img.header.get_data_dtype()
even from regular users of nibabel. I would propose having an explicit concept of raw (on-disk) and effective dtypes (provisionally, rdtype and edtype).
class DataobjHeader:
@property
def rdtype(self):
"""Raw type of data object, as stored on disk"""
@rdtype.setter
def rdtype(self, dt):
"""Set the type that data should be coerced to when saved to disk"""
@property
def edtype(self):
"""Effective type of data object, when scaled"""
@edtype.setter
def edtype(self, dt):
"""Set the type that data should be coerced to when read into a numpy array"""
This would allow for checks like:
if np.issubdtype(img.header.edtype, np.integral):
# Probably a label or mask file
else:
# Probably not intended to be discrete
Currently the easiest way to find out the effective dtype is img.dataobj[0, 0, 0].dtype
.