def create_files_for_code(code):
    dir_and_file_name = ensure_dir(
        join(
            basic_dir,
            geometry_dir.format(channel_number[code],
                                geometry_descriptions[code]),
            prb_filename.format(geometry_descriptions[code])))

    all_electrodes, channel_positions = pi.create_128channels_imec_prb(
        filename=dir_and_file_name,
        bad_channels=bad_channels[code],
        steps_r=steps_r[code],
        steps_c=steps_c[code])

    new_param_filename = join(
        basic_dir,
        geometry_dir.format(channel_number[code], geometry_descriptions[code]),
        'threshold_6_5std.prm')
    copyfile(param_filename, new_param_filename)
    text_in_prm = r"experiment_name = 'threshold_6_5std'" + '\n'
    text_in_prm = text_in_prm + "prb_file = r'" + join(basic_dir,
                                                       dir_and_file_name) + "'"
    file = open(new_param_filename, 'r+')
    content = file.read()
    file.seek(0, 0)
    file.write(text_in_prm + '\n' + content)
    file.close()
def create_files_for_code(code):
    dir_and_file_name = ensure_dir(join(basic_dir, geometry_dir.format(channel_number[code],
                                        geometry_descriptions[code]),
                                        prb_filename.format(geometry_descriptions[code])))

    all_electrodes, channel_positions = pi.create_128channels_imec_prb(filename=dir_and_file_name,
                                                                       bad_channels=bad_channels[code],
                                                                       steps_r=steps_r[code], steps_c=steps_c[code])

    new_param_filename = join(basic_dir, geometry_dir.format(channel_number[code],
                                                             geometry_descriptions[code]), 'threshold_6_5std.prm')
    copyfile(param_filename, new_param_filename)
    text_in_prm = r"experiment_name = 'threshold_6_5std'" + '\n'
    text_in_prm = text_in_prm + "prb_file = r'" + join(basic_dir, dir_and_file_name) + "'"
    file = open(new_param_filename, 'r+')
    content = file.read()
    file.seek(0, 0)
    file.write(text_in_prm + '\n' + content)
    file.close()
Exemple #3
0
import numpy as np
import matplotlib.pyplot as plt
import Layouts.Probes.probes_imec as pr_im
import BrainDataAnalysis.Graphics.ploting_functions as pf
import mne.filter as filters
import scipy.ndimage.measurements as sp_m

window = 0
window_size_secs = 10
filtered_data_type = np.float64
sampling_freq = 30000
high_pass_freq = 500
window_size = int(window_size_secs * sampling_freq)
iir_params = {'order': 4, 'ftype': 'butter', 'padlen': 0}
num_of_channels = np.shape(raw_data_ivm.dataMatrix)[0]
electrode_structure, channel_positions = pr_im.create_128channels_imec_prb()

# Get the high passed data for the current time window
temp_unfiltered = raw_data_ivm.dataMatrix[:,
                                          window * window_size:(window + 1) *
                                          window_size]
temp_unfiltered = temp_unfiltered.astype(filtered_data_type)
temp_filtered = filters.high_pass_filter(temp_unfiltered,
                                         sampling_freq,
                                         high_pass_freq,
                                         method='iir',
                                         iir_params=iir_params)

# Find thresholds
stdvs = np.median(np.abs(temp_filtered) / 0.6745, axis=1)
# Single Cell comparison between Klusta and tsne
# 0) Create the required .dat file and the probe .prb file to throw into klustakwik (i.e. the phy module)
spikes_to_include = num_of_spikes
fin_time_point = spike_triggers[spikes_to_include] + 500
start_time_point = 0
time_limits = [start_time_point, fin_time_point]

raw_data_file_ivm = os.path.join(data_folder, 'amplifier'+date+'T'+cell_capture_times+'.bin')
raw_data_ivm = ephys.load_raw_data(raw_data_file_ivm, numchannels=num_ivm_channels, dtype=amp_dtype)
file_dat = os.path.join(analysis_folder, r'klustakwik\raw_data_ivm_klusta.dat')

