else:
        phases_m_g.append(np.zeros(data.shape[1]))
        phases_m_f_g.append(np.zeros(data.shape[1]))

phases_m_g = np.array(phases_m_g)
phases_m_f_g = np.array(phases_m_f_g)

fig = plt.figure(2)
fig.set_size_inches(10, 19)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
plt.set_cmap('viridis')
ax.imshow(phases_m_f_g, origin='lower', aspect='auto')

one_s_v.graph(globals(), 'phases_m_f_g')

one_s_v.image(globals(), 'phases_m_f_g', image_levels=[-2, 15], flip='ud')

fig = plt.figure()
ax1 = fig.add_subplot(611)
ax1.plot(d_data_smooth[sub_channels, :].T)
ax2 = fig.add_subplot(612)
ax2.plot(d_phases[sub_channels, :].T)
ax3 = fig.add_subplot(613)
ax3.plot(m_phases_f_smoothed.T)
ax4 = fig.add_subplot(614)
ax4.plot(f_phases[sub_channels, :].T)
ax5 = fig.add_subplot(615)
ax5.plot(m_phases_d.T)
ax6 = fig.add_subplot(616)
Example #2
0
def update_head_trajectory(f):
    global head_traj_x
    global head_traj_y
    head_traj_x = head_positions[:f, 0]
    head_traj_y = head_positions[:f, 1]
    return head_positions[:f, :]


body_traj = None
tr.connect_repl_var(globals(), 'frame', 'body_traj', 'update_body_trajectory')

head_traj = None
tr.connect_repl_var(globals(), 'frame', 'head_traj', 'update_head_trajectory')

osv.graph(globals(), 'body_traj_y', 'body_traj_x')
osv.graph(globals(), 'head_traj_y', 'head_traj_x')

# -------------------------------------------------
# <editor-fold desc="GENERATE THE SPEED VECTOR">
# Load the cleaned body positions
body_positions = np.load(
    join(dlc_project_folder, 'post_processing', 'body_positions.npy'))

