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

TEST: unit test for convertwarp, make fslcreatehd test save output to output dir

parent 71c5738b
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,7 @@ import numpy as np
import nibabel as nib
THISDIR = op.dirname(__file__)
THISDIR = op.dirname(op.abspath(__file__))
# 2=char, 4=short, 8=int, 16=float, 64=double
......@@ -251,6 +251,9 @@ def test_existing_file_xml_different_shape():
def main():
outdir = sys.argv[1]
os.chdir(outdir)
test_new_file()
test_existing_file()
test_new_file_xml()
......
#!/usr/bin/env fslpython
import os
import sys
import os.path as op
import subprocess as sp
import numpy as np
import nibabel as nib
from fsl.data.image import Image
from fsl.utils.image.resample import resampleToPixdims
THISDIR = op.dirname(op.abspath(__file__))
SRC = op.join(THISDIR, 'src.nii.gz')
REF = op.join(THISDIR, 'ref.nii.gz')
AFF = op.join(THISDIR, 'src2ref.mat')
def register_test_images():
# use fnirt to register src to ref
# (images are small, won't take long)
sp.call(f'fnirt --in={SRC} --ref={REF} --aff={AFF} '
'--cout=cout --fout=fout'.split())
# check that fnirt set the
# displacement field affine
# correctly
ref = Image(REF)
fout = Image('fout')
assert fout.sameSpace(ref)
def test_convertwarp_sets_affine_correctly():
# We're assuming that register_test_images
# has already been called
# convert coefficient field to displacement field
sp.call(f'convertwarp --ref={REF} --warp1=cout --out=disp'.split())
# check that result is in same space as reference
ref = Image(REF)
disp = Image('disp')
assert disp.sameSpace(ref)
# repeat the above test, but with a
# reference image of different resolution
refrs, refxform = resampleToPixdims(ref, np.array(ref.pixdim) / 2)
refrs = Image(refrs, xformr=refxform)
refrs.save('refrs')
sp.call(f'convertwarp --ref=refrs --warp1=cout --out=disprs'.split())
# check that result is in same
# space as the resampled reference
disp = Image('disprs')
assert disp.sameSpace(refrs)
def main():
outdir = sys.argv[1]
os.chdir(outdir)
register_test_images()
test_convertwarp_sets_affine_correctly()
if __name__ == '__main__':
main()
File added
File added
1.130654884 -0.02090760163 0.05273442572 -0.523881946
0.01777234539 0.9990179929 0.2039857328 5.806280637
-0.003319001082 -0.2740303429 1.071017063 0.4915523243
0 0 0 1
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