nibabel icon indicating copy to clipboard operation
nibabel copied to clipboard

Add ConsistencyWarning to flag apparent inconsistencies in headers

Open effigies opened this issue 6 years ago • 3 comments

I've run across (poldracklab/fmriprep#1069) an image with sform_code = 1, but srow_x = srow_y = srow_z = [0, 0, 0, 0]. Although there is a valid qform, Nifti1Header.get_best_affine returns an affine:

array([[0., 0., 0., 0.],
       [0., 0., 0., 0.],
       [0., 0., 0., 0.],
       [0., 0., 0., 1.]])

Is this an appropriate case for nibabel to handle differently, or is it the responsibility of the user/program to check for invalid affine matrices?

If it is nibabel's problem, then I wonder whether the better solution is to throw a HeaderDataError or to have get_best_affine check for an invalid sform and return the qform.

Thoughts?

effigies avatar Apr 26 '18 17:04 effigies

Anybody have thoughts on this? I'm inclined to at least warn.

effigies avatar Apr 26 '19 12:04 effigies

Yes, it's tricky. Certainly warn, but I can see the argument for dropping back to the qform as well.

matthew-brett avatar Apr 26 '19 13:04 matthew-brett

As I'm thinking about it, I'm hesitant to try to guess intent. This should probably be treated as a corrupt file and falling back to qform disguises that.

I'm thinking of introducing a ConsistencyWarning for cases like this, so apps that are doing things such as fixing up a header can add an 'ignore' filter when they know they're working with an inconsistent header, and add an 'error' filter when they would prefer an exception to be raised and caught.

This might be a useful pattern for #118 as well, permitting write-time precision loss to produce a warning above a certain threshold and let programmers decide how/whether to filter.

effigies avatar Apr 28 '19 14:04 effigies