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 " "{:.4f}-{:.4f}".format(cond_keys[cond], band_info[band]["name"], top, vmax, vmin), fontsize=48) plt.tight_layout() fig1.canvas.draw() mat1 = np.frombuffer(fig1.canvas.tostring_rgb(), dtype=np.uint8) mat1 = mat1.reshape(fig1.canvas.get_width_height()[::-1] + (3, ))
axes[pan].axis("off") for pad in pads: axes[pad].axis("off") params = aic_comps["sig_params"].copy() simp_params = np.expand_dims(aic_comps["simp_params"].copy()[:, 1], 1) params = np.concatenate((params, simp_params), axis=1) params_n = param_norm(params) vmin = -abs(params).max() vmax = abs(params).max() param_n = params_n[:, -1] rgba = params_to_rgba(param_n) brains.append( plot_rgba(rgba, labels, parc, figsize=figsize, background=background)) img = make_brain_image(views, brains[-1], text="A", text_loc="lup", text_pan=0) ax = axes["A"] ax.imshow(img) # changes from rest for each individual task # audio param_n = params_n[:, 0] rgba = params_to_rgba(param_n) brains.append( plot_rgba(rgba, labels, parc, figsize=figsize, background=background)) img = make_brain_image(views, brains[-1], text="B", text_loc="lup", text_pan=0) ax = axes["B"] ax.imshow(img) # visual param_n = params_n[:, 1]
if pad: mos_str += pad + "\n" fig, axes = plt.subplot_mosaic(mos_str, figsize=(64.8, 108)) for desc, pan in zip(descs, pans): axes[pan].set_title("{}".format(desc), fontsize=fontsize) axes[pan].axis("off") for pad in pads: axes[pad].axis("off") legend_props = [["Audio", "r"], ["Visual", "g"], ["Aud. Distr.", "b"]] for pan, desc, cond in zip(pans, descs, conds): if cond == "rainbow": img = make_brain_image(views, params_brains[cond], text=pan, text_loc="lup", text_pan=0, legend=legend_props, legend_pan=2) else: img = make_brain_image(views, params_brains[cond], text=pan, text_loc="lup", text_pan=0) axes[pan].imshow(img) plt.suptitle("Estimated connectivity change from resting state", fontsize=fontsize) plt.savefig("../images/cnx_byresp_figure.png")
alpha_max=None, ldown_title="", top_cnx=top_cnx, figsize=figsize, background=background, text_color=text_color) with open("{}{}/cnx_params_{}.pickle".format(lmm_dir, band, band), "wb") as f: pickle.dump(cnx_params, f) ###### make figure for manuscripts # rest cnx by brainview brain_img = make_brain_image(views, params_brains["rest"], text="", text_loc="lup", text_pan=0, orient="horizontal") # cnx conditions by matrix # rearrange by region, hemisphere, ant/pos inds = [] reg_arranged = [] hemi_arranged = [] for lobe, lobe_regs in region_dict.items(): for hemi in ["lh", "rh"]: these_label_names = ["{}-{}".format(lr, hemi) for lr in lobe_regs] these_labels = [x for x in labels if x.name in these_label_names] # order based on ant-pos location these_ypos = np.array([x.pos[:, 1].mean() for x in these_labels])
stc = mne.read_source_estimate("{}/stcs/{}".format(proc_dir, filename)) stc = morphs[trial_info[0]].apply(stc) for reg_idx, reg in enumerate(regions): temp_data = mne.extract_label_time_course(stc, reg, fs_src, mode="mean") data[reg_idx].append(temp_data.mean()) data = np.array(data) data = data.mean(axis=1) np.save("{}rest_dics.npy".format(proc_dir), data) else: data = np.load("{}rest_dics.npy".format(proc_dir)) data_norm = (data) / (data.max()) rgbs = cm.get_cmap(cmap)(data_norm) rgbs[:, -1] = data_norm brain = plot_rgba(rgbs, regions, parc, background=(1, 1, 1)) img = make_brain_image(views, brain, cbar=cmap, vmin=0, vmax=data.max(), orient="horizontal", cbar_label="DICS power (NAI normalised)") fig, ax = plt.subplots(1, 1, figsize=(38.4, 12.8)) ax.imshow(img) ax.axis("off") plt.tight_layout() plt.savefig("../images/dics_rest.png")