Skip to content

Commit 7a857ce

Browse files
committed
RF: refactor parrec2nii test to use test params
Use EXAMPLE_IMAGES in test_parrec.py to test parrec2nii conversion.
1 parent 1995aa3 commit 7a857ce

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

nibabel/tests/test_scripts.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424

2525
from .scriptrunner import ScriptRunner
2626
from .nibabel_data import needs_nibabel_data
27-
from .test_parrec import DTI_PAR_BVECS, DTI_PAR_BVALS
27+
from ..testing import assert_dt_equal
28+
from .test_parrec import (DTI_PAR_BVECS, DTI_PAR_BVALS,
29+
EXAMPLE_IMAGES as PARREC_EXAMPLES)
2830
from .test_parrec_data import BALLS, AFF_OFF
31+
from .test_helpers import assert_data_similar
2932

3033

3134
def _proc_stdout(stdout):
@@ -89,19 +92,18 @@ def test_parrec2nii():
8992
cmd = ['parrec2nii', '--help']
9093
code, stdout, stderr = run_command(cmd)
9194
assert_true(stdout.startswith('Usage'))
92-
in_fname = pjoin(DATA_PATH, 'phantom_EPI_asc_CLEAR_2_1.PAR')
93-
out_froot = 'phantom_EPI_asc_CLEAR_2_1.nii'
9495
with InTemporaryDirectory():
95-
run_command(['parrec2nii', in_fname])
96-
img = load(out_froot)
97-
assert_equal(img.shape, (64, 64, 9, 3))
98-
assert_equal(img.get_data_dtype(), np.dtype(np.uint16))
99-
# Check against values from Philips converted nifti image
100-
data = img.get_data()
101-
assert_true(np.allclose(
102-
(data.min(), data.max(), data.mean()),
103-
(0.0, 2299.4110643863678, 194.95876256117265)))
104-
assert_almost_equal(vox_size(img.get_affine()), (3.75, 3.75, 8))
96+
for eg_dict in PARREC_EXAMPLES:
97+
fname = eg_dict['fname']
98+
run_command(['parrec2nii', fname])
99+
out_froot = splitext(basename(fname))[0] + '.nii'
100+
img = load(out_froot)
101+
assert_equal(img.shape, eg_dict['shape'])
102+
assert_dt_equal(img.get_data_dtype(), eg_dict['dtype'])
103+
# Check against values from Philips converted nifti image
104+
data = img.get_data()
105+
assert_data_similar(data, eg_dict)
106+
assert_almost_equal(img.header.get_zooms(), eg_dict['zooms'])
105107

106108

107109
@script_test

0 commit comments

Comments
 (0)