Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disambiguating on-disk dtype and effective dtype #1151

Open
effigies opened this issue Nov 30, 2022 · 0 comments
Open

Disambiguating on-disk dtype and effective dtype #1151

effigies opened this issue Nov 30, 2022 · 0 comments

Comments

@effigies
Copy link
Member

effigies commented Nov 30, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant