Skip to content

Commit 693c36a

Browse files
Merge pull request #481 from matthew-brett/parrec-codes-to-1
MRG: add qform, sform code 1 for parrec2nii As discussed in github issue 478.
2 parents 42959a3 + 12afd01 commit 693c36a

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

nibabel/parrec2nii_cmd.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ def proc_file(infile, opts):
221221
nhdr = nimg.header
222222
nhdr.set_data_dtype(out_dtype)
223223
nhdr.set_slope_inter(slope, intercept)
224-
nhdr.set_qform(affine, code=2)
224+
nhdr.set_sform(affine, code=1)
225+
nhdr.set_qform(affine, code=1)
225226

226227
if 'parse' in opts.minmax:
227228
# need to get the scaled data

nibabel/tests/test_parrec2nii.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
""" Tests for the parrec2nii exe code
22
"""
3-
import imp
43
from os.path import join, isfile, basename
54

65
import numpy
@@ -9,7 +8,7 @@
98
import nibabel
109
from nibabel import parrec2nii_cmd as parrec2nii
1110

12-
from mock import Mock, MagicMock
11+
from mock import Mock, MagicMock, patch
1312
from nose.tools import assert_true
1413
from numpy.testing import (assert_almost_equal, assert_array_equal)
1514

@@ -30,27 +29,21 @@
3029
[ 0. , 0. , 0. , 1. ]])
3130

3231

33-
def teardown():
34-
# Reload tested module to clear run-time settings in tests
35-
imp.reload(parrec2nii)
36-
37-
38-
def test_parrec2nii_sets_qform_with_code2():
39-
"""Unit test that ensures that set_qform() is called on the new header.
40-
"""
41-
imp.reload(parrec2nii)
32+
@patch('nibabel.parrec2nii_cmd.verbose')
33+
@patch('nibabel.parrec2nii_cmd.io_orientation')
34+
@patch('nibabel.parrec2nii_cmd.nifti1')
35+
@patch('nibabel.parrec2nii_cmd.pr')
36+
def test_parrec2nii_sets_qform_sform_code1(*args):
37+
# Check that set_sform(), set_qform() are called on the new header.
4238
parrec2nii.verbose.switch = False
4339

44-
parrec2nii.io_orientation = Mock()
45-
parrec2nii.io_orientation.return_value = [[0, 1],[1, 1],[2, 1]] # LAS+
40+
parrec2nii.io_orientation.return_value = [[0, 1],[1, 1],[2, 1]] # LAS+
4641

47-
parrec2nii.nifti1 = Mock()
4842
nimg = Mock()
4943
nhdr = MagicMock()
5044
nimg.header = nhdr
5145
parrec2nii.nifti1.Nifti1Image.return_value = nimg
5246

53-
parrec2nii.pr = Mock()
5447
pr_img = Mock()
5548
pr_hdr = Mock()
5649
pr_hdr.get_data_scaling.return_value = (npa([]), npa([]))
@@ -70,15 +63,15 @@ def test_parrec2nii_sets_qform_with_code2():
7063

7164
infile = 'nonexistent.PAR'
7265
parrec2nii.proc_file(infile, opts)
73-
nhdr.set_qform.assert_called_with(pr_hdr.get_affine(), code=2)
66+
nhdr.set_qform.assert_called_with(AN_OLD_AFFINE, code=1)
67+
nhdr.set_sform.assert_called_with(AN_OLD_AFFINE, code=1)
7468

7569

76-
def test_parrec2nii_save_load_qform_code():
77-
"""Tests that after parrec2nii saves file, it has the qform 'code'
78-
set to '2', which means 'aligned', so that other software, e.g. FSL
79-
picks up the qform.
80-
"""
81-
imp.reload(parrec2nii)
70+
@patch('nibabel.parrec2nii_cmd.verbose')
71+
def test_parrec2nii_save_load_qform_code(*args):
72+
# Tests that after parrec2nii saves file, it has the sform and qform 'code'
73+
# set to '1', which means 'scanner', so that other software, e.g. FSL picks
74+
# up the qform.
8275
parrec2nii.verbose.switch = False
8376

8477
opts = Mock()
@@ -98,6 +91,6 @@ def test_parrec2nii_save_load_qform_code():
9891
outfname = join(pth, basename(fname)).replace('.PAR', '.nii')
9992
assert_true(isfile(outfname))
10093
img = nibabel.load(outfname)
101-
assert_almost_equal(img.get_affine(), PAR_AFFINE, 4)
102-
assert_array_equal(img.header['qform_code'], 2)
103-
assert_array_equal(img.header['sform_code'], 2)
94+
assert_almost_equal(img.affine, PAR_AFFINE, 4)
95+
assert_array_equal(img.header['qform_code'], 1)
96+
assert_array_equal(img.header['sform_code'], 1)

0 commit comments

Comments
 (0)