コード例 #1
0
def create_juxta_label(kwik_file,
                       spike_thresholds,
                       num_of_spike_groups=1,
                       adc_channel_used=0,
                       adc_dtype=np.uint16,
                       inter_spike_time_distance=0.002,
                       amp_gain=100,
                       num_of_raw_data_channels=None,
                       spike_channels=None,
                       verbose=True):
    """
    Find the juxta spikes in the extra spike train and label them according to size splitting them into
    num_of_spike_groups groups

    Parameters
    ----------
    kwik_file
    spike_thresholds
    num_of_spike_groups
    adc_channel_used
    adc_dtype
    inter_spike_time_distance
    amp_gain
    num_of_raw_data_channels
    spike_channels
    verbose

    Returns
    -------

    """

    h5file = h5.File(kwik_file, mode='r')
    extra_spike_times = np.array(
        list(h5file['channel_groups/0/spikes/time_samples']))
    h5file.close()

    spikes_used = len(extra_spike_times)
    if verbose:
        print("Total spikes in extra = " + str(len(extra_spike_times)))

    # Get the juxta spikes and generate labels
    # 1) Generate the juxta spike time triggers (and the adc traces in Volts)
    raw_juxta_data_file = r'D:\Data\George\Projects\SpikeSorting\Joana_Paired_128ch\2015-09-03\Data' + \
                          r'\adc2015-09-03T21_18_47.bin'
    raw_data_patch = ephys.load_raw_event_trace(raw_juxta_data_file,
                                                number_of_channels=8,
                                                channel_used=adc_channel_used,
                                                dtype=adc_dtype)
    juxta_spike_triggers, juxta_spike_peaks, juxta_spike_data_in_V = tf.create_spike_triggered_events(
        raw_data_patch.dataMatrix,
        threshold=spike_thresholds,
        inter_spike_time_distance=inter_spike_time_distance,
        amp_gain=amp_gain)
    num_of_spikes = len(juxta_spike_triggers)
    if verbose:
        print('Total spikes in Juxta = ' + str(num_of_spikes))

    # 2) Seperate the juxta spikes into a number of groups according to their size
    juxta_spikes_grouped, juxta_spike_peaks_grouped, juxta_spike_triggers_grouped_withnans,\
            juxta_spike_peaks_grouped_withnans, spike_thresholds_groups = \
        split_juxta_spikes_into_groups_by_size(num_of_spike_groups=num_of_spike_groups,
                                                   juxta_spike_peaks=juxta_spike_peaks,
                                                   juxta_spike_triggers=juxta_spike_triggers)

    # 3) Find the common spikes between the extra apikes and the juxta spikes for all the juxta spikes and for all the
    # sub groups of juxta spikes and group the good spikes
    common_spikes_grouped = {}
    juxta_spikes_not_found_grouped = {}
    indices_of_common_extra_spikes_grouped = {}
    for g in range(1, num_of_spike_groups + 1):
        common_spikes_grouped[g], indices_of_common_extra_spikes_grouped[g], juxta_spikes_not_found_grouped[g] = \
             ut.find_points_in_array_with_jitter(array_of_points_to_be_found=juxta_spikes_grouped[g],
                                                 array_to_search=extra_spike_times[:spikes_used],
                                                 jitter_around_each_point=7)
    if spike_channels is not None and num_of_raw_data_channels is not None:
        common_spikes_grouped[g], indices_of_common_extra_spikes_grouped[g] \
            = select_spikes_in_certain_channels(spike_thresholds, common_spikes_grouped[g],
                                                indices_of_common_extra_spikes_grouped[g],
                                                spike_channels, num_of_raw_data_channels)

    # 5) Get the t-sne indices of the grouped juxta spikes
    indices_of_data_for_tsne = range(spikes_used)
    juxta_cluster_indices_grouped = {}
    for g in range(0, num_of_spike_groups):
        juxta_cluster_indices_temp = np.intersect1d(
            indices_of_data_for_tsne,
            indices_of_common_extra_spikes_grouped[g + 1])
        juxta_cluster_indices_grouped[g] = [
            i for i in np.arange(0, len(indices_of_data_for_tsne)) if len(
                np.where(juxta_cluster_indices_temp ==
                         indices_of_data_for_tsne[i])[0])
        ]
        if verbose and spike_channels is not None:
            print('Labeled after cleaning = ' +
                  str(len(juxta_cluster_indices_grouped[g])))

    return juxta_cluster_indices_grouped, spike_thresholds_groups
                         'c': 'ivm_data_filtered_continous_cell{}.dat',
                         'k': 'ivm_data_filtered_klusta_spikes_cell{}.dat',
                         'p': 'patch_data_cell{}.dat'}



