diff --git a/nibabel/nifti1.py b/nibabel/nifti1.py index e2666609e2..82e4531f66 100644 --- a/nibabel/nifti1.py +++ b/nibabel/nifti1.py @@ -820,7 +820,7 @@ def get_qform(self, coded=False): quat = self.get_qform_quaternion() R = quat2mat(quat) vox = hdr['pixdim'][1:4].copy() - if np.any(vox) < 0: + if np.any(vox < 0): raise HeaderDataError('pixdims[1,2,3] should be positive') qfac = hdr['pixdim'][0] if qfac not in (-1, 1): diff --git a/nibabel/tests/test_nifti1.py b/nibabel/tests/test_nifti1.py index a40367d877..57b58bf729 100644 --- a/nibabel/tests/test_nifti1.py +++ b/nibabel/tests/test_nifti1.py @@ -448,6 +448,10 @@ def test_qform(self): assert_true, ehdr['qform_code'] == xfas['scanner'] ehdr.set_qform(A, xfas['aligned']) assert_true, ehdr['qform_code'] == xfas['aligned'] + # Test pixdims[1,2,3] are checked for negatives + for dims in ((-1, 1, 1), (1, -1, 1), (1, 1, -1)): + ehdr['pixdim'][1:4] = dims + assert_raises(HeaderDataError, ehdr.get_qform) def test_sform(self): # Test roundtrip case