Skip to content

Commit

Permalink
ENH: Catch SVD failure and raise informative HeaderDataError
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Apr 20, 2023
1 parent c0be346 commit 5827168
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 @@ -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')
Expand Down

0 comments on commit 5827168

Please sign in to comment.