contrasts["audio-video"] = contrasts["audio"] - contrasts["video"] contrasts["video-audio"] = -contrasts["audio-video"] contrasts["computation-sentences"] = contrasts["computation"] - contrasts["sentences"] contrasts["reading-visual"] = contrasts["phrasevideo"] - contrasts["damier_H"] # keep only interesting contrasts interesting_contrasts = [ "H-V", "V-H", "computation-sentences", "reading-visual", "video-audio", "audio-video", "left-right", ] contrasts = dict([(key, contrasts[key]) for key in interesting_contrasts]) for index, (contrast_id, contrast_val) in enumerate(contrasts.items()): print(" Contrast % 2i out of %i: %s" % (index + 1, len(contrasts), contrast_id)) # save the z_image image_path = path.join(write_dir, "%s_z_map.nii" % contrast_id) z_map, = fmri_glm.contrast(contrast_val, con_id=contrast_id, output_z=True) save(z_map, image_path) # Create snapshots of the contrasts vmax = max(-z_map.get_data().min(), z_map.get_data().max()) display = plotting.plot_stat_map(z_map, display_mode="z", threshold=3.0, title=contrast_id) display.savefig(path.join(write_dir, "%s_z_map.png" % contrast_id)) plt.show()
mask='compute') fmri_glm.fit(do_scaling=True, model='ar1') # save computed mask mask_path = os.path.join(output_dir, "mask.nii.gz") print("Saving mask image %s" % mask_path) nibabel.save(fmri_glm.mask, mask_path) # compute bg unto which activation will be projected mean_img = mean_img(subject_data.func) print("Computing contrasts ..") for contrast_id, contrast_val in contrasts.items(): print("\tcontrast id: %s" % contrast_id) z_map, t_map, eff_map, var_map = fmri_glm.contrast( contrasts[contrast_id], con_id=contrast_id, output_z=True, output_stat=True, output_effects=True, output_variance=True) # store stat maps to disk for dtype, out_map in zip(['z', 't', 'effects', 'variance'], [z_map, t_map, eff_map, var_map]): map_dir = os.path.join(output_dir, '%s_maps' % dtype) if not os.path.exists(map_dir): os.makedirs(map_dir) map_path = os.path.join(map_dir, '%s.nii.gz' % contrast_id) nibabel.save(out_map, map_path) print("\t\t%s map: %s" % (dtype, map_path)) # plot activation map if contrast_id == 'active-rest': display = plot_stat_map(z_map, bg_img=mean_img, threshold=3.0, display_mode='z', cut_coords=3, black_bg=True,
contrast['DSt_minus_SSt_for_DSp'] = _pad_vector([0, - 1, 0, 1], n_columns) contrast['DSp_minus_SSp_for_DSt'] = _pad_vector([0, 0, - 1, 1], n_columns) contrast['Deactivation'] = _pad_vector([- 1, - 1, - 1, - 1, 4], n_columns) contrast['Effects_of_interest'] = np.eye(n_columns)[:5] return contrast # compute fixed effects of the two runs and compute related images n_columns = np.load(design_files[0])['X'].shape[1] contrasts = make_fiac_contrasts(n_columns) print('Computing contrasts...') mean_img = multi_session_model.means[0] # for display for index, (contrast_id, contrast_val) in enumerate(contrasts.items()): print(' Contrast % 2i out of %i: %s' % ( index + 1, len(contrasts), contrast_id)) z_image_path = path.join(write_dir, '%s_z_map.nii' % contrast_id) z_map, = multi_session_model.contrast( [contrast_val] * 2, con_id=contrast_id, output_z=True) nib.save(z_map, z_image_path) # make a snapshot of the contrast activation if contrast_id == 'Effects_of_interest': vmax = max(- z_map.get_data().min(), z_map.get_data().max()) vmin = - vmax display = plot_stat_map(z_map, bg_img=mean_img, threshold=2.5, title=contrast_id) display.savefig(path.join(write_dir, '%s_z_map.png' % contrast_id)) print('All the results were witten in %s' % write_dir) plt.show()