8000 Merge pull request #1227 from effigies/enh/catch_svd_failure · nipy/nibabel@977d044 · GitHub
[go: up one dir, main page]

Skip to content

Commit 977d044

Browse files
authored
Merge pull request #1227 from effigies/enh/catch_svd_failure
ENH: Catch SVD failure and raise informative HeaderDataError
2 parents abe765f + 5827168 commit 977d044

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
@@ -1097,7 +1097,10 @@ def set_qform(self, affine, code=None, strip_shears=True):
10971097
# (a subtle requirement of the NIFTI format qform transform)
10981098
# Transform below is polar decomposition, returning the closest
10991099
# orthogonal matrix PR, to input R
1100-
P, S, Qs = npl.svd(R)
1100+
try:
1101+
P, S, Qs = npl.svd(R)
1102+
except np.linalg.LinAlgError as e:
1103+
raise HeaderDataError(f'Could not decompose affine:\n{affine}') from e
11011104
PR = np.dot(P, Qs)
11021105
if not strip_shears and not np.allclose(PR, R):
11031106
raise HeaderDataError('Shears in affine and `strip_shears` is False')

0 commit comments

Comments
 (0)
0