Skip to content
Snippets Groups Projects
Commit 2fa377ae authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

TEST: More basic tests for x5 scripts

parent 1587e85a
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,8 @@
import numpy as np
import pytest
import fsl.scripts.fsl_apply_x5 as fsl_apply_x5
import fsl.data.image as fslimage
import fsl.utils.image.resample as resample
......@@ -31,6 +33,17 @@ def _random_image(aff, shape=None):
return fslimage.Image(data, xform=aff)
def test_help():
def run(args):
with pytest.raises(SystemExit) as e:
fsl_apply_x5.main(args)
assert e.value.code == 0
run([])
run(['-h'])
def test_linear():
with tempdir.tempdir():
......
......@@ -2,6 +2,9 @@
import os.path as op
import hashlib
import pytest
import numpy as np
......@@ -28,6 +31,20 @@ def random_image():
return fslimage.Image(data, xform=aff)
def test_convert_flirt_help():
def run(args):
with pytest.raises(SystemExit) as e:
fsl_convert_x5.main(args)
assert e.value.code == 0
run([])
run(['-h'])
run(['flirt'])
run(['fnirt'])
run(['flirt', '-h'])
run(['fnirt', '-h'])
def test_convert_flirt():
with tempdir.tempdir():
......@@ -60,6 +77,42 @@ def test_convert_flirt():
assert np.all(np.isclose(gotxform, xform))
def test_convert_flirt_sameformat():
with tempdir.tempdir():
src = random_image()
ref = random_image()
src.save('src')
ref.save('ref')
xform = affine.compose(
np.random.randint(1, 10, 3),
np.random.randint(-100, 100, 3),
(np.random.random(3) - 0.5) * np.pi)
np.savetxt('src2ref.mat', xform)
# test both .mat and .x5
fsl_convert_x5.main('flirt -s src -r ref '
'src2ref.mat src2ref.x5'.split())
# mat -> mat
fsl_convert_x5.main('flirt -s src -r ref '
'src2ref.mat copy.mat'.split())
# x5 -> x5
fsl_convert_x5.main('flirt -s src -r ref '
'src2ref.x5 copy.x5'.split())
with open('src2ref.mat', 'rb') as f: origmat = hashlib.md5(f.read()).digest()
with open('copy.mat', 'rb') as f: copymat = hashlib.md5(f.read()).digest()
with open('src2ref.x5', 'rb') as f: origx5 = hashlib.md5(f.read()).digest()
with open('copy.x5', 'rb') as f: copyx5 = hashlib.md5(f.read()).digest()
assert origmat == copymat
assert origx5 == copyx5
def test_convert_fnirt_deformation_field():
datadir = op.join(op.dirname(__file__), '..',
......@@ -124,3 +177,33 @@ def test_convert_fnirt_coefficient_field():
diff = np.abs(dfnii.data - df.data)
tols = {'rtol' : 1e-5, 'atol' : 1e-5}
assert np.all(np.isclose(dfnii.data, df.data, **tols))
def test_convert_fnirt_sameformat():
datadir = op.join(op.dirname(__file__), '..',
'test_transform', 'testdata', 'nonlinear')
srcfile = op.join(datadir, 'src.nii.gz')
reffile = op.join(datadir, 'ref.nii.gz')
dffile = op.join(datadir, 'displacementfield.nii.gz')
with tempdir.tempdir():
base = list('fnirt -s {} -r {}'.format(srcfile, reffile).split())
# test both .mat and .x5
fsl_convert_x5.main(base + [dffile, 'src2ref.x5'])
# nii -> nii
fsl_convert_x5.main(base + [dffile, 'copy.nii.gz'])
# x5 -> x5
fsl_convert_x5.main(base + [dffile, 'copy.x5'])
with open(dffile, 'rb') as f: origdef = hashlib.md5(f.read()).digest()
with open('copy.nii.gz', 'rb') as f: copydef = hashlib.md5(f.read()).digest()
with open('src2ref.x5', 'rb') as f: origx5 = hashlib.md5(f.read()).digest()
with open('copy.x5', 'rb') as f: copyx5 = hashlib.md5(f.read()).digest()
assert origdef == copydef
assert origx5 == copyx5
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment