def test_convertxfm(): filelist, outdir, cwd = create_files_in_directory() cvt = fsl.ConvertXFM() # make sure command gets called yield assert_equal, cvt.cmd, "convert_xfm" # test raising error with mandatory args absent yield assert_raises, ValueError, cvt.run # .inputs based parameters setting cvt.inputs.in_file = filelist[0] cvt.inputs.invert_xfm = True cvt.inputs.out_file = "foo.mat" yield assert_equal, cvt.cmdline, 'convert_xfm -omat foo.mat -inverse %s' % filelist[ 0] # constructor based parameter setting cvt2 = fsl.ConvertXFM(in_file=filelist[0], in_file2=filelist[1], concat_xfm=True, out_file="bar.mat") yield assert_equal, cvt2.cmdline, \ "convert_xfm -omat bar.mat -concat %s %s" % (filelist[1], filelist[0]) clean_directory(outdir, cwd)
def test_convertxfm(create_files_in_directory_plus_output_type): filelist, outdir, _ = create_files_in_directory_plus_output_type cvt = fsl.ConvertXFM() # make sure command gets called assert cvt.cmd == "convert_xfm" # test raising error with mandatory args absent with pytest.raises(ValueError): cvt.run() # .inputs based parameters setting cvt.inputs.in_file = filelist[0] cvt.inputs.invert_xfm = True cvt.inputs.out_file = "foo.mat" assert cvt.cmdline == "convert_xfm -omat foo.mat -inverse %s" % filelist[0] # constructor based parameter setting cvt2 = fsl.ConvertXFM( in_file=filelist[0], in_file2=filelist[1], concat_xfm=True, out_file="bar.mat" ) assert cvt2.cmdline == "convert_xfm -omat bar.mat -concat %s %s" % ( filelist[1], filelist[0], )
def acpc_alignment(config=None, acpc_target='whole-head', mask=False, wf_name='acpc_align'): preproc = pe.Workflow(name=wf_name) inputnode = pe.Node(util.IdentityInterface(fields=[ 'anat_leaf', 'anat_brain', 'brain_mask', 'template_brain_only_for_anat', 'template_skull_for_anat', 'template_brain_for_acpc', 'template_head_for_acpc' ]), name='inputspec') output_node = pe.Node(util.IdentityInterface( fields=['acpc_aligned_head', 'acpc_brain_mask']), name='outputspec') robust_fov = pe.Node(interface=fsl_utils.RobustFOV(), name='anat_acpc_1_robustfov') robust_fov.inputs.brainsize = config.anatomical_preproc['acpc_alignment'][ 'brain_size'] robust_fov.inputs.out_transform = 'fov_xfm.mat' # align head-to-head to get acpc.mat (for human) if acpc_target == 'whole-head': preproc.connect(inputnode, 'anat_leaf', robust_fov, 'in_file') # align brain-to-brain to get acpc.mat (for monkey) if acpc_target == 'brain': preproc.connect(inputnode, 'anat_brain', robust_fov, 'in_file') convert_fov_xfm = pe.Node(interface=fsl_utils.ConvertXFM(), name='anat_acpc_2_fov_convertxfm') convert_fov_xfm.inputs.invert_xfm = True preproc.connect(robust_fov, 'out_transform', convert_fov_xfm, 'in_file') align = pe.Node(interface=fsl.FLIRT(), name='anat_acpc_3_flirt') align.inputs.interp = 'spline' align.inputs.searchr_x = [30, 30] align.inputs.searchr_y = [30, 30] align.inputs.searchr_z = [30, 30] preproc.connect(robust_fov, 'out_roi', align, 'in_file') # align head-to-head to get acpc.mat (for human) if acpc_target == 'whole-head': preproc.connect(inputnode, 'template_head_for_acpc', align, 'reference') # align brain-to-brain to get acpc.mat (for monkey) if acpc_target == 'brain': preproc.connect(inputnode, 'template_brain_for_acpc', align, 'reference') concat_xfm = pe.Node(interface=fsl_utils.ConvertXFM(), name='anat_acpc_4_concatxfm') concat_xfm.inputs.concat_xfm = True preproc.connect(convert_fov_xfm, 'out_file', concat_xfm, 'in_file') preproc.connect(align, 'out_matrix_file', concat_xfm, 'in_file2') aff_to_rig_imports = ['import os', 'from numpy import *'] aff_to_rig = pe.Node(util.Function(input_names=['in_xfm', 'out_name'], output_names=['out_mat'], function=fsl_aff_to_rigid, imports=aff_to_rig_imports), name='anat_acpc_5_aff2rigid') aff_to_rig.inputs.out_name = 'acpc.mat' preproc.connect(concat_xfm, 'out_file', aff_to_rig, 'in_xfm') apply_xfm = pe.Node(interface=fsl.ApplyWarp(), name='anat_acpc_6_applywarp') apply_xfm.inputs.interp = 'spline' apply_xfm.inputs.relwarp = True preproc.connect(inputnode, 'anat_leaf', apply_xfm, 'in_file') preproc.connect(inputnode, 'template_head_for_acpc', apply_xfm, 'ref_file') preproc.connect(aff_to_rig, 'out_mat', apply_xfm, 'premat') preproc.connect(apply_xfm, 'out_file', output_node, 'acpc_aligned_head') if mask: apply_xfm_mask = pe.Node(interface=fsl.ApplyWarp(), name='anat_mask_acpc_7_applywarp') apply_xfm_mask.inputs.interp = 'nn' apply_xfm_mask.inputs.relwarp = True preproc.connect(inputnode, 'brain_mask', apply_xfm_mask, 'in_file') preproc.connect(inputnode, 'template_brain_for_acpc', apply_xfm_mask, 'ref_file') preproc.connect(aff_to_rig, 'out_mat', apply_xfm_mask, 'premat') preproc.connect(apply_xfm_mask, 'out_file', output_node, 'acpc_brain_mask') return preproc