Skip to content

Commit b144ea5

Browse files
committed
Merge pull request #347 from effigies/patch-1
MRG: negative vox size check always False Wrongly placed parenthesis always returned False for negative voxel check. Fix and test.
2 parents 7fe2ebc + 08a20a4 commit b144ea5

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

nibabel/nifti1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ def get_qform(self, coded=False):
820820
quat = self.get_qform_quaternion()
821821
R = quat2mat(quat)
822822
vox = hdr['pixdim'][1:4].copy()
823-
if np.any(vox) < 0:
823+
if np.any(vox < 0):
824824
raise HeaderDataError('pixdims[1,2,3] should be positive')
825825
qfac = hdr['pixdim'][0]
826826
if qfac not in (-1, 1):

nibabel/tests/test_nifti1.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ def test_qform(self):
448448
assert_true, ehdr['qform_code'] == xfas['scanner']
449449
ehdr.set_qform(A, xfas['aligned'])
450450
assert_true, ehdr['qform_code'] == xfas['aligned']
451+
# Test pixdims[1,2,3] are checked for negatives
452+
for dims in ((-1, 1, 1), (1, -1, 1), (1, 1, -1)):
453+
ehdr['pixdim'][1:4] = dims
454+
assert_raises(HeaderDataError, ehdr.get_qform)
451455

452456
def test_sform(self):
453457
# Test roundtrip case

0 commit comments

Comments
 (0)