def test_ants_apply_warp_func_mni_symm(): test_name = 'test_ants_apply_warps_func_mni_symm' # get the config and strat for the mock c, strat = configuration_strategy_mock() num_strat = 0 node, out = strat['mean_functional'] mean_functional = node.inputs.file # build the workflow workflow = pe.Workflow(name=test_name) workflow.base_dir = c.workingDirectory workflow.config['execution'] = { 'hash_method': 'timestamp', 'crashdump_dir': os.path.abspath(c.crashLogDirectory) } workflow = ants_apply_warps_func_mni( workflow, 'mean_functional_to_standard_symm', 'mean_functional', 'template_brain_for_func_preproc', num_strat, strat, interpolation_method=c.funcRegANTSinterpolation, distcor=False, map_node=False, inverse=False, symmetry='symmetric', input_image_type=0, num_ants_cores=8) workflow = ants_apply_warps_func_mni( workflow, 'mean_functional_standard_to_original_symm', 'mean_functional_to_standard_symm', 'mean_functional', num_strat, strat, interpolation_method=c.funcRegANTSinterpolation, distcor=False, map_node=False, inverse=True, symmetry='symmetric', input_image_type=0, num_ants_cores=1) retval = workflow.run() mean_functional_after_transform = os.path.join( c.workingDirectory, test_name, 'apply_ants_warp_mean_functional_standard_to_original_symm_inverse_0', 'sub-M10978008_ses-NFB3_task-test_bold_calc_tshift_resample_volreg_calc_tstat_antswarp_antswarp.nii.gz' ) assert (test_utils.pearson_correlation( mean_functional, mean_functional_after_transform) > .93)
def test_smooth(): test_name = 'test_smooth_nodes' c, strat = configuration_strategy_mock(method='FSL') num_strat = 0 # build the workflow workflow = pe.Workflow(name=test_name) workflow.base_dir = c.workingDirectory workflow.config['execution'] = { 'hash_method': 'timestamp', 'crashdump_dir': os.path.abspath(c.crashLogDirectory) } spatial_smooth(workflow, 'mean_functional', 'functional_brain_mask', 'mean_functional_smooth'.format(num_strat), strat, num_strat, c) func_node, func_output = strat['mean_functional'] mask_node, mask_output = strat['functional_brain_mask'] spatial_smooth(workflow, (func_node, func_output), (mask_node, mask_output), 'mean_functional_smooth_nodes'.format(num_strat), strat, num_strat, c) print(workflow.list_node_names()) workflow.run() correlations = [] for fwhm in c.fwhm: out_name1 = os.path.join( c.workingDirectory, test_name, '_fwhm_{0}/mean_functional_smooth_0/'.format(fwhm), 'sub-M10978008_ses-NFB3_task-test_bold_calc_tshift_resample_volreg_calc_tstat_maths.nii.gz' ) out_name2 = os.path.join( c.workingDirectory, test_name, '_fwhm_{0}/mean_functional_smooth_nodes_0/'.format(fwhm), 'sub-M10978008_ses-NFB3_task-test_bold_calc_tshift_resample_volreg_calc_tstat_maths.nii.gz' ) correlations.append( test_utils.pearson_correlation(out_name1, out_name2) > 0.99) assert all(correlations)
def test_output_func_to_standard_FSL_linear(): test_name = 'test_output_func_to_standard_FSL_linear' # get the config and strat for the mock c, strat = configuration_strategy_mock(method='FSL') strat.append_name('anat_mni_flirt_register_0') num_strat = 0 # build the workflow workflow = pe.Workflow(name='test_output_func_to_standard_FSL_linear') workflow.base_dir = c.workingDirectory workflow.config['execution'] = { 'hash_method': 'timestamp', 'crashdump_dir': os.path.abspath(c.crashLogDirectory) } output_func_to_standard(workflow, 'mean_functional', 'template_brain_for_func_preproc', 'mean_functional_to_standard', strat, num_strat, c, input_image_type='func_derivative') out1_name = os.path.join( c.workingDirectory, test_name, 'func_mni_fsl_warp_mean_functional_to_standard_0', 'sub-M10978008_ses-NFB3_task-test_bold_calc_tshift_resample_volreg_calc_tstat_warp.nii.gz' ) func_node, func_out = strat['mean_functional'] output_func_to_standard(workflow, (func_node, func_out), 'template_brain_for_func_preproc', 'mean_functional_to_standard_node', strat, num_strat, c, input_image_type='func_derivative') out2_name = os.path.join( c.workingDirectory, test_name, 'func_mni_fsl_warp_mean_functional_to_standard_node_0', 'sub-M10978008_ses-NFB3_task-test_bold_calc_tshift_resample_volreg_calc_tstat_warp.nii.gz' ) workflow.run() assert (test_utils.pearson_correlation(out1_name, out2_name) > 0.99)
def pearson_correlation(file_out, file_ref=None, name=None, **kwargs): corr = test_utils.pearson_correlation(file_out[0], file_ref[0]) print(f'\nCorrelation = {round(corr,3)}\n') out = {} out["corr"] = f"{corr:.2f}" try: assert corr > .99 out["regr"] = "PASSED" except (AssertionError): out["regr"] = "FAILED" report_filename = Path(f"report_{name}.json") with report_filename.open("w") as f: json.dump(out, f)
def test_ants_apply_warps_func_mni_mapnode(): test_name = 'test_ants_apply_warps_func_mni_mapnode' # get the config and strat for the mock c, strat = configuration_strategy_mock() num_strat = 0 node, out = strat['dr_tempreg_maps_files'] dr_spatmaps = node.inputs.file # build the workflow workflow = pe.Workflow(name='test_ants_apply_warps_func_mni_mapnode') workflow.base_dir = c.workingDirectory workflow.config['execution'] = { 'hash_method': 'timestamp', 'crashdump_dir': os.path.abspath(c.crashLogDirectory) } workflow = ants_apply_warps_func_mni( workflow, 'dr_tempreg_maps_to_standard', 'dr_tempreg_maps_files', 'template_brain_for_func_preproc', num_strat, strat, interpolation_method=c.funcRegANTSinterpolation, distcor=False, map_node=True, inverse=False, input_image_type=0, num_ants_cores=1) workflow = ants_apply_warps_func_mni( workflow, 'dr_tempreg_maps_standard_to_original', 'dr_tempreg_maps_to_standard', 'mean_functional', num_strat, strat, interpolation_method=c.funcRegANTSinterpolation, distcor=False, map_node=True, inverse=True, input_image_type=0, num_ants_cores=8) workflow.run() dr_spatmaps_after_transform = [ os.path.join( c.workingDirectory, test_name, 'apply_ants_warp_dr_tempreg_maps_standard_to_original_mapnode_inverse_0', 'mapflow', '_apply_ants_warp_dr_tempreg_maps_standard_to_original_mapnode_inverse_0{0}' .format(n), 'temp_reg_map_000{0}_antswarp_antswarp.nii.gz'.format(n)) for n in range(0, 10) ] test_results = [ test_utils.pearson_correlation(orig_file, xformed_file) > 0.99 \ for orig_file, xformed_file in zip(dr_spatmaps, dr_spatmaps_after_transform)] assert all(test_results)
def test_smooth_mapnode(): test_name = 'test_smooth_mapnode' c, strat = configuration_strategy_mock(method='FSL') num_strat = 0 # build the workflow workflow = pe.Workflow(name=test_name) workflow.base_dir = c.workingDirectory workflow.config['execution'] = { 'hash_method': 'timestamp', 'crashdump_dir': os.path.abspath(c.crashLogDirectory) } spatial_smooth(workflow, 'dr_tempreg_maps_files', 'functional_brain_mask', 'dr_tempreg_maps_smooth'.format(num_strat), strat, num_strat, c, input_image_type='func_derivative_multi') func_node, func_output = strat['dr_tempreg_maps_files'] mask_node, mask_output = strat['functional_brain_mask'] spatial_smooth(workflow, (func_node, func_output), (mask_node, mask_output), 'dr_tempreg_maps_smooth_nodes'.format(num_strat), strat, num_strat, c, input_image_type='func_derivative_multi') print(workflow.list_node_names()) workflow.run() correlations = [] for fwhm in c.fwhm: dr_spatmaps_after_smooth1 = [ os.path.join( c.workingDirectory, test_name, '_fwhm_{0}/dr_tempreg_maps_smooth_multi_0/mapflow'.format( fwhm), '_dr_tempreg_maps_smooth_multi_0{0}/temp_reg_map_000{0}_maths.nii.gz' .format(n)) for n in range(0, 10) ] dr_spatmaps_after_smooth2 = [ os.path.join( c.workingDirectory, test_name, '_fwhm_{0}/dr_tempreg_maps_smooth_nodes_multi_0/mapflow'. format(fwhm), '_dr_tempreg_maps_smooth_nodes_multi_0{0}/temp_reg_map_000{0}_maths.nii.gz' .format(n)) for n in range(0, 10) ] correlations += [test_utils.pearson_correlation(file1, file2) > 0.99 \ for file1, file2 in zip(dr_spatmaps_after_smooth1, dr_spatmaps_after_smooth2)] assert all(correlations)