# Generate the spike time triggers (and the adc traces in Volts) for all cells
all_cells_spike_triggers = {}
all_cells_spike_data_in_V = {}
for i in np.arange(0, len(good_cells)):
    raw_data_file_pipette = os.path.join(data_folder, 'adc'+date+'T'+cell_capture_times[good_cells[i]]+'.bin')

    raw_data_patch = ephys.load_raw_event_trace(raw_data_file_pipette, number_of_channels=8,
                                                  channel_used=adc_channel_used, dtype=adc_dtype)
    spike_triggers, spike_peaks, spike_data_in_V = tf.create_spike_triggered_events(raw_data_patch.dataMatrix,
                                                                   threshold=spike_thresholds[good_cells[i]],
                                                                   inter_spike_time_distance=inter_spike_time_distance,
                                                                   amp_gain=amp_gain)
    all_cells_spike_triggers[good_cells[i]] = spike_triggers
    all_cells_spike_data_in_V[good_cells[i]] = spike_data_in_V

    print(len(spike_triggers))



# Generate the (channels x time_points x spikes) high passed extracellular recordings datasets for all cells
all_cells_ivm_filtered_data = {}
data_to_load = 't'
for i in np.arange(0, len(good_cells)):
    raw_data_file_ivm = os.path.join(data_folder, 'amplifier'+date+'T'+cell_capture_times[good_cells[i]]+'.bin')

    raw_data_ivm = ephys.load_raw_data(raw_data_file_ivm, numchannels=num_ivm_channels, dtype=amp_dtype)
コード例 #3
0
def create_juxta_label(kwik_file, spike_thresholds, num_of_spike_groups=1,
                       adc_channel_used=0, adc_dtype=np.uint16, inter_spike_time_distance=0.002,
                       amp_gain=100,
                       num_of_raw_data_channels=None,
                       spike_channels=None,
                       verbose=True):
    """
    Find the juxta spikes in the extra spike train and label them according to size splitting them into
    num_of_spike_groups groups

    Parameters
    ----------
    kwik_file
    spike_thresholds
    num_of_spike_groups
    adc_channel_used
    adc_dtype
    inter_spike_time_distance
    amp_gain
    num_of_raw_data_channels
    spike_channels
    verbose

    Returns
    -------

    """

    h5file = h5.File(kwik_file, mode='r')
    extra_spike_times = np.array(list(h5file['channel_groups/0/spikes/time_samples']))
    h5file.close()

    spikes_used = len(extra_spike_times)
    if verbose:
        print("Total spikes in extra = " + str(len(extra_spike_times)))


    # Get the juxta spikes and generate labels
    # 1) Generate the juxta spike time triggers (and the adc traces in Volts)
    raw_juxta_data_file = r'D:\Data\George\Projects\SpikeSorting\Joana_Paired_128ch\2015-09-03\Data' + \
                          r'\adc2015-09-03T21_18_47.bin'
    raw_data_patch = ephys.load_raw_event_trace(raw_juxta_data_file, number_of_channels=8,
                                                  channel_used=adc_channel_used, dtype=adc_dtype)
    juxta_spike_triggers, juxta_spike_peaks, juxta_spike_data_in_V = tf.create_spike_triggered_events(raw_data_patch.dataMatrix,
                                                                       threshold=spike_thresholds,
                                                                       inter_spike_time_distance=inter_spike_time_distance,
                                                                       amp_gain=amp_gain)
    num_of_spikes = len(juxta_spike_triggers)
    if verbose:
        print('Total spikes in Juxta = ' + str(num_of_spikes))



    # 2) Seperate the juxta spikes into a number of groups according to their size
    juxta_spikes_grouped, juxta_spike_peaks_grouped, juxta_spike_triggers_grouped_withnans,\
            juxta_spike_peaks_grouped_withnans, spike_thresholds_groups = \
        split_juxta_spikes_into_groups_by_size(num_of_spike_groups=num_of_spike_groups,
                                                   juxta_spike_peaks=juxta_spike_peaks,
                                                   juxta_spike_triggers=juxta_spike_triggers)

    # 3) Find the common spikes between the extra apikes and the juxta spikes for all the juxta spikes and for all the
    # sub groups of juxta spikes and group the good spikes
    common_spikes_grouped = {}
    juxta_spikes_not_found_grouped = {}
    indices_of_common_extra_spikes_grouped = {}
    for g in range(1, num_of_spike_groups+1):
        common_spikes_grouped[g], indices_of_common_extra_spikes_grouped[g], juxta_spikes_not_found_grouped[g] = \
             ut.find_points_in_array_with_jitter(array_of_points_to_be_found=juxta_spikes_grouped[g],
                                                 array_to_search=extra_spike_times[:spikes_used],
                                                 jitter_around_each_point=7)
    if spike_channels is not None and num_of_raw_data_channels is not None:
        common_spikes_grouped[g], indices_of_common_extra_spikes_grouped[g] \
            = select_spikes_in_certain_channels(spike_thresholds, common_spikes_grouped[g],
                                                indices_of_common_extra_spikes_grouped[g],
                                                spike_channels, num_of_raw_data_channels)


    # 5) Get the t-sne indices of the grouped juxta spikes
    indices_of_data_for_tsne = range(spikes_used)
    juxta_cluster_indices_grouped = {}
    for g in range(0, num_of_spike_groups):
        juxta_cluster_indices_temp = np.intersect1d(indices_of_data_for_tsne, indices_of_common_extra_spikes_grouped[g+1])
        juxta_cluster_indices_grouped[g] = [i for i in np.arange(0, len(indices_of_data_for_tsne)) if
                                 len(np.where(juxta_cluster_indices_temp == indices_of_data_for_tsne[i])[0])]
        if verbose and spike_channels is not None:
                print('Labeled after cleaning = ' + str(len(juxta_cluster_indices_grouped[g])))

    return juxta_cluster_indices_grouped, spike_thresholds_groups
