Skip to content

Commit

Permalink
Merge pull request #1227 from effigies/enh/catch_svd_failure
Browse files Browse the repository at this point in the history
ENH: Catch SVD failure and raise informative HeaderDataError
  • Loading branch information
effigies authored Sep 5, 2024
2 parents abe765f + 5827168 commit 977d044
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nibabel/nifti1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,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')
Expand Down

0 comments on commit 977d044

Please sign in to comment.