Skip to content
Snippets Groups Projects
Commit d2092ea1 authored by Taylor Hanayik's avatar Taylor Hanayik
Browse files

Merge branch 'bet-units' into 'master'

add initial round of bed unit tests

See merge request !3
parents 82ec8617 052b7203
No related branches found
No related tags found
1 merge request!3add initial round of bed unit tests
Showing
with 575 additions and 0 deletions
File added
#!/usr/bin/env fslpython
"""
test bet with 4D input file
"""
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')
def test_bet_4d():
cmd = [
join(FSLBIN, 'bet'),
'4D_MNI152_T1_2mm.nii.gz',
join(OUTDIR, 'bet_test.nii.gz'),
'-F'
]
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, 'bet_test.nii.gz')) == True
# the 4D option should create a mask, so make sure the file exists
assert os.path.isfile(join(OUTDIR, 'bet_test_mask.nii.gz')) == True
test_bet_4d()
#!/usr/bin/env fslpython
"""
test bet with -A option for bet2 and betsurf
"""
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')
def test_bet_A():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz'),
'-A'
]
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, 'bet_test.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_inskull_mask.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_inskull_mesh.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_inskull_mesh.vtk')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_mesh.vtk')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_outskin_mask.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_outskin_mesh.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_outskin_mesh.vtk')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_outskull_mask.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_outskull_mesh.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_outskull_mesh.vtk')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_skull_mask.nii.gz')) == True
test_bet_A()
File added
File added
#!/usr/bin/env fslpython
"""
test bet with -A2 option for bet2 and betsurf with a T2 added
"""
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')
def test_bet_A2():
cmd = [
join(FSLBIN, 'bet'),
'T1.nii.gz',
join(OUTDIR, 'bet_test.nii.gz'),
'-A2',
'T2.nii.gz'
]
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, 'bet_test.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_inskull_mask.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_inskull_mesh.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_inskull_mesh.vtk')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_mesh.vtk')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_outskin_mask.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_outskin_mesh.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_outskin_mesh.vtk')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_outskull_mask.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_outskull_mesh.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_outskull_mesh.vtk')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_skull_mask.nii.gz')) == True
test_bet_A2()
#!/usr/bin/env fslpython
"""
test bet with -B for bias field and neck clean
"""
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')
def test_bet_bias_and_neck_clean():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz'),
'-B'
]
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, 'bet_test.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_mask.nii.gz')) == True
test_bet_bias_and_neck_clean()
#!/usr/bin/env fslpython
"""
test bet with custom cog value
"""
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')
def test_bet_custom_cog():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz'),
'-c',
'90',
'113',
'112'
]
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, 'bet_test.nii.gz')) == True
test_bet_custom_cog()
#!/usr/bin/env fslpython
"""
test bet with custom -f value
"""
from subprocess import run, PIPE, CalledProcessError
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')
def test_bet_custom_f():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz'),
'-f',
'0.3'
]
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, 'bet_test.nii.gz')) == True
def test_bet_negative_f():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz'),
'-f',
'-0.3'
]
try:
run_result = run(cmd, stdout=PIPE, check=True)
stdout_string = run_result.stdout.decode('utf-8')
assert False
except CalledProcessError as e:
# a negative f value is BAD. error code should be > 0 since bet2 should fail.
print("test_bet_negative_f correctly failed. This is good! negative -f values are not to be used with bet")
assert e.returncode != 0
print("running test_bet_custom_f()")
test_bet_custom_f()
print("running test_bet_negative_f()")
test_bet_negative_f()
#!/usr/bin/env fslpython
"""
test bet with custom radius option
"""
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')
def test_bet_custom_radius():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz'),
'-r',
'50'
]
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, 'bet_test.nii.gz')) == True
test_bet_custom_radius()
#!/usr/bin/env fslpython
"""
test bet with -S for eye cleanup
"""
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')
def test_bet_eye_clean():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz'),
'-S'
]
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, 'bet_test.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_mask.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_skull.nii.gz')) == True
test_bet_eye_clean()
#!/usr/bin/env fslpython
"""
test bet with the -n and -m option combo
"""
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')
def test_bet_mask_only():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz'),
'-n',
'-m'
]
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 mask file should be made in this case
assert os.path.isfile(join(OUTDIR, 'bet_test_mask.nii.gz')) == True
# however, the brain extracted input should NOT exist (we only requested the mask)
assert os.path.isfile(join(OUTDIR, 'bet_test.nii.gz')) == False
test_bet_mask_only()
#!/usr/bin/env fslpython
"""
test bet with negative gradient option
"""
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')
def test_bet_negative_gradient():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz'),
'-g',
'-0.5'
]
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, 'bet_test.nii.gz')) == True
test_bet_negative_gradient()
#!/usr/bin/env fslpython
"""
test bet with -n option (will produce no images)
"""
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')
def test_bet_no_images():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz'),
'-n'
]
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 NOT exist
assert os.path.isfile(join(OUTDIR, 'bet_test.nii.gz')) == False
test_bet_no_images()
#!/usr/bin/env fslpython
"""
test bet with poitive gradient option
"""
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')
def test_bet_positive_gradient():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz'),
'-g',
'0.5'
]
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, 'bet_test.nii.gz')) == True
test_bet_positive_gradient()
#!/usr/bin/env fslpython
"""
test bet with -R robust option
"""
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')
def test_bet_robust():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz'),
'-R'
]
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, 'bet_test.nii.gz')) == True
test_bet_robust()
#!/usr/bin/env fslpython
"""
test bet with no options
"""
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')
def test_bet_simple():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz')
]
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, 'bet_test.nii.gz')) == True
test_bet_simple()
#!/usr/bin/env fslpython
"""
test bet with the -e option to produce the surface mesh
"""
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')
def test_bet_surface_mesh():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz'),
'-e'
]
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, 'bet_test.nii.gz')) == True
assert os.path.isfile(join(OUTDIR, 'bet_test_mesh.vtk')) == True
test_bet_surface_mesh()
#!/usr/bin/env fslpython
"""
test bet with the -m combo to produce a mask file and the betted file
"""
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')
def test_bet_with_mask():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz'),
'-m'
]
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 mask file should exist
assert os.path.isfile(join(OUTDIR, 'bet_test_mask.nii.gz')) == True
# the brain extracted input should exist
assert os.path.isfile(join(OUTDIR, 'bet_test.nii.gz')) == True
test_bet_with_mask()
#!/usr/bin/env fslpython
"""
test bet with the -m -s combo to produce a mask file and the betted file, and the skull file
"""
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')
def test_bet_with_mask_and_skull():
cmd = [
join(FSLBIN, 'bet'),
join(FSLDIR, 'data', 'standard', 'MNI152_T1_1mm.nii.gz'),
join(OUTDIR, 'bet_test.nii.gz'),
'-m',
'-s'
]
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 mask file should exist
assert os.path.isfile(join(OUTDIR, 'bet_test_mask.nii.gz')) == True
# the brain extracted input should exist
assert os.path.isfile(join(OUTDIR, 'bet_test.nii.gz')) == True
# the skull image should exist
assert os.path.isfile(join(OUTDIR, 'bet_test_skull.nii.gz')) == True
test_bet_with_mask_and_skull()
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