split_mats[0].append(temp_mat) temp_mat = mat.copy() temp_mat[temp_mat > 0] = 0 split_mats[1].append(temp_mat) for sm, axe, type_title in zip(split_mats, axes, ["Outflow", "Inflow"]): total_flow = np.sum(sm[si]) if (sm[si] == 0).all(): for a in axe: a.axis("off") continue mfig = mlab.figure(size=(1280, 1024)) brain = plot_directed_cnx(sm[si], labels, parc, fig=mfig, alpha_min=mat_min, alpha_max=mat_max, uniform_weight=True, alpha=0.99) mlab.view(*side_views["left_side"]) axe[0].imshow(mlab.screenshot()) axe[0].axis("off") axe[0].set_title("{}\n\nLeft Saggital View".format(type_title)) mlab.view(*side_views["right_side"]) axe[1].imshow(mlab.screenshot()) axe[1].axis("off") axe[1].set_title("Right Saggital View") mlab.view(*side_views["top_side"]) axe[2].imshow(mlab.screenshot()) axe[2].axis("off") axe[2].set_title("Horizontal View")
data = [] for sub_idx, sub in enumerate(subjs): # we actually only need the dPTE to get the number of trials data_temp = load_sparse("{}nc_{}_{}_dPTE_{}.sps".format( proc_dir, sub, cond, band)) for epo_idx in range(data_temp.shape[0]): data.append(data_temp[epo_idx, ]) data = np.array(data) data = data.mean(axis=0) fontsize = 110 top = 100 background = (1, 1, 1) brain_a = plot_directed_cnx(data, regions, parc, top_cnx=top, centre=0.5, background=background) vmin, vmax = get_vminmax(data, top) print("Top {}: {} - {}".format(top, vmin, vmax)) img = make_brain_image(views, brain_a, text="A", text_loc="lup", text_pan=0, fontsize=fontsize) fig1, ax1 = plt.subplots(1, 1, figsize=(38.4, 12.8)) ax1.imshow(img) ax1.axis("off") fig1.suptitle( "{}, {} band, Strongest {} connections, dPTE magnitude range "
rests = [] for sub in subjs: idx = 0 for k in eff_dict.keys(): dPTE = load_sparse("{}nc_{}_{}_dPTE_{}.sps".format( proc_dir, sub, k, band)) dPTEs[idx].append(dPTE.mean(axis=0)) idx += 1 dPTE = load_sparse("{}nc_{}_rest_dPTE_{}.sps".format(proc_dir, sub, band)) rests.append(dPTE.mean(axis=0)) dPTEs = np.mean(dPTEs, axis=1) rest = np.mean(rests, axis=0) # mask by significant edges contrasts = { "audio": dPTEs[0] - rest, "visselten": dPTEs[1] - rest, "visual": dPTEs[2] - rest, "zaehlen": dPTEs[3] - rest, } for k, v in contrasts.items(): temp_dpte = np.zeros(v.shape) for edge in eff_dict[k]["clusters"][1][0]: temp_dpte[edge[0], edge[1]] = v[edge[0], edge[1]] contrasts[k] = temp_dpte brains = [] for k, v in contrasts.items(): brains.append( plot_directed_cnx(v, labels, parc, lup_title=k, top_cnx=top_cnx))
# threshold by statistically significant edges for edge_idx in range(len(edges)): thresh_pte[edges[edge_idx,0],edges[edge_idx,1]] = \ temp_pte[edges[edge_idx,0],edges[edge_idx,1]] # threshold by top x connections top_thresh = np.sort(np.abs(thresh_pte.flatten()))[-top_cnx] thresh_pte[np.abs(thresh_pte) < top_thresh] = 0 dPTEs.append(thresh_pte) con_pte = dPTEs[0] - dPTEs[1] alpha_max = max([np.abs(d).max() for d in dPTEs]) alpha_min = min([np.abs(d[d != 0]).min() for d in dPTEs]) brain0 = plot_directed_cnx(dPTEs[0], labels, parc, figsize=figsize, ldown_title=band, rup_title=conds[0], alpha_min=alpha_min, alpha_max=alpha_max) brain1 = plot_directed_cnx(dPTEs[1], labels, parc, figsize=figsize, ldown_title=band, rup_title=conds[1], alpha_min=alpha_min, alpha_max=alpha_max) brain2 = plot_directed_cnx(con_pte, labels, parc, figsize=figsize,
mask_mat[ROI_idx, :] = np.ones(cnx_params[stat_cond].shape[1]) cnx_params[stat_cond] *= mask_mat all_params = np.abs( np.array([cnx_params[stat_cond] for stat_cond in stat_conds]).flatten()) all_params.sort() alpha_max, alpha_min = all_params[-1:], all_params[-top_cnx].min() alpha_max, alpha_min = 0.015, 0.001 alpha_max, alpha_min = None, None params_brains = {} for stat_cond, cond in zip(stat_conds, conds): params_brains[cond] = plot_directed_cnx(cnx_params[stat_cond], labels, parc, alpha_min=alpha_min, alpha_max=alpha_max, ldown_title="", top_cnx=top_cnx, figsize=figsize, background=background, text_color=text_color) params_brains["task"] = plot_directed_cnx(cnx_params["task"], labels, parc, alpha_min=None, alpha_max=None, ldown_title="", top_cnx=top_cnx, figsize=figsize, background=background, text_color=text_color)
mask_mat[:, ROI_idx] = np.ones(cnx_params[stat_cond].shape[0]) mask_mat[ROI_idx, :] = np.ones(cnx_params[stat_cond].shape[1]) cnx_params[stat_cond] *= mask_mat all_params = np.abs( np.array([cnx_params[stat_cond] for stat_cond in stat_conds]).flatten()) all_params.sort() alpha_max, alpha_min = all_params[-1:], all_params[-top_cnx].min() alpha_max, alpha_min = 0.015, 0.001 alpha_max, alpha_min = None, None params_brains = {} for stat_cond, cond in zip(stat_conds, conds): params_brains[cond] = plot_directed_cnx(cnx_params[stat_cond], labels, parc, alpha_min=alpha_min, alpha_max=alpha_max, ldown_title="", top_cnx=top_cnx, figsize=figsize) if write_images: make_brain_figure(views, params_brains[-1]) params_brains["simple_RT"] = plot_directed_cnx(cnx_params["simple_RT"], labels, parc, alpha_min=None, alpha_max=None, ldown_title="", top_cnx=top_cnx, figsize=figsize) if write_images:
mask_mat[ROI_idx, :] = np.ones(cnx_params[stat_cond].shape[1]) cnx_params[stat_cond] *= mask_mat all_params = np.abs( np.array([cnx_params[stat_cond] for stat_cond in stat_conds]).flatten()) all_params.sort() alpha_max, alpha_min = all_params[-1:], all_params[-top_cnx].min() alpha_max, alpha_min = 0.015, 0.001 alpha_max, alpha_min = None, None params_brains = [] for stat_cond, cond in zip(stat_conds, conds): params_brains.append( plot_directed_cnx(cnx_params[stat_cond], labels, parc, alpha_min=alpha_min, alpha_max=alpha_max, ldown_title=cond, top_cnx=top_cnx)) if write_images: make_brain_figure(views, params_brains[-1]) params_brains.append( plot_directed_cnx(cnx_params["simple_task"], labels, parc, alpha_min=None, alpha_max=None, ldown_title="Simple (task)", top_cnx=top_cnx)) if write_images: