def get_avg_firing_rates_around_events(spike_rates, event_time_points, ev_video_df, time_around_event=5, keep_trials=False): frames_of_events = sync_funcs.time_point_to_frame_from_video_df(ev_video_df, event_time_points) frames_around_event = time_around_event * VIDEO_FRAME_RATE firing_rate_around_events = np.zeros((len(event_time_points), len(spike_rates), 2 * frames_around_event)) for f in np.arange(len(frames_of_events)): frame = frames_of_events[f] firing_rate_around_events[f, :, :] = spike_rates[:, frame - frames_around_event: frame + frames_around_event] avg_firing_rate_around_events = firing_rate_around_events.mean(axis=0) if keep_trials: return firing_rate_around_events, avg_firing_rate_around_events return avg_firing_rate_around_events
time_points_of_non_trial_pokes_selected.append( all_pokes[non_trial_pokes_in_all_pokes_to_select_from[np.squeeze( selecetd_index)]]) dif_of_non_trial_pokes_to_previous_poke_to_select_from = \ np.delete(dif_of_non_trial_pokes_to_previous_poke_to_select_from, selecetd_index) all_pokes_to_select_from = np.delete( non_trial_pokes_in_all_pokes_to_select_from, selecetd_index) time_points_of_non_trial_pokes_selected = np.squeeze( np.array(time_points_of_non_trial_pokes_selected)) # Create the corresponding time windows (and in frames) window_size_frames = np.array(trial_durations / const_comm.SAMPLING_FREQUENCY * 120, dtype=np.int32) trial_frames = sync_funcs.time_point_to_frame_from_video_df( event_dataframes['ev_video'], time_points_of_trial_pokes) non_trial_frames = sync_funcs.time_point_to_frame_from_video_df( event_dataframes['ev_video'], time_points_of_non_trial_pokes_selected) number_of_trial_pokes = len(trial_frames) number_of_non_trial_pokes = len(non_trial_frames) trial_windows_in_frames = [ np.arange(trial_frames[tf] - window_size_frames[tf], trial_frames[tf] + window_size_frames[tf], 1) for tf in np.arange(len(trial_frames)) ] non_trial_windows_in_frames = [ np.arange(non_trial_frames[ntf] - window_size_frames[ntf], non_trial_frames[ntf] + window_size_frames[ntf], 1) for ntf in np.arange(len(non_trial_frames))
def tp_to_frame(frame): return sync_funcs.time_point_to_frame_from_video_df(ev_video, frame)[0] - frames_before_tb
# Patterned behaviour is defined as going to the ball and then requiring a short time interval to go to the poke with # no or very little digression from the "touch ball -> go to poke" pattern time_between_tb_and_p = 15 frames_between_tb_and_p = time_between_tb_and_p * 120 frames_before_tb = 1 * 120 index_of_events_tb_followed_by_fast_p = np.squeeze(np.argwhere((events_successful_trial_pokes - events_touch_ball_successful_trial) / const.SAMPLING_FREQUENCY < time_between_tb_and_p)) # The following delete is because during the 30th time span the rat just sits doing nothing index_of_events_tb_followed_by_fast_p = np.delete(index_of_events_tb_followed_by_fast_p, 30) frames_tb_followed_by_fast_p = sync_funcs.time_point_to_frame_from_video_df(ev_video, events_touch_ball_successful_trial[ index_of_events_tb_followed_by_fast_p]) frames_fast_p = sync_funcs.time_point_to_frame_from_video_df(ev_video, events_successful_trial_pokes[ index_of_events_tb_followed_by_fast_p]) number_of_patterned_events = len(index_of_events_tb_followed_by_fast_p) windows_of_patterned_behaviour = [np.arange(frames_tb_followed_by_fast_p[frame], frames_fast_p[frame], 1) for frame in np.arange(number_of_patterned_events)] # <editor-fold desc="Have a look at the selected patterned behaviour events">
globals(), 'index', 'output', 'show_rasters_decrease', 'args', slider_limits=[0, len(decreasing_firing_rates_neuron_index) - 1]) # </editor-fold> # ------------------------------------------------- # <editor-fold desc="Looking at the time of touching ball. Nothing happens!"> plt.plot(cdt.space_data(avg_firing_rate_around_suc_trials, 10).transpose()) touch_ball_trials = event_dataframes['ev_rat_touch_ball'] frames_of_touch_ball_trials = sync_funcs.time_point_to_frame_from_video_df( event_dataframes['ev_video'], touch_ball_trials['AmpTimePoints'].values) firing_rate_around_touch_trials = np.zeros( (len(touch_ball_trials), len(spike_rates), 2 * frames_around_beam_break)) for f in np.arange(len(firing_rate_around_touch_trials)): frame = frames_of_touch_ball_trials[f] firing_rate_around_touch_trials[ f, :, :] = spike_rates[:, frame - frames_around_beam_break:frame + frames_around_beam_break] avg_firing_rate_around_touch_trials = firing_rate_around_touch_trials.mean( axis=0) avg_firing_rate_around_touch_trials -= np.expand_dims( avg_firing_rate_around_touch_trials[:, :600].mean(axis=1), axis=1) plt.imshow(avg_firing_rate_around_touch_trials,
def tp_to_frame(tp): return sync_funcs.time_point_to_frame_from_video_df( event_dataframes['ev_video'], tp)[0]