klusta.make_dat_file(raw_data_ivm.dataMatrix, filename=file_dat, num_channels=num_ivm_channels, time_limits=time_limits)

file_prb = os.path.join(analysis_folder, r'klustakwik\128ch_passive_imec.prb')
electrode_structure = pr_imec.create_128channels_imec_prb(file_prb)



# 0.5) Grab the mask and the PCA components for all spikes from the .kwx file
filename = r'D:\Data\George\Projects\SpikeSorting\Joana_Paired_128ch\2015-09-03\Analysis\klustakwik\threshold_6_5std\threshold_6_5std.kwx'
h5file = h5.File(filename, mode='r')
pca_and_masks = np.array(list(h5file['channel_groups/0/features_masks']))
masks = np.array(pca_and_masks[:, :, 1])
pca_features = np.array(pca_and_masks[:, :, 0])
masked_pca_features = pca_features * masks



# 1) Grab the spike times from the .kwik file
filename = r'D:\Data\George\Projects\SpikeSorting\Joana_Paired_128ch\2015-09-03\Analysis\klustakwik\threshold_6_5std\threshold_6_5std.kwik'
import mne.filter as filters
import scipy.ndimage.measurements as sp_m





window = 0
window_size_secs = 10
filtered_data_type = np.float64
sampling_freq = 30000
high_pass_freq = 500
window_size = int(window_size_secs * sampling_freq)
iir_params = {'order': 4, 'ftype': 'butter', 'padlen': 0}
num_of_channels = np.shape(raw_data_ivm.dataMatrix)[0]
electrode_structure, channel_positions = pr_im.create_128channels_imec_prb()


# Get the high passed data for the current time window
temp_unfiltered = raw_data_ivm.dataMatrix[:, window * window_size:(window + 1) * window_size]
temp_unfiltered = temp_unfiltered.astype(filtered_data_type)
temp_filtered = filters.high_pass_filter(temp_unfiltered,
                                         sampling_freq, high_pass_freq, method='iir',
                                             iir_params=iir_params)


# Find thresholds
stdvs  = np.median(np.abs(temp_filtered)/0.6745, axis=1)

large_thresholds = np.zeros(np.shape(temp_filtered))
small_thresholds = np.zeros(np.shape(temp_filtered))
Exemple #6
0
# Single Cell comparison between Klusta and tsne
# 0) Create the required .dat file and the probe .prb file to throw into klustakwik (i.e. the phy module)
spikes_to_include = num_of_spikes
fin_time_point = spike_triggers[spikes_to_include] + 500
start_time_point = 0
time_limits = [start_time_point, fin_time_point]

raw_data_file_ivm = os.path.join(data_folder, 'amplifier'+date+'T'+cell_capture_times+'.bin')
raw_data_ivm = ephys.load_raw_data(raw_data_file_ivm, numchannels=num_ivm_channels, dtype=amp_dtype)
file_dat = os.path.join(analysis_folder, r'klustakwik\raw_data_ivm_klusta.dat')

klusta.make_dat_file(raw_data_ivm.dataMatrix, filename=file_dat, num_channels=num_ivm_channels, time_limits=time_limits)

file_prb = os.path.join(analysis_folder, r'klustakwik\128ch_passive_imec.prb')
electrode_structure = pr_imec.create_128channels_imec_prb(file_prb)



# 0.5) Grab the mask and the PCA components for all spikes from the .kwx file
filename = os.path.join(analysis_folder, 'klustakwik', 'threshold_6_5std', r'threshold_6_5std.kwx')
h5file = h5.File(filename, mode='r')
pca_and_masks = np.array(list(h5file['channel_groups/0/features_masks']))
masks = np.array(pca_and_masks[:, :, 1])
pca_features = np.array(pca_and_masks[:, :, 0])
masked_pca_features = pca_features * masks



# 1) Grab the spike times from the .kwik file
filename = os.path.join(analysis_folder, 'klustakwik', 'threshold_6_5std', r'threshold_6_5std.kwik')