def vis_sources_by_pval(padj, all_coord, short_label): ''' 1. visualize the sources (brain regions) based on the FDR-adjusted p values display both the source objects and the brain object ''' # Define the default camera state used for each subplot CAM_STATE = dict( azimuth=0, # azimuth angle elevation=90, # elevation angle scale_factor=180 # distance to the camera ) S_KW = dict(camera_state=CAM_STATE) # Create the scene CBAR_STATE = dict(cbtxtsz=12, txtsz=13., width=.5, cbtxtsh=2., rect=(1., -2., 1., 4.)) sc = SceneObj(bgcolor='black', size=(1600, 1000)) # mask = padj<=0.05 # significant regions with true label data0, max_p, min_p = get_log_pval(padj) b_obj = BrainObj('white', hemisphere='both', translucent=True) b_obj.animate(iterations=10, step=30, interval=1) s_obj = SourceObj( 's1', all_coord, #all_coord, # mask = mask, # mask_color='white', # mask_radius = 15, color=padj * 100, data=data0, text=short_label, text_size=10, text_bold=True, text_color='yellow', symbol='disc', visible=True, radius_min=10, radius_max=40, alpha=0.65) s_obj_1.set_visible_sources('left') s_obj.color_sources(data=data0, cmap='jet', clim=(min_p, max_p)) cb_data = ColorbarObj(s_obj, cblabel='Log FDR-adjusted p value', border=False, **CBAR_STATE) sc.add_to_subplot(b_obj, row=0, col=0, rotate='front') sc.add_to_subplot(s_obj, row=0, col=0) sc.add_to_subplot(cb_data, row=0, col=1, width_max=90) # recording animation and save it sc.record_animation('output/animate_pvalue_projection.gif', n_pic=10) sc.preview()
s_obj_1 = SourceObj('iEEG', xyz1, data=data1, cmap=cmap) s_obj_1.color_sources(data=data1) s_obj_2 = SourceObj('iEEG', xyz2, data=data2, cmap=cmap) s_obj_2.color_sources(data=data2) s_obj_3 = SourceObj('iEEG', xyz3, data=data3, cmap=cmap) s_obj_3.color_sources(data=data3) s_obj_4 = SourceObj('iEEG', xyz4, data=data4, cmap=cmap) s_obj_4.color_sources(data=data4) s_obj_all = s_obj_1 + s_obj_2 + s_obj_3 + s_obj_4 b_obj_proj_left = BrainObj(template_brain, hemisphere='both', translucent=False) b_obj_proj_left.project_sources(s_obj_all, clim=(0, 4), cmap=cmap) sc.add_to_subplot(b_obj_proj_left, row=0, col=0, rotate='right', use_this_cam=True) # b_obj_proj_left = BrainObj(template_brain, hemisphere='left', translucent=False) # b_obj_proj_left.project_sources(s_obj_all, clim=(0, 4), cmap=cmap) # sc.add_to_subplot(b_obj_proj_left, row=0, col=1, rotate='right', use_this_cam=True) # # b_obj_proj_right = BrainObj(template_brain, hemisphere='right', translucent=False) # b_obj_proj_right.project_sources(s_obj_all, clim=(0, 4), cmap=cmap) # sc.add_to_subplot(b_obj_proj_right, row=0, col=2, rotate='right', use_this_cam=True) sc.record_animation(os.path.join(n_f_dir, 'intact_largest.gif'), n_pic=40) sc.preview()
def generate_img(l_file, r_file, activated_areas, brain_name, out_file, views, add_hemispheres, is_estimate=False, cmap='copper', vmin=0., vmax=0.01, save_gif=False): """Generate .png and .gif animation of rotating brains """ sc = SceneObj(size=(1000 * (len(views) // 2 + (1 if add_hemispheres else 0)), 1000 * (len(views) > 1)), bgcolor='black') KW = dict(title_size=14., zoom=2.) # zoom not working CBAR_STATE = dict(cbtxtsz=12, txtsz=10., width=.1, cbtxtsh=3., rect=(-.3, -2., 1., 4.)) # PLOT OBJECTS for i, rot in enumerate(views): # cannot use the same object b_obj = create_brain_obj(l_file, r_file, activated_areas, brain_name, cmap=cmap, vmin=vmin, vmax=vmax) sc.add_to_subplot(b_obj, row=i // 2, col=i % 2, rotate=rot, title=rot, **KW) # Get the colorbar of the brain object and add it to the scene # Identical brain ==> same colorbar if add_hemispheres: # add left brain b_obj = create_brain_obj(l_file, r_file, activated_areas, brain_name, hemisphere='right', cmap=cmap, vmin=vmin, vmax=vmax) sc.add_to_subplot(b_obj, row=i // 2 + 1, col=0, rotate='left', title='right half', **KW) b_obj = create_brain_obj(l_file, r_file, activated_areas, brain_name, hemisphere='left', cmap=cmap, vmin=vmin, vmax=vmax) sc.add_to_subplot(b_obj, row=i // 2 + 1, col=1, rotate='right', title='left half', **KW) if is_estimate: # cmap needs to be set for all objects cb_parr = ColorbarObj(b_obj, cblabel='Data to parcellates', **CBAR_STATE) # not working properly and can't find a way to rotate that bar # sc.add_to_subplot(cb_parr, row=0, col=2, row_span=i//2+1, width_max=200) # gif and png # sc.preview() if save_gif: sc.record_animation(out_file + ('_est' if is_estimate else '') + "_areas.gif") sc.screenshot(saveas=out_file + ('_est' if is_estimate else '') + "_areas.png") return sc.render()