# Use body position to create velocities (both linear and polar)
conversion_const = const.PIXEL_PER_FRAME_TO_CM_PER_SECOND
body_velocities = np.diff(body_positions, axis=0) * conversion_const
body_velocities_polar = np.array([
    np.sqrt(
        np.power(body_velocities[:, 0], 2) +
        np.power(body_velocities[:, 1], 2)), 180 * (1 / np.pi) *
    x = spike_info['times'].values[np.logical_and(spike_info['times'] < end,
                                                  spike_info['times'] > start)]
    templates = spike_info['template_after_sorting'].values[np.logical_and(
        spike_info['times'] < end, spike_info['times'] > start)]
    y = []
    for t in templates:
        y.append(template_info[template_info['template number'] == t]
                 ['position Y'].values[0])
    y = np.array(y) * const.POSITION_MULT
    return x, y


raster = None
tr.connect_repl_var(globals(), 'pane', 'raster', 'raster_from_pane')

osv.graph(globals(), 'y', 'x', True)

# Calculating firing rates using arbitrary time windows
'''
seconds_in_averaging_window = 0.5
averaging_window = int(seconds_in_averaging_window * const.SAMPLING_FREQUENCY)
num_of_windows = int(ap_data.shape[1] / averaging_window)
spike_rates = np.zeros((len(template_info), num_of_windows))


for t_index in np.arange(len(template_info)):
    template_index = template_info['template number'].iloc[t_index]
    spike_times_in_template = spike_info[spike_info['template_after_sorting'] == template_index]['times'].values

    for s_index in np.arange(num_of_windows):
        start = s_index * averaging_window
dd.connect_repl_var(globals(), 'six_pip_sound_start_times', 'sync_starting_point')
# tr.connect_repl_var(globals(), 'sync_starting_point', 'sound_starting_point', 'sync_to_sound_1')
tr.connect_repl_var(globals(), 'sync_starting_point', 'sound_starting_point', 'sync_to_sound_2')

range = 10000
# sv.graph_range(globals(), 'sync_starting_point', 'range', 'sync1')
sv.graph_range(globals(), 'sync_starting_point', 'range', 'sync_diff')

range_sound = 200000
sv.graph_range(globals(), 'sound_starting_point', 'range_sound', 'rec2_sound')

sound_data = []
args_end_of_data = [150000]
# tr.connect_repl_var(globals(), 'sound_starting_point', 'sound_data', 'get_sound1_data', 'args_end_of_data')
tr.connect_repl_var(globals(), 'sound_starting_point', 'sound_data', 'get_sound2_data', 'args_end_of_data')
osv.graph(globals(), 'sound_data')

freq_and_power = 0
fig = plt.figure(1)
args_spectrum_figure = [fig]
tr.connect_repl_var(globals(), 'sound_data',  'freq_and_power', 'get_freq_and_power', 'args_spectrum_figure')

# this is just to live display the freq and intensity
tr.connect_repl_var(globals(), 'freq_and_power', 'freq_and_power')


# Get the freqs and the intensities at that freq for all sound that are found clean in the sync file
# -------------------------
six_pip_sound_start_times = np.load(join(events_folder, 'six_pip_sound_start_times.npy'))
sound_to_sync_sampling_ratio = 15
sync_starts1, sound_1_offsets = np.load(join(events_folder, 'sync_starts_to_sound1_offsets.npy'))
    return [factor, t, buffer, imfs]


sl.connect_repl_var(globals(),
                    'time',
                    'update_args',
                    'args',
                    slider_limits=[1000000, 1200000])
window = None
sl.connect_repl_var(globals(),
                    'imf',
                    'window',
                    'get_windowed_imf',
                    'args',
                    slider_limits=[0, 12])
osv.graph(globals(), 'window')

#  -------------------------------------------------
# TEST WHAT HAPPENS IF I KILOSORT ONE IMF OF ALL CHANNELS
#  -------------------------------------------------

# Prepare the data
imf_for_ks = 3
imf_for_ks_filename = join(imf_kilosort_folder, 'imf_{}'.format(imf_for_ks),
                           'single_imf_{}.bin'.format(imf_for_ks))
'''
imf_data_for_ks = np.memmap(imf_for_ks_filename, dtype=imfs.dtype, mode='w+', shape=(imfs.shape[0], imfs.shape[2]))
imf_data_for_ks[:, :] = np.array(imfs[:, imf_for_ks, :].copy())
del imf_data_for_ks
'''
imf_data_for_ks = np.memmap(imf_for_ks_filename,
          'image_levels',
          'cms',
          'ops',
          'flips',
          number_of_images=2)

#osv.image(globals(), 'im1')

#osv.image(globals(), 'data1')

im_l = (0, 255)
op = 250
cm = 'jet'
osv.image(globals(), 'data2', 'im_l', 'cm', 'op', number_of_images=1)

osv.graph(globals(), 'data2')

import transform as tr

a = 1
b = 2
c = 3


def t(a, b):
    return a + b


tr.connect_repl_var(globals(), 'a', 'c', 't', 'b')
'''
import drop_down as dd
Example #7
0
    axis=2)
seq_v.graph_pane(globals(), 's', 'spike_data_fd')

spike_data_sd = np.diff(spike_data_fd, axis=2)
spike_data_sd = np.concatenate(
    (spike_data_sd, np.zeros((spike_data.shape[0], spike_data.shape[1], 1))),
    axis=2)

largest_channel_index = np.squeeze(
    np.argwhere(large_channels_full == large_channels[0]))


def get_phase_x_of_channel_for_spike(s):
    return spike_data_sd[s, largest_channel_index, :]


def get_phase_y_of_channel_for_spike(s):
    return spike_data_fd[s, largest_channel_index, :]


phase_x = None
phase_y = None

tr.connect_repl_var(globals(), 's', 'phase_x',
                    'get_phase_x_of_channel_for_spike')
tr.connect_repl_var(globals(), 's', 'phase_y',
                    'get_phase_y_of_channel_for_spike')

s = 1
one_s_v.graph(globals(), 'phase_y', 'phase_x')
bad_lfp_channels = [35, 36, 37]
lfp_channels_used = np.delete(
    np.arange(const.NUMBER_OF_LFP_CHANNELS_IN_BINARY_FILE), bad_lfp_channels)


def spread_lfp_pane(p):
    pane = lfp_data_panes[p, :, :]
    spread = ns_funcs.spread_data(pane, channels_heights, lfp_channels_used)
    spread = np.flipud(spread)
    return spread


pane_data = None
tr.connect_repl_var(globals(), 'pane', 'pane_data', 'spread_lfp_pane')

one_v.graph(globals(), 'pane_data')


camera_pulses, beam_breaks, sounds = \
    sync_funcs.get_time_points_of_events_in_sync_file(data_folder, clean=True,
                                                      cam_ttl_pulse_period=
                                                      const.CAMERA_TTL_PULSES_TIMEPOINT_PERIOD)
points_per_pulse = np.mean(np.diff(camera_pulses))

camera_frames_in_video = csv_funcs.get_true_frame_array(data_folder)
time_point_of_first_video_frame = camera_pulses[camera_frames_in_video][0]

video_frame = 0
video_file = join(data_folder, 'Video.avi')
seq_v.image_sequence(globals(), 'video_frame', 'video_file')
Example #9
0
    np.arange(const.NUMBER_OF_LFP_CHANNELS_IN_BINARY_FILE), bad_lfp_channels)

pane = 100


def spread_lfp_pane(p):
    pane = lfp_data_panes[p, :, :]
    spread = ns_funcs.spread_data(pane, channels_heights, lfp_channels_used)
    spread = np.flipud(spread)
    return spread


pane_data = None
tr.connect_repl_var(globals(), 'pane', 'pane_data', 'spread_lfp_pane')

one_v.graph(globals(), 'pane_data')


def do_nothing(p):
    return p


nothing = None
slider_limits = [0, lfp_data_panes.shape[0] - 1]
sl.connect_repl_var(globals(), 'pane', 'nothing', slider_limits=slider_limits)

# ----------------------------------------------------------------------------------------------------------------------
# SUBSAMPLE THE LFPS WITH DIFFERENT RATIOS AND SAVE THE FILES
# ----------------------------------------------------------------------------------------------------------------------

ds_filename = join(const.base_save_folder, const.rat_folder,
Example #10
0
global traj_y
traj_y = 0


def update_trajectory(f):
    global traj_x
    global traj_y
    traj_x = body_positions[:f, 0]
    traj_y = body_positions[:f, 1]
    return body_positions[:f, :]


traj = None
tr.connect_repl_var(globals(), 'frame', 'traj', 'update_trajectory')

osv.graph(globals(), 'traj_y', 'traj_x')
#  -------------------------------------------------
'''
#  -------------------------------------------------
# FITTING THE MARKERS TO GET BETTER ESTIMATES OF THE LOW LIKELIHOOD ONES
# Fitting 2d surface using multiple markers
# DID NOT WORK

body_markers_positions = markers.loc[:, markers.columns.get_level_values(1).isin(body_parts)]
body_markers_positions = body_markers.loc[:, body_markers.columns.get_level_values(2).isin(['x', 'y'])]


t = np.reshape(body_markers_positions.loc[:3605*120-1, :].values, (3605, 120, 6))
sec = 0
im_lev = [0, 50]
cm = 'jet'