Skip to content

Commit 5827168

Browse files
committed
ENH: Catch SVD failure and raise informative HeaderDataError
1 parent c0be346 commit 5827168

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

nibabel/nifti1.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,10 @@ def set_qform(self, affine, code=None, strip_shears=True):
10981098
# (a subtle requirement of the NIFTI format qform transform)
10991099
# Transform below is polar decomposition, returning the closest
11001100
# orthogonal matrix PR, to input R
1101-
P, S, Qs = npl.svd(R)
1101+
try:
1102+
P, S, Qs = npl.svd(R)
1103+
except np.linalg.LinAlgError as e:
1104+
raise HeaderDataError(f'Could not decompose affine:\n{affine}') from e
11021105
PR = np.dot(P, Qs)
11031106
if not strip_shears and not np.allclose(PR, R):
11041107
raise HeaderDataError('Shears in affine and `strip_shears` is False')

0 commit comments

Comments
 (0)