def main(): """ Entry point for script """ # first figure: betas for each predictor fig, axes = plt.subplots(figsize=(8, 18), nrows=3) image_paths = { "3T": (f"{PATHS['figures_misc']}/figure_3_images/" f"C1051_20161006_childVSall_depth_1.png"), "7T": (f"{PATHS['figures_misc']}/figure_3_images/" f"C1051_20160212_childVSall_depth_1_sim2pt4.png"), "7T_noise": (f"{PATHS['figures_misc']}/figure_3_images/" f"C1051_20160212_childVSall_depth_1_sim2pt4_noise.png"), } for ax, (_, image_path) in zip(axes, image_paths.items()): assert os.path.isfile(image_path) img = imread(image_path) img[np.where(np.sum(img, axis=2) == 0.0)] = 1.0 ax.imshow(img[200:-100, 50:-50, :]) ax.axis("off") savefig(f"{PATHS['figures']}/figure_3ac.png") plt.close(fig)
def make_plots(partition_weights, savepath): # first figure: betas for each predictor fig, axes = plt.subplots(figsize=(10, 6), nrows=2, sharey=True, sharex=True) plot_partition_weights(axes, partition_weights) savefig(savepath) plt.close(fig)
def plot_helper(matrices, aligned_embeddings, plot_params, savepath): fig, axes = plt.subplots(figsize=(18, 12), nrows=2, ncols=3) plot_utils.plot_rdms( axes[0], matrices, cmap=plot_params["cmap"], clim=plot_params["clim"] ) plot_utils.plot_embeddings( axes[1], aligned_embeddings, point_size=250, alpha=0.8, plot_dashed_lines=True ) savefig(savepath) plt.close(fig)
def main(): """ Wrapper for plotting functions and statistical functions """ # global plot params plt.rcParams.update({"font.size": 34}) regressors = build_regressors() fig, axes = plt.subplots(figsize=(12, 3), ncols=4) for regressor, ax in zip(regressors, axes): ax.imshow(regressor, cmap="gray_r", clim=[-0.5, 1]) ax.axis("off") save_path = f"{PATHS['figures']}/figure_7a_rdm_fit_diagram.png" savefig(save_path) plt.close(fig)
def main(): fig, axes = plt.subplots(figsize=(24, 8), ncols=5, nrows=2) path_base = f"{PATHS['figures_misc']}/figure_1_images" # these numbers correspond to the images in the downloadable fLoc dataset stim = [ "word-80", "body-24", "adult-28", "car-64", "corridor-62", "number-59", "limb-49", "child-108", "instrument-50", "house-80", ] # colors in order of categories colors = ( np.array([ [0, 0, 0], # black [252, 164, 0], # dark yellow [248, 51, 60], # dark red [0, 0, 255], # dark blue [10, 255, 0], # dark green [150, 150, 150], # gray [252, 195, 88], # light yellow [244, 110, 116], # light red [0, 0, 150], # light blue [10, 150, 10], # light green ]) / 255.0) image_paths = [f"{path_base}/{x}.jpg" for x in stim] border_width = 30 # px for ax, image_path, border_color in zip(axes.ravel(), image_paths, colors): assert os.path.isfile(image_path) img = imread(image_path) plot_img_with_border(ax, img, border_width, border_color) ax.axis("off") savefig(f"{PATHS['figures']}/figure_1a.png") plt.close(fig)
def main(): """ Entry point for script """ font = {"size": 18} matplotlib.rc("font", **font) save_dir = f"{PATHS['figures']}/figure_10c_metric_means" mkdirquiet(save_dir) # do stats for betas only lateral_betas = load_means( metric="beta", partition="VTC_lateral", abs_string="noabs", r2_control=ARGS.r2_control, ) medial_betas = load_means( metric="beta", partition="VTC_medial", abs_string="noabs", r2_control=ARGS.r2_control, ) data = prepare_dataframe(lateral_betas, medial_betas) fpath = f"{PATHS['r_scripts']}/data/raw_betas.csv" data.to_csv(fpath) subprocess.call( f"Rscript --vanilla {PATHS['r_scripts']}/raw_betas_script.r {fpath}", shell=True) for abs_string in ["abs", "noabs"]: for metric in METRICS + ["beta"]: print(f"Plotting metric: {metric}") fig, axes = plt.subplots(figsize=(16, 4), ncols=3, sharey=True) for ax, partition in zip(axes, PARTITIONS): partition_means = load_means(metric=metric, partition=partition, abs_string=abs_string) plot_means(ax, partition_means, metric=metric) savefig(f"{save_dir}/{metric}_{abs_string}.png") plt.close(fig)
def main(): """ Entry point for script """ font = {"size": 18} matplotlib.rc("font", **font) # create dictionary specifying data and plot options metrics = { "tSNR": { "lateral": load_tsnr(partition="VTC_lateral"), "medial": load_tsnr(partition="VTC_medial"), "ylabel": "tSNR", }, "R2": { "lateral": load_R2(partition="VTC_lateral"), "medial": load_R2(partition="VTC_medial"), "ylabel": r"$R^2$", }, } # make plots fig, axes = plt.subplots(figsize=(12, 4), ncols=2, gridspec_kw={"wspace": 0.4}) for (metric_name, metric_vals), ax in zip(metrics.items(), axes): print(f"==============={metric_name}================") lateral = metric_vals["lateral"] medial = metric_vals["medial"] plot_vals(ax, lateral, medial, ylabel=metric_vals["ylabel"]) report_range(lateral, medial, metric=metric_name) data = prepare_dataframe(lateral, medial) # call the R script fpath = f"{PATHS['r_scripts']}/data/metrics_by_depth.csv" data.to_csv(fpath) subprocess.call( f"Rscript --vanilla {PATHS['r_scripts']}/metrics_by_depth_script.r {fpath}", shell=True, ) savefig(f"{PATHS['figures']}/figure_10ab_tsnr_r2.png") plt.close(fig)
def make_plots(partition_weights, save_dir): """ """ # first figure: betas for each predictor fig, axes = plt.subplots(figsize=(14, 7), ncols=2, sharey=True) plot_partition_weights(axes, partition_weights) savefig(f"{save_dir}/fit_weights.png") plt.close(fig) # second figure: betas for each predictor fig, ax = plt.subplots(figsize=(10, 10)) plot_beta_scatter(ax, partition_weights) ax.spines["top"].set_visible(False) ax.spines["right"].set_visible(False) savefig(f"{save_dir}/partition_comparison.png") plt.close(fig)
def main(): """ Entry point for script """ save_dir = f"{PATHS['figures']}/figure_8af_rdms_by_depth" mkdirquiet(save_dir) # define some colormaps and limits here for each metric (maybe move to constants?) plot_params = { "tstat": {"cmap": plot_utils.blueblackred, "clim": [0.5, 1.5]}, "zscore": {"cmap": plot_utils.blueblackred, "clim": [0.5, 1.5]}, "znorm": {"cmap": plot_utils.blueblackred, "clim": [0.5, 1.5]}, } for metric in plot_params.keys(): print(f"Plotting metric: {metric}") rsms = load_rsms(metric=metric) mean_rdms_by_depth = { partition: np.mean( [1 - split_by_depth(rsm) for rsm in partition_rsms], axis=0 ) for (partition, partition_rsms) in rsms.items() } base = 6 fig, axes = plt.subplots(figsize=(base * 3, base * 2), nrows=2, ncols=3) for partition_idx, partition in enumerate(PARTITIONS): if partition == "hOc1": continue rdm_dict = { f"{partition}_{x}": mean_rdms_by_depth[partition][x] for x in range(3) } plot_utils.plot_rdms( axes[partition_idx, :], rdm_dict, cmap=plot_params[metric]["cmap"], clim=plot_params[metric]["clim"], ) savefig(f"{save_dir}/{metric}.png") plt.close(fig)
def main(): """ Entry point for script """ # define bounding box for right VTC width = 225 y_start = 245 x_start = 50 bbox = [y_start, x_start, width, width] # first figure: betas for each predictor fig, axes = plt.subplots(figsize=(27.7, 8), ncols=5, nrows=2) # redefining contrast order to match figures contrasts = [ "wordVSall", "bodyVSall", "adultVSall", "carVSall", "corridorVSall", "numberVSall", "limbVSall", "childVSall", "instrumentVSall", "corridorVSall", ] for contrast, ax in zip(contrasts, axes.ravel()): image_path = (f"{PATHS['figures_misc']}/figure_4_images/" f"C1051_20160212_{contrast}_depth_1.png") assert os.path.isfile(image_path) img = imread(image_path) img[np.where(np.sum(img, axis=2) == 0.0)] = 1.0 ax.imshow(img[bbox[0]:bbox[0] + bbox[2], bbox[1]:bbox[1] + bbox[3], :]) ax.axis("off") savefig(f"{PATHS['figures']}/figure_4a.png") plt.close(fig)
def main(): """ Entry point for script """ # first figure: betas for each predictor fig, axes = plt.subplots(figsize=(16, 8), ncols=3, nrows=1) for depth, ax in zip(range(1, 4), axes.ravel()): image_path = (f"{PATHS['figures_misc']}/figure_4_images/" f"C1051_20160212_adultVSall_depth_{depth}.png") assert os.path.isfile(image_path) img = imread(image_path) img[np.where(np.sum(img, axis=2) == 0.0)] = 1.0 ax.imshow(img[200:-100, 50:-50, :]) ax.axis("off") savefig(f"{PATHS['figures']}/figure_4b.png") plt.close(fig)
def make_plots(partition_weight_dict, rdm_dict): """ """ fig, axes = plt.subplots(figsize=(20, 20), nrows=3, ncols=3) col_keys = ["high_resolution", "low_resolution", "low_resolution_noise"] for col_idx, col_key in enumerate(col_keys): plot_group_average_rdm(axes[0, col_idx], rdm_dict[col_key]["VTC_lateral"]) plot_group_average_rdm(axes[1, col_idx], rdm_dict[col_key]["VTC_medial"]) plot_beta_scatter(axes[2, col_idx], partition_weight_dict[col_key]) # add a ylabel to the leftmost plot for ax in axes.ravel(): ax.spines["top"].set_visible(False) ax.spines["right"].set_visible(False) savefig(f"{PATHS['figures']}/figure_11_rescomp.png") plt.close(fig)