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

RF: re-work applyxfm tests - no longer rely on external data. Use benchmark

data for evaluation
parent 270f7f8e
No related branches found
No related tags found
No related merge requests found
Showing
with 209 additions and 35 deletions
#!/usr/bin/env fslpython
"""
test applyxfm4D matfile directory option with user prefix
"""
from subprocess import run, PIPE
from os.path import join
from tempfile import mkdtemp
import os
import sys
OUTDIR = sys.argv[1]
INDIR = sys.argv[2]
FSLDIR = os.environ.get('FSLDIR')
FSLBIN = join(FSLDIR, 'bin')
print(INDIR)
def test_applyxfm4D_userprefix():
# use trilinear interp for speed
cmd = [
join(FSLBIN, 'applyxfm4D'),
join(INDIR, 'unit_tests', 'applyxfm4D', 'applyxfm4D_in.nii.gz'),
join(INDIR, 'unit_tests', 'applyxfm4D', 'applyxfm4D_ref.nii.gz'),
join(OUTDIR, 'applyxfm4D_out.nii.gz'),
join(INDIR, 'unit_tests', 'applyxfm4D', 'matfiles_user_prefix'),
'-interp',
'trilinear',
'-userprefix',
'myprefix_'
]
run_result = run(cmd, stdout=PIPE, check=True)
stdout_string = run_result.stdout.decode('utf-8')
# check that the files were written to disk
# the brain extracted input should exist
assert os.path.isfile(join(OUTDIR, 'applyxfm4D_out.nii.gz')) == True
test_applyxfm4D_userprefix()
#!/usr/bin/env fslpython
"""
test applyxfm4D correct failure
"""
import sys
from subprocess import run, CalledProcessError
from os.path import join
OUTDIR = sys.argv[1]
cmd = [
'applyxfm4D',
'applyxfm4D_in.nii.gz',
'applyxfm4D_ref.nii.gz',
join(OUTDIR, 'applyxfm4D_out.nii.gz'),
'applyxfm4D_mat.mat']
try:
run(cmd, check=True)
assert False
except CalledProcessError as e:
print("test_applyxfm4D correctly failed. This is good!")
assert e.returncode != 0
#!/usr/bin/env fslpython
"""
test applyxfm4D matfile directory option with 4 digit numbers in filenames
"""
import sys
from subprocess import run
from os.path import join
OUTDIR = sys.argv[1]
cmd = [
'applyxfm4D',
'applyxfm4D_in.nii.gz',
'applyxfm4D_ref.nii.gz',
join(OUTDIR, 'applyxfm4D_out.nii.gz'),
'matfiles_four_digit',
'-interp',
'trilinear',
'-fourdigit']
run(cmd, check=True)
#!/usr/bin/env fslpython
"""
test applyxfm4D nn interp
"""
import sys
from subprocess import run
from os.path import join
OUTDIR = sys.argv[1]
cmd = [
'applyxfm4D',
'applyxfm4D_in.nii.gz',
'applyxfm4D_ref.nii.gz',
join(OUTDIR, 'applyxfm4D_out.nii.gz'),
'applyxfm4D_mat.mat',
'-singlematrix',
'-interp',
'nn']
run(cmd, check=True)
#!/usr/bin/env fslpython
"""
test applyxfm4D sinc interp
"""
import sys
from subprocess import run
from os.path import join
OUTDIR = sys.argv[1]
cmd = [
'applyxfm4D',
'applyxfm4D_in.nii.gz',
'applyxfm4D_ref.nii.gz',
join(OUTDIR, 'applyxfm4D_out.nii.gz'),
'applyxfm4D_mat.mat',
'-singlematrix',
'-interp',
'sinc']
run(cmd, check=True)
#!/usr/bin/env fslpython
"""
test applyxfm4D single matrix option
"""
import sys
from subprocess import run
from os.path import join
OUTDIR = sys.argv[1]
cmd = [
'applyxfm4D',
'applyxfm4D_in.nii.gz',
'applyxfm4D_ref.nii.gz',
join(OUTDIR, 'applyxfm4D_out.nii.gz'),
'applyxfm4D_mat.mat',
'-singlematrix',
'-interp',
'nn']
run(cmd, check=True)
#!/usr/bin/env fslpython
"""
test applyxfm4D spline interp
"""
import sys
from subprocess import run
from os.path import join
OUTDIR = sys.argv[1]
cmd = [
'applyxfm4D',
'applyxfm4D_in.nii.gz',
'applyxfm4D_ref.nii.gz',
join(OUTDIR, 'applyxfm4D_out.nii.gz'),
'applyxfm4D_mat.mat',
'-singlematrix',
'-interp',
'spline']
run(cmd, check=True)
#!/usr/bin/env fslpython
"""
test applyxfm4D matfile directory option
"""
import sys
from subprocess import run
from os.path import join
OUTDIR = sys.argv[1]
cmd = [
'applyxfm4D',
'applyxfm4D_in.nii.gz',
'applyxfm4D_ref.nii.gz',
join(OUTDIR, 'applyxfm4D_out.nii.gz'),
'matfiles_five_digit',
'-interp',
'trilinear']
run_result = run(cmd, check=True)
#!/usr/bin/env fslpython
"""
test applyxfm4D trilinear interp
"""
import sys
from subprocess import run
from os.path import join
OUTDIR = sys.argv[1]
cmd = [
'applyxfm4D',
'applyxfm4D_in.nii.gz',
'applyxfm4D_ref.nii.gz',
join(OUTDIR, 'applyxfm4D_out.nii.gz'),
'applyxfm4D_mat.mat',
'-singlematrix',
'-interp',
'trilinear']
run(cmd, check=True)
#!/usr/bin/env fslpython
"""
test applyxfm4D matfile directory option with user prefix
"""
import sys
from subprocess import run
from os.path import join
OUTDIR = sys.argv[1]
cmd = [
'applyxfm4D',
'applyxfm4D_in.nii.gz',
'applyxfm4D_ref.nii.gz',
join(OUTDIR, 'applyxfm4D_out.nii.gz'),
'matfiles_user_prefix',
'-interp',
'trilinear',
'-userprefix',
'myprefix_']
run_result = run(cmd, check=True)
1.0000000000 0.0000000000 0.0000000000 -0.3750000000
0.0000000000 1.0000000000 0.0000000000 0.8958333450
0.0000000000 0.0000000000 1.0000000000 2.0000000000
0.0000000000 0.0000000000 0.0000000000 1.0000000000
1.0000000000 0.0000000000 0.0000000000 -0.3750000000
0.0000000000 1.0000000000 0.0000000000 0.8958333450
0.0000000000 0.0000000000 1.0000000000 2.0000000000
0.0000000000 0.0000000000 0.0000000000 1.0000000000
1.0000000000 0.0000000000 0.0000000000 -0.3750000000
0.0000000000 1.0000000000 0.0000000000 0.8958333450
0.0000000000 0.0000000000 1.0000000000 2.0000000000
0.0000000000 0.0000000000 0.0000000000 1.0000000000
1.0000000000 0.0000000000 0.0000000000 -0.3750000000
0.0000000000 1.0000000000 0.0000000000 0.8958333450
0.0000000000 0.0000000000 1.0000000000 2.0000000000
0.0000000000 0.0000000000 0.0000000000 1.0000000000
1.0000000000 0.0000000000 0.0000000000 -0.3750000000
0.0000000000 1.0000000000 0.0000000000 0.8958333450
0.0000000000 0.0000000000 1.0000000000 2.0000000000
0.0000000000 0.0000000000 0.0000000000 1.0000000000
1.0000000000 0.0000000000 0.0000000000 -0.3750000000
0.0000000000 1.0000000000 0.0000000000 0.8958333450
0.0000000000 0.0000000000 1.0000000000 2.0000000000
0.0000000000 0.0000000000 0.0000000000 1.0000000000
1.0000000000 0.0000000000 0.0000000000 -0.3750000000
0.0000000000 1.0000000000 0.0000000000 0.8958333450
0.0000000000 0.0000000000 1.0000000000 2.0000000000
0.0000000000 0.0000000000 0.0000000000 1.0000000000
1.0000000000 0.0000000000 0.0000000000 -0.3750000000
0.0000000000 1.0000000000 0.0000000000 0.8958333450
0.0000000000 0.0000000000 1.0000000000 2.0000000000
0.0000000000 0.0000000000 0.0000000000 1.0000000000
1.0000000000 0.0000000000 0.0000000000 -0.3750000000
0.0000000000 1.0000000000 0.0000000000 0.8958333450
0.0000000000 0.0000000000 1.0000000000 2.0000000000
0.0000000000 0.0000000000 0.0000000000 1.0000000000
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