def plot_all_waterfalls(df, savepath, scale='blank_subtracted_NLL'): areas, cres = dataset_params() for area in areas: for cre in cres: session_IDs = get_sessions(df, area, cre) if len(session_IDs) > 0: #sort by direction using event magnitude direction_order = get_cell_order_direction_sorted( df, area, cre, savepath) #display response significance resp, blank, p_all = pool_sessions(session_IDs, area + '_' + cre, savepath, scale=scale) resp = center_direction_zero(resp) condition_responses = resp[p_all < SIG_THRESH] dirXcon_mat = concatenate_contrasts(condition_responses) dirXcon_mat = dirXcon_mat[direction_order] dirXcon_mat = move_all_negative_to_bottom(dirXcon_mat) plot_full_waterfall( dirXcon_mat, cre, shorthand(area) + '_' + shorthand(cre) + '_full', scale, savepath)
def get_cell_order_direction_sorted(df, area, cre, savepath): session_IDs = get_sessions(df, area, cre) resp, blank, p_all = pool_sessions(session_IDs, area + '_' + cre, savepath, scale='event') resp = center_direction_zero(resp) condition_responses = resp[p_all < SIG_THRESH] peak_dir, peak_con = get_peak_conditions(condition_responses) direction_mat = select_peak_contrast(condition_responses, peak_con) direction_order = sort_by_weighted_peak_direction(direction_mat) return direction_order
def plot_DSI_distribution(df, savepath, curve='cdf'): areas, cres = dataset_params() cre_colors = get_cre_colors() area = 'VISp' pooled_DSI = [] colors = [] alphas = [] cre_labels = [] for cre in cres: session_IDs = get_sessions(df, area, cre) resp, blank, p_all = pool_sessions(session_IDs, area + '_' + cre, savepath, scale='event') dsi = calc_DSI(resp[p_all < SIG_THRESH]) pooled_DSI.append(dsi) colors.append(cre_colors[cre]) alphas.append(1.0) cre_labels.append(shorthand(cre)) xticks = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0] plot_cdf(metric=pooled_DSI, metric_labels=cre_labels, colors=colors, alphas=alphas, hist_range=(0.0, 1.0), hist_bins=200, x_label='DSI', x_ticks=xticks, x_tick_labels=[str(x) for x in xticks], save_name='V1_DSI_' + curve, savepath=savepath, do_legend=False)
def plot_direction_vector_sum_by_contrast(df, savepath): areas, cres = dataset_params() directions, contrasts = grating_params() for area in areas: for cre in cres: session_IDs = get_sessions(df, area, cre) if len(session_IDs) > 0: resp, blank, p_all = pool_sessions(session_IDs, area + '_' + cre, savepath, scale='event') sig_resp = resp[p_all < SIG_THRESH] pref_dir_mat = calc_pref_direction_dist_by_contrast(sig_resp) pref_dir_mat = pref_dir_mat / np.sum( pref_dir_mat, axis=0, keepdims=True) resultant_mag = [] resultant_theta = [] for i_con, contrast in enumerate(contrasts): mag, theta = calc_vector_sum(pref_dir_mat[:, i_con]) resultant_mag.append(mag) resultant_theta.append(theta) #bootstrap CI for distribution at 5% contrast num_cells = len(sig_resp) uniform_LB, uniform_UB = uniform_direction_vector_sum( num_cells) radial_direction_figure( np.zeros((len(directions), )), np.zeros( (len(directions), )), resultant_mag, resultant_theta, uniform_LB, uniform_UB, cre, num_cells, shorthand(area) + '_' + shorthand(cre) + '_combined', savepath)
def plot_contrast_CoM(df, savepath, curve='cdf'): areas, cres = dataset_params() cre_colors = get_cre_colors() area = 'VISp' pooled_resp = [] colors = [] alphas = [] cre_labels = [] for cre in cres: session_IDs = get_sessions(df, area, cre) resp, blank, p_all = pool_sessions(session_IDs, area + '_' + cre, savepath, scale='event') pooled_resp.append(resp[p_all < SIG_THRESH]) colors.append(cre_colors[cre]) alphas.append(1.0) cre_labels.append(shorthand(cre)) center_of_mass = center_of_mass_for_list(pooled_resp) contrasts = [5, 10, 20, 40, 60, 80] plot_cdf(metric=center_of_mass, metric_labels=cre_labels, colors=colors, alphas=alphas, hist_range=(np.log(5.0), np.log(70.0)), hist_bins=200, x_label='Contrast (CoM)', x_ticks=np.log(contrasts), x_tick_labels=[str(x) for x in contrasts], save_name=shorthand(area) + '_contrast_' + curve, savepath=savepath, do_legend=True)