コード例 #4
0
                         'c': 'ivm_data_filtered_continous_cell{}.dat',
                         'k': 'ivm_data_filtered_klusta_spikes_cell{}.dat',
                         'p': 'patch_data_cell{}.dat'}



# Generate the spike time triggers (and the adc traces in Volts) for all cells
all_cells_spike_triggers = {}
all_cells_spike_data_in_V = {}
for i in np.arange(0, len(good_cells)):
    raw_data_file_pipette = os.path.join(data_folder, 'adc'+date+'T'+cell_capture_times[good_cells[i]]+'.bin')

    raw_data_patch = ephys.load_raw_event_trace(raw_data_file_pipette, number_of_channels=8,
                                                  channel_used=adc_channel_used, dtype=adc_dtype)
    spike_triggers, spike_peaks, spike_data_in_V = tf.create_spike_triggered_events(raw_data_patch.dataMatrix,
                                                                   threshold=spike_thresholds[good_cells[i]],
                                                                   inter_spike_time_distance=inter_spike_time_distance,
                                                                   amp_gain=amp_gain)
    all_cells_spike_triggers[good_cells[i]] = spike_triggers
    all_cells_spike_data_in_V[good_cells[i]] = spike_data_in_V

    print(len(spike_triggers))



# Generate the (channels x time_points x spikes) high passed extracellular recordings datasets for all cells
all_cells_ivm_filtered_data = {}
data_to_load = 't'
for i in np.arange(0, len(good_cells)):
    raw_data_file_ivm = os.path.join(data_folder, 'amplifier'+date+'T'+cell_capture_times[good_cells[i]]+'.bin')

    raw_data_ivm = ephys.load_raw_data(raw_data_file_ivm, numchannels=num_ivm_channels, dtype=amp_dtype)
コード例 #5
0
ic_channel = 5
ec_channels = [1, 2, 3, 4]

# Make the binary data file for klustakwik--
extra_data = data.dataMatrix[ec_channels, :]
extra_data_to_bin = np.reshape(extra_data.T, (extra_data.size))
extra_data_to_bin.tofile(
    join(analysis_folder, 'KlustaKwik', cell, full_cell_name + '_extra.dat'))
# ------------------------------------------

sampling_freq = 10000

juxta_spike_triggers, juxta_spike_peaks, juxta_spike_data_in_V = \
 tf.create_spike_triggered_events(data_raw_spikes=data.dataMatrix[ic_channel, :], threshold=16e-5,
                                  inter_spike_time_distance=0.005, amp_gain=1000,
                                  sampling_freq=sampling_freq, amp_y_digitization=2**16, amp_y_range=20)
num_of_spikes = len(juxta_spike_triggers)

# ---------------------------------------
# DO THE KLUSTA HERE---------------------
# ---------------------------------------

# Grab the spike times from the .kwik file
filename_kwik = join(analysis_folder, 'KlustaKwik', cell,
                     full_cell_name + '.kwik')
h5file = h5.File(filename_kwik, mode='r')
negative_extra_spike_times = np.array(
    list(h5file['channel_groups/0/spikes/time_samples']))
h5file.close()
print('All extra spikes = {}'.format(len(negative_extra_spike_times)))