From 20ba268aadda01257a543d2d1d92446c63dc4e62 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Thu, 24 Sep 2020 09:04:28 +0200 Subject: [PATCH] figure work,improve saving --- chirps_as_probing_signals.md | 6 ++--- response_discriminability.py | 46 +++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/chirps_as_probing_signals.md b/chirps_as_probing_signals.md index 37f46d4..2ae2212 100644 --- a/chirps_as_probing_signals.md +++ b/chirps_as_probing_signals.md @@ -43,11 +43,12 @@ Won't do, this is trivial?! * Work out the difference between baseline activity and a foreign chirp response: --> done * calculate the discriminability between the baseline (no-other fish present) and the another fish is present for each contrast -* Work out the difference between the soliloquy and the response to self generated chirp in a communication context -* Compare to the beat alone parts of the responses. +* Work out the difference between the soliloquy and the response to self generated chirp in a communication context -> done +* Compare to the beat alone parts of the responses. -> done * What kernels to use? * Duration of the chrip window? * sorting according to phase? +* we could filter the P-unit responses to model the ELL filering ## Random thoughts @@ -55,4 +56,3 @@ Won't do, this is trivial?! * Raab et al show this is also the case with rises. * Check role of AFRs and rises in Tallarovic et al, Hupe et al. * we actually do not observe chirps without stimulation -* diff --git a/response_discriminability.py b/response_discriminability.py index 4e08050..e715622 100644 --- a/response_discriminability.py +++ b/response_discriminability.py @@ -273,7 +273,7 @@ def foreign_fish_detection_beat(block_map, df, all_contrasts, all_conditions, ke baseline_dist = within_group_distance(no_other_snippets) comp_dist = across_group_distance(no_other_snippets, self_snippets) - # sort and perfom roc + # sort and perfom ROC analysis triangle_indices = np.tril_indices_from(baseline_dist, -1) valid_distances_baseline = baseline_dist[triangle_indices] temp1 = np.zeros_like(valid_distances_baseline) @@ -341,7 +341,7 @@ def foreign_fish_detection_chirp(block_map, df, all_contrasts, all_conditions, k self_vs_alone_dist = across_group_distance(alone_chirping_snippets, self_snippets) other_vs_baseline_dist = across_group_distance(baseline_snippets, other_snippets) - # sort and perfom roc for two comparisons + # sort and perfom ROC analysis for two comparisons # 1. soliloquy vs. self chirping in company # 2. other chirping vs. nobody is chirping triangle_indices = np.tril_indices_from(alone_chirping_dist, -1) @@ -373,7 +373,7 @@ def foreign_fish_detection_chirp(block_map, df, all_contrasts, all_conditions, k return detection_performances -def plot_detection_results(data_frame, df, kernel_width, cell): +def plot_detection_results(data_frame, df, kernel_width, cell, figure_name=None): cell_results = data_frame[(data_frame.cell == cell) & (data_frame.df == df)] conditions = sorted(cell_results.detection_task.unique()) kernels = sorted(cell_results.kernel_width.unique()) @@ -382,26 +382,27 @@ def plot_detection_results(data_frame, df, kernel_width, cell): fig_grid = (8, 7) for i, c in enumerate(conditions): condition_results = cell_results[cell_results.detection_task == c] + roc_data = condition_results[condition_results.kernel_width == kernel_width] + contrasts = roc_data.contrast.unique() roc_ax = plt.subplot2grid(fig_grid, (i * 2 + i, 0), colspan=3, rowspan=2) + roc_ax.set_title(c, fontsize=9, ha="left") auc_ax = plt.subplot2grid(fig_grid, (i * 2 + i, 4), colspan=3, rowspan=2) - - roc_data = condition_results[condition_results.kernel_width == kernel_width] - contrasts = roc_data.contrast.unique() for c in contrasts: tpr = roc_data.true_positives[roc_data.contrast == c].values[0] fpr = roc_data.false_positives[roc_data.contrast == c].values[0] roc_ax.plot(fpr, tpr, label="%.3f" % c, zorder=2) roc_ax.legend(loc="best", fontsize=6, ncol=2, frameon=False) roc_ax.plot([0., 1.],[0., 1.], color="k", lw=0.5, ls="--", zorder=0) - roc_ax.set_xlabel("false positive rate", fontsize=9) - roc_ax.set_ylabel("true positive rate", fontsize=9) roc_ax.set_xticks(np.arange(0.0, 1.01, 0.5)) roc_ax.set_xticks(np.arange(0.0, 1.01, 0.25), minor=True) - roc_ax.set_xticklabels(np.arange(0.0, 1.01, 0.5), fontsize=8) roc_ax.set_yticks(np.arange(0.0, 1.01, 0.5)) roc_ax.set_yticks(np.arange(0.0, 1.01, 0.25), minor=True) + if i == len(conditions) - 1: + roc_ax.set_xticklabels(np.arange(0.0, 1.01, 0.5), fontsize=8) + roc_ax.set_xlabel("false positive rate", fontsize=9) + roc_ax.set_ylabel("true positive rate", fontsize=9) roc_ax.set_yticklabels(np.arange(0.0, 1.01, 0.5), fontsize=8) for k in kernels: @@ -409,19 +410,25 @@ def plot_detection_results(data_frame, df, kernel_width, cell): aucs = np.asarray(condition_results.auc[condition_results.kernel_width == k]) aucs_sorted = aucs[np.argsort(contrasts)] contrasts_sorted = np.sort(contrasts) - auc_ax.plot(contrasts_sorted, aucs_sorted, marker=".", label=r"$\sigma$: %.4f" % k) - - auc_ax.set_xlabel("contrast [%]") - auc_ax.set_ylim([0.25, 1.0]) - auc_ax.set_ylabel("discriminability") + auc_ax.plot(contrasts_sorted, aucs_sorted, marker=".", label=r"$\sigma$: %.4f" % k, zorder=1) + if i == len(conditions) - 1: + auc_ax.set_xlabel("contrast [%]", fontsize=9) + else: + auc_ax.set_xticklabels("") + auc_ax.set_ylim([0.25, 1.0]) + auc_ax.set_yticks(np.arange(0.25, 1.01, 0.25)) + auc_ax.set_yticklabels(np.arange(0.25, 1.01, 0.25), fontsize=8) + auc_ax.set_ylabel("discriminability", fontsize=9) auc_ax.legend(ncol=2, fontsize=6) - auc_ax.plot([min(contrasts), max(contrasts)], [0.5, 0.5], lw=0.5, ls"--",) - fig.savefig("discrimination.pdf") + auc_ax.plot([min(contrasts), max(contrasts)], [0.5, 0.5], lw=0.5, ls="--", zorder=0) + name = figure_name if figure_name is not None else "foreign_fish_detection.pdf" + name = (name + ".pdf") if ".pdf" not in name else name + plt.savefig(os.path.join(figure_folder, name)) def foreign_fish_detection(block_map, all_dfs, all_contrasts, all_conditions, current_df=None, cell_name=""): dfs = [current_df] if current_df is not None else all_dfs - kernels = [0.00025, 0.0005, 0.001, 0.0025, 0.005] + kernels = [0.00025, 0.0005, 0.001, 0.0025] result_dicts = [] for df in dfs: for kw in kernels: @@ -439,6 +446,11 @@ def foreign_fish_detection(block_map, all_dfs, all_contrasts, all_conditions, cu return result_dicts +def estimate_chirp_phase(am, chirp_times): + + pass + + def process_cell(filename, dfs=[], contrasts=[], conditions=[]): nf = nix.File.open(filename, nix.FileMode.ReadOnly) block_map, all_contrasts, all_dfs, all_conditions = sort_blocks(nf)