Skip to content

Commit dc3b6ad

Browse files
TEST: Added acceptance test for qform code being '2' after parrec2nii.
1 parent 7f77fe7 commit dc3b6ad

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

nibabel/tests/test_parrec2nii.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
""" Tests for the parrec2nii exe code
22
"""
33
import imp, numpy
4+
from numpy.testing import (assert_almost_equal,
5+
assert_array_equal)
6+
from nose.tools import assert_equal
47
from mock import Mock, MagicMock
58
from numpy import array as npa
9+
from test_parrec import EG_PAR, VARY_PAR
10+
from os.path import dirname, join, isfile, basename
11+
from ..tmpdirs import InTemporaryDirectory
612

713
AN_OLD_AFFINE = numpy.array(
814
[[-3.64994708, 0., 1.83564171, 123.66276611],
915
[0., -3.75, 0., 115.617],
1016
[0.86045705, 0., 7.78655376, -27.91161211],
1117
[0., 0., 0., 1.]])
1218

19+
PAR_AFFINE = numpy.array(
20+
[[ -3.64994708, 0. , 1.83564171, 107.63076611],
21+
[ 0. , 3.75, 0. , -118.125 ],
22+
[ 0.86045705, 0. , 7.78655376, -58.25061211],
23+
[ 0. , 0. , 0. , 1. ]])
24+
1325
def test_parrec2nii_sets_qform_with_code2():
26+
"""Unit test that ensures that set_qform() is called on the new header.
27+
"""
1428
parrec2nii = imp.load_source('parrec2nii', 'bin/parrec2nii')
1529
parrec2nii.verbose.switch = False
1630

@@ -43,4 +57,35 @@ def test_parrec2nii_sets_qform_with_code2():
4357

4458
infile = 'nonexistent.PAR'
4559
parrec2nii.proc_file(infile, opts)
46-
nhdr.set_qform.assert_called_with(pr_hdr.get_affine(), code=2)
60+
nhdr.set_qform.assert_called_with(pr_hdr.get_affine(), code=2)
61+
62+
def test_parrec2nii_save_load_qform_code():
63+
"""Tests that after parrec2nii saves file, it has the qform 'code'
64+
set to '2', which means 'aligned', so that other software, e.g. FSL
65+
picks up the qform.
66+
"""
67+
import nibabel
68+
parrec2nii = imp.load_source('parrec2nii', 'bin/parrec2nii')
69+
parrec2nii.verbose.switch = False
70+
71+
opts = Mock()
72+
opts.outdir = None
73+
opts.scaling = 'off'
74+
opts.minmax = [1, 1]
75+
opts.store_header = False
76+
opts.bvs = False
77+
opts.vol_info = False
78+
opts.dwell_time = False
79+
opts.compressed = False
80+
81+
with InTemporaryDirectory() as pth:
82+
opts.outdir = pth
83+
for fname in [EG_PAR, VARY_PAR]:
84+
parrec2nii.proc_file(fname, opts)
85+
outfname = join(pth, basename(fname)).replace('.PAR', '.nii')
86+
assert isfile(outfname)
87+
img = nibabel.load(outfname)
88+
assert_almost_equal(img.get_affine(), PAR_AFFINE, 4)
89+
assert_array_equal(img.header['qform_code'], 2)
90+
assert_array_equal(img.header['sform_code'], 2)
91+

0 commit comments

Comments
 (0)