diff --git a/nibabel/nifti1.py b/nibabel/nifti1.py index 9bb88e844..8502ad4fa 100644 --- a/nibabel/nifti1.py +++ b/nibabel/nifti1.py @@ -1098,7 +1098,10 @@ def set_qform(self, affine, code=None, strip_shears=True): # (a subtle requirement of the NIFTI format qform transform) # Transform below is polar decomposition, returning the closest # orthogonal matrix PR, to input R - P, S, Qs = npl.svd(R) + try: + P, S, Qs = npl.svd(R) + except np.linalg.LinAlgError as e: + raise HeaderDataError(f'Could not decompose affine:\n{affine}') from e PR = np.dot(P, Qs) if not strip_shears and not np.allclose(PR, R): raise HeaderDataError('Shears in affine and `strip_shears` is False')