reworked code to make nice plots for my presentation

This commit is contained in:
Till Raab 2023-11-28 14:50:57 +01:00
parent 284d30ad18
commit 2c4465eae4
62 changed files with 418 additions and 125 deletions

View File

@ -15,6 +15,7 @@ from thunderfish.powerspectrum import decibel
from IPython import embed
from event_time_correlations import load_and_converete_boris_events
glob_colors = ['#BA2D22', '#53379B', '#F47F17', '#3673A4', '#AAB71B', '#DC143C', '#1E90FF', 'k']
glob_colors_new = ['tab:green', 'tab:olive', 'tab:red', 'tab:orange', 'tab:blue', 'k']
def plot_transition_matrix(matrix, labels):
@ -42,7 +43,7 @@ def plot_transition_matrix(matrix, labels):
def plot_transition_diagram(matrix, labels, node_size, ax, threshold=5,
color_by_origin=False, color_by_target=False, title=''):
color_by_origin=False, color_by_target=False, title='', color_palet=glob_colors):
@ -61,16 +62,19 @@ def plot_transition_diagram(matrix, labels, node_size, ax, threshold=5,
positions2[p][1] *= 1.2
# ToDo: nodes
nx.draw_networkx_nodes(Graph, pos=positions, node_size=node_size, ax=ax, alpha=0.5, node_color=np.array(glob_colors)[:len(node_size)])
# nx.draw_networkx_nodes(Graph, pos=positions, node_size=node_size, ax=ax, alpha=0.5, node_color=np.array(glob_colors)[:len(node_size)])
nx.draw_networkx_nodes(Graph, pos=positions, node_size=node_size, ax=ax, alpha=0.5, node_color=np.array(color_palet)[:len(node_size)])
nx.draw_networkx_labels(Graph, pos=positions2, labels=node_labels, ax=ax)
# google networkx drawing to get better graphs with networkx
# nx.draw(Graph, pos=positions, node_size=node_size, label=labels, with_labels=True, ax=ax)
# # ToDo: edges
edge_width = np.array([x / 5 for x in [*edge_labels.values()]])
if color_by_origin:
edge_colors = np.array(glob_colors)[np.array([*edge_labels.keys()], dtype=int)[:, 0]]
# edge_colors = np.array(glob_colors)[np.array([*edge_labels.keys()], dtype=int)[:, 0]]
edge_colors = np.array(color_palet)[np.array([*edge_labels.keys()], dtype=int)[:, 0]]
elif color_by_target:
edge_colors = np.array(glob_colors)[np.array([*edge_labels.keys()], dtype=int)[:, 1]]
# edge_colors = np.array(glob_colors)[np.array([*edge_labels.keys()], dtype=int)[:, 1]]
edge_colors = np.array(color_palet)[np.array([*edge_labels.keys()], dtype=int)[:, 1]]
else:
edge_colors = 'k'
@ -79,7 +83,7 @@ def plot_transition_diagram(matrix, labels, node_size, ax, threshold=5,
nx.draw_networkx_edges(Graph, pos=positions, node_size=node_size, width=edge_width,
arrows=True, arrowsize=20,
min_target_margin=25, min_source_margin=25, connectionstyle="arc3, rad=0.025",
min_target_margin=25, min_source_margin=25, connectionstyle="arc3, rad=0.05", # rad=0.025"
ax=ax, edge_color=edge_colors)
nx.draw_networkx_edge_labels(Graph, positions, label_pos=0.2, edge_labels=edge_labels, ax=ax, rotate=True)
@ -92,6 +96,157 @@ def plot_transition_diagram(matrix, labels, node_size, ax, threshold=5,
ax.set_ylim(-1.3, 1.3)
ax.set_title(title, fontsize=12)
def plot_mixed_transition_diagram(og_matrix_origin, og_matrix_target, labels, node_size,
threshold=10, color_by_origin=False, color_by_target=False,
title='', color_palet=glob_colors):
old_mask = np.zeros_like(og_matrix_origin, dtype=bool)
for scenario in np.arange(1, 9):
fig, ax = plt.subplots(figsize=(21 / 2.54, 19 / 2.54))
fig.subplots_adjust(left=0.0, bottom=0.0, right=1, top=1)
matrix_origin = np.copy(og_matrix_origin)
matrix_target = np.copy(og_matrix_target)
matrix_origin[matrix_origin <= threshold] = 0
matrix_target[matrix_target <= threshold] = 0
helper_maks = matrix_origin >= matrix_target
matrix_origin[~helper_maks] = 0
matrix_target[helper_maks] = 0
matrix_origin_prev = np.copy(matrix_origin)
matrix_target_prev = np.copy(matrix_target)
mask = np.zeros_like(og_matrix_origin, dtype=bool)
if scenario == 1:
mask[-1, :] = 1
elif scenario == 2:
mask[1, :] = 1
elif scenario == 3:
mask[2, :] = 1
elif scenario == 4:
mask[0, :] = 1
mask[3, :] = 1
mask[0, 0] = 0
elif scenario == 5:
mask[4, :] = 1
elif scenario == 6:
mask = np.ones_like(matrix_origin, dtype=bool)
mask[0, 0] = 0
elif scenario == 7:
mask = np.zeros_like(matrix_origin, dtype=bool)
mask[5, 1] = 1
mask[1, 2] = 1
mask[2, 0] = 1
mask[0, 3] = 1
mask[3, 0] = 1
elif scenario == 8:
old_mask = np.ones_like(matrix_origin, dtype=bool)
old_mask[0, 0] = 0
mask = np.zeros_like(matrix_origin, dtype=bool)
mask[5, 1] = 1
mask[1, 2] = 1
mask[2, 0] = 1
mask[0, 3] = 1
mask[3, 0] = 1
mask[2, 3] = 1
mask[5, 2] = 1
old_mask[mask] = 0
matrix_origin[~mask] = 0
matrix_target[~mask] = 0
matrix_origin_prev[~old_mask] = 0
matrix_target_prev[~old_mask] = 0
matrix_origin = np.around(matrix_origin, decimals=1)
matrix_target = np.around(matrix_target, decimals=1)
matrix_origin_prev = np.around(matrix_origin_prev, decimals=1)
matrix_target_prev = np.around(matrix_target_prev, decimals=1)
Graph = nx.from_numpy_array(matrix_origin, create_using=nx.DiGraph)
Graph2 = nx.from_numpy_array(matrix_target, create_using=nx.DiGraph)
Graph_prev = nx.from_numpy_array(matrix_origin_prev, create_using=nx.DiGraph)
Graph2_prev = nx.from_numpy_array(matrix_target_prev, create_using=nx.DiGraph)
node_labels = dict(zip(Graph, labels))
edge_labels = nx.get_edge_attributes(Graph, 'weight')
edge_labels2 = nx.get_edge_attributes(Graph2, 'weight')
edge_labels_prev = nx.get_edge_attributes(Graph_prev, 'weight')
edge_labels2_prev = nx.get_edge_attributes(Graph2_prev, 'weight')
positions = nx.circular_layout(Graph)
positions2 = nx.circular_layout(Graph)
for p in positions:
positions2[p][0] *= 1.2
positions2[p][1] *= 1.2
nx.draw_networkx_nodes(Graph, pos=positions, node_size=node_size, ax=ax, alpha=0.5, node_color=np.array(color_palet)[:len(node_size)])
nx.draw_networkx_labels(Graph, pos=positions2, labels=node_labels, ax=ax)
edge_width = np.array([x / 5 for x in [*edge_labels.values()]])
edge_width2 = np.array([x / 5 for x in [*edge_labels2.values()]])
edge_width_prev = np.array([x / 5 for x in [*edge_labels_prev.values()]])
edge_width2_prev = np.array([x / 5 for x in [*edge_labels2_prev.values()]])
edge_width[edge_width >= 6] = 6
edge_width2[edge_width2 >= 6] = 6
edge_width_prev[edge_width_prev >= 6] = 6
edge_width2_prev[edge_width2_prev >= 6] = 6
if len(edge_labels2) >= 1:
if color_by_origin:
edge_colors = np.array(color_palet)[np.array([*edge_labels2.keys()], dtype=int)[:, 0]]
elif color_by_target:
edge_colors = np.array(color_palet)[np.array([*edge_labels2.keys()], dtype=int)[:, 1]]
else:
edge_colors = 'k'
nx.draw_networkx_edges(Graph2, pos=positions, node_size=node_size, width=edge_width2,
arrows=True, arrowsize=20, arrowstyle='->',
min_target_margin=25, min_source_margin=25, connectionstyle="arc3, rad=0.05",
# rad=0.025"
ax=ax, edge_color=edge_colors)
if len(edge_labels2_prev) >= 1:
if color_by_origin:
edge_colors_prev = np.array(color_palet)[np.array([*edge_labels2_prev.keys()], dtype=int)[:, 0]]
elif color_by_target:
edge_colors_prev = np.array(color_palet)[np.array([*edge_labels2_prev.keys()], dtype=int)[:, 1]]
else:
edge_colors_prev = 'k'
nx.draw_networkx_edges(Graph2_prev, pos=positions, node_size=node_size, width=edge_width2_prev,
arrows=True, arrowsize=20, arrowstyle='->',
min_target_margin=25, min_source_margin=25, connectionstyle="arc3, rad=0.05", # rad=0.025"
ax=ax, edge_color=edge_colors_prev, alpha=.25)
nx.draw_networkx_edges(Graph, pos=positions, node_size=node_size, width=edge_width,
arrows=True, arrowsize=20, arrowstyle='->',
min_target_margin=25, min_source_margin=25, connectionstyle="arc3, rad=0.05",
ax=ax, edge_color='k')
nx.draw_networkx_edges(Graph_prev, pos=positions, node_size=node_size, width=edge_width_prev,
arrows=True, arrowsize=20, arrowstyle='->',
min_target_margin=25, min_source_margin=25, connectionstyle="arc3, rad=0.05",
ax=ax, edge_color='k', alpha=.25)
ax.spines["top"].set_visible(False)
ax.spines["bottom"].set_visible(False)
ax.spines["right"].set_visible(False)
ax.spines["left"].set_visible(False)
ax.set_xlim(-1.4, 1.4)
ax.set_ylim(-1.3, 1.3)
ax.set_title(title, fontsize=12)
old_mask += mask
plt.savefig(os.path.join(os.path.split(__file__)[0], 'figures', 'markov', f'marcov_buildup_{scenario}' + '.png'), dpi=300)
plt.close()
# plt.show()
def create_marcov_matrix(individual_event_times, individual_event_labels):
event_times = []
event_labels = []
@ -114,7 +269,7 @@ def create_marcov_matrix(individual_event_times, individual_event_labels):
marcov_matrix[-1, enu_tar] = n
marcov_matrix[-1, 5] = 0
individual_event_labels.append('void')
individual_event_labels.append('start')
### get those cases where ag_on does not point to event and no event points to corresponding ag_off ... add thise cases in marcov matrix
chase_on_idx = np.where(event_labels == individual_event_labels[4])[0]
@ -400,24 +555,50 @@ def main(base_path):
collective_marcov_matrix = np.sum(all_marcov_matrix, axis=0)
collective_event_counts = np.sum(all_event_counts, axis=0)
for del_idx in [3, 2]:
collective_marcov_matrix = np.delete(collective_marcov_matrix, del_idx, 0)
collective_marcov_matrix = np.delete(collective_marcov_matrix, del_idx, 1)
collective_event_counts = np.delete(collective_event_counts, del_idx, 0)
individual_event_labels.pop(del_idx)
# collective_event_counts = np.ones_like(collective_event_counts) * collective_event_counts.mean()
ball_size = np.ones_like(collective_event_counts) * collective_event_counts.mean()
plot_transition_matrix(collective_marcov_matrix, individual_event_labels)
# marcov by origin
fig, ax = plt.subplots(figsize=(21 / 2.54, 19 / 2.54))
fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
plot_transition_diagram(
collective_marcov_matrix / collective_event_counts.reshape(len(collective_event_counts), 1) * 100,
individual_event_labels, collective_event_counts, ax, threshold=5, color_by_origin=True, title='origin triggers target [%]')
plt.savefig(os.path.join(os.path.split(__file__)[0], 'figures', 'markov', 'markov_destination' + '.png'), dpi=300)
plt.close()
individual_event_labels, ball_size, ax, threshold=5, color_by_origin=True, title='origin triggers target [%]', color_palet=glob_colors_new)
# plt.savefig(os.path.join(os.path.split(__file__)[0], 'figures', 'markov', 'markov_destination' + '.png'), dpi=300)
# plt.close()
# marcov by target
fig, ax = plt.subplots(figsize=(21 / 2.54, 19 / 2.54))
fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
plot_transition_diagram(collective_marcov_matrix / collective_event_counts * 100,
individual_event_labels, collective_event_counts, ax, threshold=5, color_by_target=True,
title='target triggered by origin [%]')
plt.savefig(os.path.join(os.path.split(__file__)[0], 'figures', 'markov', 'markov_origin' + '.png'), dpi=300)
plt.close()
individual_event_labels, ball_size, ax, threshold=5, color_by_target=True,
title='target triggered by origin [%]', color_palet=glob_colors_new)
# plt.savefig(os.path.join(os.path.split(__file__)[0], 'figures', 'markov', 'markov_origin' + '.png'), dpi=300)
# plt.close()
mm_origin = collective_marcov_matrix / collective_event_counts.reshape(len(collective_event_counts), 1) * 100
mm_target = collective_marcov_matrix / collective_event_counts * 100
max_collective_marcov = np.array([mm_origin, mm_target]).max(0)
fig, ax = plt.subplots(figsize=(21 / 2.54, 19 / 2.54))
fig.subplots_adjust(left=0.0, bottom=0.0, right=1, top=1)
plot_transition_diagram(max_collective_marcov,
individual_event_labels, ball_size, ax, threshold=10, color_by_origin=True,
title='best of both worlds', color_palet=glob_colors_new)
plt.show()
plot_mixed_transition_diagram(mm_origin, mm_target, individual_event_labels, ball_size,
color_by_target=True, color_palet=glob_colors_new)
for i, (marcov_matrix, event_counts) in enumerate(zip(all_marcov_matrix, all_event_counts)):
fig, ax = plt.subplots(figsize=(21 / 2.54, 19 / 2.54))

View File

@ -420,12 +420,34 @@ def event_category_signal(all_event_t, all_contact_t, all_ag_on_t, all_ag_off_t,
time_context_values.append(len(all_pre_chase_time) * 3 * 60 * 60 - np.sum(time_context_values))
time_context_values /= np.sum(time_context_values)
# fig, ax = plt.subplots(figsize=(12/2.54,12/2.54))
event_context_values2 = []
time_context_values2 = []
for event_value, time_value in zip(event_context_values[:-1], time_context_values[:-1]):
event_context_values2.append(event_value)
time_context_values2.append(time_value)
if event_value >= time_value:
time_context_values2.append(event_value - time_value)
event_context_values2.append(0)
else:
event_context_values2.append(time_value - event_value)
time_context_values2.append(0)
event_context_values2.append(1-np.sum(event_context_values2))
time_context_values2.append(1-np.sum(time_context_values2))
# fig, ax_pie = plt.subplots(figsize=(12/2.54,12/2.54))
size = 0.3
outer_colors = ['tab:red', 'tab:orange', 'yellow', 'tab:green', 'k', 'tab:brown', 'tab:grey']
ax_pie.pie(event_context_values, radius=1, colors=outer_colors,
# embed()
# quit()
outer_colors = ['tab:red', 'tab:grey',
'tab:orange', 'tab:grey',
'yellow', 'tab:grey',
'tab:green', 'tab:grey',
'k', 'tab:grey', 'tab:brown',
'tab:grey', 'tab:grey']
ax_pie.pie(event_context_values2, radius=1, colors=outer_colors,
wedgeprops=dict(width=size, edgecolor='w'), startangle=90, center=(0, 1))
ax_pie.pie(time_context_values, radius=1 - size, colors=outer_colors,
ax_pie.pie(time_context_values2, radius=1 - size, colors=outer_colors,
wedgeprops=dict(width=size, edgecolor='w', alpha=.6), startangle=90, center=(0, 1))
ax_pie.set_title(r'event context')
@ -451,7 +473,7 @@ def event_category_signal(all_event_t, all_contact_t, all_ag_on_t, all_ag_off_t,
Patch(facecolor='tab:brown', alpha=0.6, edgecolor='w',
label='%.1f' % (time_context_values[5] * 100) + '%')]
ax_pie.legend(handles=legend_elements, loc='lower right', ncol=2, bbox_to_anchor=(1.15, -0.25), frameon=False,
ax_pie.legend(handles=legend_elements, loc='lower right', ncol=2, bbox_to_anchor=(1.15, -0.3), frameon=False,
fontsize=9)
plt.savefig(os.path.join(os.path.split(__file__)[0], 'figures', 'event_time_corr', f'{event_name}_categories.png'),

View File

@ -1,6 +1,7 @@
import os
import sys
import argparse
import pathlib
import time
import itertools
@ -91,7 +92,7 @@ def kde(event_dt, conv_t, kernal_w = 1, kernal_h = 0.2):
return conv_array
def permutation_kde(event_dt, conv_t, repetitions = 2000, max_mem_use_GB = 4, kernal_w = 1, kernal_h = 0.2):
def permutation_kde(event_dt, conv_t, repetitions = 2000, max_mem_use_GB = 2, kernal_w = 1, kernal_h = 0.2):
def chunk_permutation(select_event_dt, conv_tt, n_chuck, max_jitter, kernal_w, kernal_h):
# array.shape = (120, 100, 15486) = (len(conv_t), repetitions, len(event_dt))
# event_dt_perm = cp.tile(event_dt, (len(conv_t), repetitions, 1))
@ -385,37 +386,7 @@ def main(base_path):
conv_t = cp.arange(-max_dt, max_dt+conv_t_dt, conv_t_dt)
conv_t_numpy = cp.asnumpy(conv_t)
# embed()
# quit()
# for centered_times, event_counts, title in \
# [[lose_chrips_centered_on_ag_off_t, lose_chirp_count, r'chirp$_{lose}$ on chase$_{off}$'],
# [lose_chrips_centered_on_ag_on_t, lose_chirp_count, r'chirp$_{lose}$ on chase$_{on}$'],
# [lose_chrips_centered_on_contact_t, lose_chirp_count, r'chirp$_{lose}$ on contact'],
# [lose_chrips_centered_on_win_rises, lose_chirp_count, r'chirp$_{lose}$ on rise$_{win}$'],
# [lose_chrips_centered_on_win_chirp, lose_chirp_count, r'chirp$_{lose}$ on chirp$_{win}$'],
# [lose_chirps_centered_on_lose_rises, lose_chirp_count, r'chirp$_{lose}$ on rises$_{lose}$'],
#
# [win_chrips_centered_on_ag_off_t, win_chirp_count, r'chirp$_{win}$ on chase$_{off}$'],
# [win_chrips_centered_on_ag_on_t, win_chirp_count, r'chirp$_{win}$ on chase$_{on}$'],
# [win_chrips_centered_on_contact_t, win_chirp_count, r'chirp$_{win}$ on contact'],
# [win_chrips_centered_on_lose_rises, win_chirp_count, r'chirp$_{win}$ on rise$_{lose}$'],
# [win_chrips_centered_on_lose_chirp, win_chirp_count, r'chirp$_{win}$ on chirp$_{lose}$'],
# [win_chirps_centered_on_win_rises, win_chirp_count, r'chirp$_{win}$ on rises$_{win}$'],
#
# [lose_rises_centered_on_ag_off_t, lose_rises_count, r'rise$_{lose}$ on chase$_{off}$'],
# [lose_rises_centered_on_ag_on_t, lose_rises_count, r'rise$_{lose}$ on chase$_{on}$'],
# [lose_rises_centered_on_contact_t, lose_rises_count, r'rise$_{lose}$ on contact'],
# [lose_rises_centered_on_win_chirps, lose_rises_count, r'rise$_{lose}$ on chirp$_{win}$'],
#
# [win_rises_centered_on_ag_off_t, win_rises_count, r'rise$_{win}$ on chase$_{off}$'],
# [win_rises_centered_on_ag_on_t, win_rises_count, r'rise$_{win}$ on chase$_{on}$'],
# [win_rises_centered_on_contact_t, win_rises_count, r'rise$_{win}$ on contact'],
# [win_rises_centered_on_lose_chirps, win_rises_count, r'rise$_{win}$ on chirp$_{lose}$'],
#
# [ag_off_centered_on_ag_on, chase_count, r'chase$_{off}$ on chase$_{on}$']]:
for centered_times, event_counts, title in \
for category_enu, (centered_times, event_counts, title) in enumerate(
[[lose_chrips_centered_on_ag_off_t, chase_count, r'chirp$_{lose}$ on chase$_{off}$'],
[lose_chrips_centered_on_ag_on_t, chase_count, r'chirp$_{lose}$ on chase$_{on}$'],
[lose_chrips_centered_on_contact_t, contact_count, r'chirp$_{lose}$ on contact'],
@ -440,11 +411,13 @@ def main(base_path):
[win_rises_centered_on_contact_t, contact_count, r'rise$_{win}$ on contact'],
[win_rises_centered_on_lose_chirps, lose_chirp_count, r'rise$_{win}$ on chirp$_{lose}$'],
[ag_off_centered_on_ag_on, chase_count, r'chase$_{off}$ on chase$_{on}$']]:
[ag_off_centered_on_ag_on, chase_count, r'chase$_{off}$ on chase$_{on}$']]):
save_str = title.replace('$', '').replace('{', '').replace('}', '').replace(' ', '_')
###########################################################################################################
### by pairing ###
if True:
centered_times_pairing = []
for sex_w, sex_l in itertools.product(['m', 'f'], repeat=2):
centered_times_pairing.append([])
@ -520,24 +493,38 @@ def main(base_path):
perm_p1, perm_p50, perm_p99 = np.percentile(boot_kde, (1, 50, 99), axis=0)
jk_p1, jk_p50, jk_p99 = np.percentile(jk_kde, (1, 50, 99), axis=0)
if category_enu == 0:
# chirp on chase off
chirp_on_chase_off = [perm_p1, perm_p50, perm_p99, jk_p1, jk_p50, jk_p99, event_counts]
elif category_enu == 1:
# chirp on chase on
chirp_on_chase_on = [perm_p1, perm_p50, perm_p99, jk_p1, jk_p50, jk_p99, event_counts]
elif category_enu == 20:
# chase off on chase on
chase_off_on_chase_on = [perm_p1, perm_p50, perm_p99, jk_p1, jk_p50, jk_p99, event_counts]
elif category_enu == 12:
rise_on_chase_off = [perm_p1, perm_p50, perm_p99, jk_p1, jk_p50, jk_p99, event_counts]
elif category_enu == 13:
rise_on_chase_on = [perm_p1, perm_p50, perm_p99, jk_p1, jk_p50, jk_p99, event_counts]
elif category_enu == 2:
chirp_on_contact = [perm_p1, perm_p50, perm_p99, jk_p1, jk_p50, jk_p99, event_counts]
elif category_enu == 14:
rise_on_contact = [perm_p1, perm_p50, perm_p99, jk_p1, jk_p50, jk_p99, event_counts]
fig = plt.figure(figsize=(20/2.54, 12/2.54))
gs = gridspec.GridSpec(1, 1, left=0.1, bottom=0.1, right=0.95, top=0.95)
ax = fig.add_subplot(gs[0, 0])
# ax.fill_between(conv_t_numpy, perm_p1/len(np.hstack(centered_times)), perm_p99/len(np.hstack(centered_times)), color='cornflowerblue', alpha=.8)
# ax.plot(conv_t_numpy, perm_p50/len(np.hstack(centered_times)), color='dodgerblue', alpha=1, lw=3)
#
# ax.fill_between(conv_t_numpy, jk_p1/len(np.hstack(centered_times))/jack_pct, jk_p99/len(np.hstack(centered_times))/jack_pct, color='tab:red', alpha=.8)
# ax.plot(conv_t_numpy, jk_p50/len(np.hstack(centered_times))/jack_pct, color='firebrick', alpha=1, lw=3)
ax.fill_between(conv_t_numpy, perm_p1/np.nansum(event_counts), perm_p99/np.nansum(event_counts), color='cornflowerblue', alpha=.8)
ax.plot(conv_t_numpy, perm_p50/np.nansum(event_counts), color='dodgerblue', alpha=1, lw=3)
ax.fill_between(conv_t_numpy, jk_p1/np.nansum(event_counts)/jack_pct, jk_p99/np.nansum(event_counts)/jack_pct, color='tab:red', alpha=.8)
ax.plot(conv_t_numpy, jk_p50/np.nansum(event_counts)/jack_pct, color='firebrick', alpha=1, lw=3)
ax_m = ax.twinx()
counter = 0
for enu, centered_events in enumerate(centered_times):
Cevents = centered_events[np.abs(centered_events) <= max_dt]
if len(Cevents) != 0:
@ -555,6 +542,104 @@ def main(base_path):
plt.savefig(os.path.join(os.path.split(__file__)[0], 'figures', 'event_time_corr', f'{save_str}.png'), dpi=300)
plt.close()
embed()
quit()
event_time_plot_with_agonistic_dur(conv_t_numpy, chirp_on_chase_off, chase_off_on_chase_on,
lose_chrips_centered_on_ag_off_t, jack_pct, max_dt,
title=r'chirp$_{lose}$ on chase$_{off}$', chase_on_centered=False)
event_time_plot_with_agonistic_dur(conv_t_numpy, chirp_on_chase_on, chase_off_on_chase_on,
lose_chrips_centered_on_ag_on_t, jack_pct, max_dt,
title=r'chirp$_{lose}$ on chase$_{on}$', chase_on_centered=True)
event_time_plot_with_agonistic_dur(conv_t_numpy, rise_on_chase_off, chase_off_on_chase_on,
lose_rises_centered_on_ag_off_t, jack_pct, max_dt,
title=r'rise$_{lose}$ on chase$_{off}$', chase_on_centered=False)
event_time_plot_with_agonistic_dur(conv_t_numpy, rise_on_chase_on, chase_off_on_chase_on,
lose_rises_centered_on_ag_on_t, jack_pct, max_dt,
title=r'rise$_{lose}$ on chase$_{on}$', chase_on_centered=True)
event_time_plot_with_agonistic_dur(conv_t_numpy, rise_on_contact, None,
lose_rises_centered_on_contact_t, jack_pct, max_dt,
title=r'rise$_{lose}$ on contact')
event_time_plot_with_agonistic_dur(conv_t_numpy, chirp_on_contact, None,
lose_chrips_centered_on_contact_t, jack_pct, max_dt,
title=r'chirp$_{lose}$ on contact')
def event_time_plot_with_agonistic_dur(conv_t_numpy, centered_communication, chase_dur_dist,
centered_raster_times, jack_pct, max_dt, title='', chase_on_centered=True):
fig = plt.figure(figsize=(20 / 2.54, 12 / 2.54))
gs = gridspec.GridSpec(1, 1, left=0.1, bottom=0.125 , right=0.9, top=0.95)
ax = fig.add_subplot(gs[0, 0])
perm_p1, perm_p50, perm_p99, jk_p1, jk_p50, jk_p99, event_counts = centered_communication
ax.fill_between(conv_t_numpy, perm_p1 / np.nansum(event_counts), perm_p99 / np.nansum(event_counts),
color='tab:gray', alpha=.8)
ax.plot(conv_t_numpy, perm_p50 / np.nansum(event_counts), color='tab:gray', alpha=1, lw=3)
ax.fill_between(conv_t_numpy, jk_p1 / np.nansum(event_counts) / jack_pct,
jk_p99 / np.nansum(event_counts) / jack_pct, color='tab:red', alpha=.8)
ax.plot(conv_t_numpy, jk_p50 / np.nansum(event_counts) / jack_pct, color='firebrick', alpha=1, lw=3)
ax.set_xlabel('time [s]', fontsize=14)
ax.set_ylabel('event rate [Hz]', fontsize=14)
ax.set_title(title, fontsize=14)
ax.set_xlim(-max_dt, max_dt)
ax.tick_params(labelsize=12)
### chasing dist
if hasattr(chase_dur_dist, '__len__'):
ax_m = ax.twinx()
perm_p1, perm_p50, perm_p99, jk_p1, jk_p50, jk_p99, event_counts = chase_dur_dist
if chase_on_centered == False:
y1label = r'p(chase$_{start}$)'
jk_p1 = jk_p1[::-1]
jk_p50 = jk_p50[::-1]
jk_p99 = jk_p99[::-1]
mask = conv_t_numpy <= 0
else:
y1label = r'p(chase$_{end}$)'
mask = conv_t_numpy >= 0
ax_m.fill_between(conv_t_numpy[mask], jk_p1[mask] / np.nansum(event_counts) / jack_pct,
jk_p99[mask] / np.nansum(event_counts) / jack_pct, color='tab:blue', alpha=.6)
ax_m.plot(conv_t_numpy[mask], jk_p50[mask] / np.nansum(event_counts) / jack_pct, color='tab:blue', alpha=.75, lw=3)
ax_m.set_ylabel(y1label, fontsize=14)
ax_m.yaxis.label.set_color('tab:blue')
ax_m.spines["right"].set_edgecolor('tab:blue')
ax_m.tick_params(axis='y', colors='tab:blue', labelsize=12)
counter = 0
ax_m2 = ax.twinx()
for enu, centered_events in enumerate(centered_raster_times):
Cevents = centered_events[np.abs(centered_events) <= max_dt]
if len(Cevents) != 0:
ax_m2.plot(Cevents, np.ones(len(Cevents)) * counter, '|', markersize=8, color='k', alpha=.1)
counter += 1
ax_m2.plot([0, 0], [-1, counter], '--', color='k', lw=2)
ax_m2.set_ylim(-1, counter)
ax_m2.yaxis.set_visible(False)
# embed()
# quit()
save_path = pathlib.Path(__file__).parent / 'figures' / 'event_time_corr_new'
save_str = title.replace(' ', '_').replace('{', '').replace('}', '').replace('$', '')
if not save_path.exists():
save_path.mkdir(parents=True, exist_ok=True)
plt.savefig(save_path / f'{save_str}.png', dpi=300)
plt.close()
if __name__ == '__main__':
main(sys.argv[1])

View File

@ -15,6 +15,9 @@ def main(folder, dt):
create_video_path = os.path.join(folder, 'rise_video')
if not os.path.exists(create_video_path):
os.mkdir(create_video_path)
# embed()
# quit()
video = cv2.VideoCapture(video_path) # was 'cap'
# fish_freqs = np.load(os.path.join(folder, 'analysis', 'fish_freq_interp.npy'))
@ -29,6 +32,8 @@ def main(folder, dt):
fill_spec = np.memmap(os.path.join(folder, 'fill_spec.npy'), dtype='float', mode='r',
shape=(fill_spec_shape[0], fill_spec_shape[1]), order='F')
#######################################
# embed()
# quit()
for fish_nr in np.arange(2)[::-1]:
for idx_oi in tqdm(np.array(rise_idx[fish_nr][~np.isnan(rise_idx[fish_nr])], dtype=int)):
@ -98,7 +103,7 @@ def main(folder, dt):
# plt.ion()
for i in tqdm(np.arange(len(frames_oi))):
break
# break
video.set(cv2.CAP_PROP_POS_FRAMES, int(frames_oi[i]))
ret, frame = video.read()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 KiB

After

Width:  |  Height:  |  Size: 270 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 303 KiB

After

Width:  |  Height:  |  Size: 286 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 293 KiB

After

Width:  |  Height:  |  Size: 285 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 KiB

After

Width:  |  Height:  |  Size: 340 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 357 KiB

After

Width:  |  Height:  |  Size: 354 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 435 KiB

After

Width:  |  Height:  |  Size: 383 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 374 KiB

After

Width:  |  Height:  |  Size: 380 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 375 KiB

After

Width:  |  Height:  |  Size: 387 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 316 KiB

After

Width:  |  Height:  |  Size: 348 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 321 KiB

After

Width:  |  Height:  |  Size: 305 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 305 KiB

After

Width:  |  Height:  |  Size: 324 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 331 KiB

After

Width:  |  Height:  |  Size: 327 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 342 KiB

After

Width:  |  Height:  |  Size: 327 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 310 KiB

After

Width:  |  Height:  |  Size: 282 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 363 KiB

After

Width:  |  Height:  |  Size: 361 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 373 KiB

After

Width:  |  Height:  |  Size: 351 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 KiB

After

Width:  |  Height:  |  Size: 270 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 KiB

After

Width:  |  Height:  |  Size: 248 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 352 KiB

After

Width:  |  Height:  |  Size: 340 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 466 KiB

After

Width:  |  Height:  |  Size: 481 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 310 KiB

After

Width:  |  Height:  |  Size: 316 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 408 KiB

After

Width:  |  Height:  |  Size: 376 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 375 KiB

After

Width:  |  Height:  |  Size: 383 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 451 KiB

After

Width:  |  Height:  |  Size: 400 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 322 KiB

After

Width:  |  Height:  |  Size: 319 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 381 KiB

After

Width:  |  Height:  |  Size: 397 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 352 KiB

After

Width:  |  Height:  |  Size: 360 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 380 KiB

After

Width:  |  Height:  |  Size: 370 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 347 KiB

After

Width:  |  Height:  |  Size: 364 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 353 KiB

After

Width:  |  Height:  |  Size: 360 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 373 KiB

After

Width:  |  Height:  |  Size: 364 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 403 KiB

After

Width:  |  Height:  |  Size: 434 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 333 KiB

After

Width:  |  Height:  |  Size: 342 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 337 KiB

After

Width:  |  Height:  |  Size: 310 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 291 KiB

After

Width:  |  Height:  |  Size: 296 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 230 KiB

After

Width:  |  Height:  |  Size: 234 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 137 KiB

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 363 KiB

After

Width:  |  Height:  |  Size: 369 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 418 KiB

After

Width:  |  Height:  |  Size: 424 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 316 KiB

After

Width:  |  Height:  |  Size: 318 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 403 KiB

After

Width:  |  Height:  |  Size: 412 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 328 KiB

After

Width:  |  Height:  |  Size: 330 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 364 KiB

After

Width:  |  Height:  |  Size: 371 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 KiB

After

Width:  |  Height:  |  Size: 242 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 340 KiB

After

Width:  |  Height:  |  Size: 346 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 274 KiB

After

Width:  |  Height:  |  Size: 276 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 317 KiB

After

Width:  |  Height:  |  Size: 323 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 360 KiB

After

Width:  |  Height:  |  Size: 362 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

After

Width:  |  Height:  |  Size: 408 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 357 KiB

After

Width:  |  Height:  |  Size: 361 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 425 KiB

After

Width:  |  Height:  |  Size: 431 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 391 KiB

After

Width:  |  Height:  |  Size: 399 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 475 KiB

After

Width:  |  Height:  |  Size: 484 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 KiB

After

Width:  |  Height:  |  Size: 243 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 295 KiB

After

Width:  |  Height:  |  Size: 297 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 426 KiB

After

Width:  |  Height:  |  Size: 323 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 468 KiB

After

Width:  |  Height:  |  Size: 354 KiB