def create_128channels_imec_prb(filename=None, bad_channels=None):

    r1 = np.array([103,	101, 99,	97,	95,	93,	91,	89,	87,	70,	66,	84,	82,	80,	108,	110,	47,	45,	43,	41,	1,61,	57,
                   36,	34,	32,	30,	28,	26,	24,	22,	20])
    r2 = np.array([106, 104, 115, 117, 119, 121, 123, 125, 127, 71, 67, 74, 76, 78, 114, 112,
                   49, 51, 53, 55, 2, 62, 58, 4, 6, 8, 10, 12, 14, 21, 19, 16])
    r3 = np.array([102, 100, 98, 96, 94, 92, 90, 88, 86, 72, 68, 65, 85, 83, 81, 111, 46, 44, 42, 40, 38, 63, 59,
                   39, 37, 35, 33, 31, 29, 27, 25, 23])
    r4 = np.array([109, 107, 105, 116, 118, 120, 122, 124, 126, 73, 69, 64, 75, 77, 79, 113,
                   48, 50, 52, 54, 56, 0, 60, 3, 5, 7, 9, 11, 13, 15, 18,-1])

    all_electrodes_concat = np.concatenate((r1, r2, r3, r4))
    all_electrodes = all_electrodes_concat.reshape((4, 32))
    all_electrodes = np.flipud(all_electrodes.T)


    if filename is not None:
        prb_gen.generate_prb_file(filename=filename, all_electrodes_array=all_electrodes, channel_number=128)


    electrode_coordinate_grid = list(itertools.product(np.arange(1, 32), np.arange(1, 5)))
    electrode_coordinate_grid = [tuple(reversed(x)) for x in electrode_coordinate_grid]
    electrode_amplifier_index_on_grid = all_electrodes_concat
    electrode_amplifier_name_on_grid = np.array(["Int" + str(x) for x in electrode_amplifier_index_on_grid])
    indices_arrays = [electrode_amplifier_index_on_grid.tolist(), electrode_amplifier_name_on_grid.tolist()]
    indices_tuples = list(zip(*indices_arrays))
    channel_position_indices = pd.MultiIndex.from_tuples(indices_tuples, names=['Numbers', 'Strings'])
    channel_positions = pd.Series(electrode_coordinate_grid, index=channel_position_indices)
    channel_positions.columns = ['Positions']
    channel_positions = channel_positions.reset_index(level=None, drop=False, name='Positions')
    if bad_channels is not None:
        channel_positions = channel_positions[~channel_positions.Numbers.isin(bad_channels)]

    return all_electrodes, channel_positions
def create_all_electrodes(filename=None, bad_channels=None):

    r1 = np.array([
        103, 101, 99, 97, 95, 93, 91, 89, 87, 70, 66, 84, 82, 80, 108, 110, 47,
        45, 43, 41, 1, 61, 57, 36, 34, 32, 30, 28, 26, 24, 22, 20
    ])
    r2 = np.array([
        106, 104, 115, 117, 119, 121, 123, 125, 127, 71, 67, 74, 76, 78, 114,
        112, 49, 51, 53, 55, 2, 62, 58, 4, 6, 8, 10, 12, 14, 21, 19, 16
    ])
    r3 = np.array([
        102, 100, 98, 96, 94, 92, 90, 88, 86, 72, 68, 65, 85, 83, 81, 111, 46,
        44, 42, 40, 38, 63, 59, 39, 37, 35, 33, 31, 29, 27, 25, 23
    ])
    r4 = np.array([
        109, 107, 105, 116, 118, 120, 122, 124, 126, 73, 69, 64, 75, 77, 79,
        113, 48, 50, 52, 54, 56, 0, 60, 3, 5, 7, 9, 11, 13, 15, 18, -1
    ])

    all_electrodes_concat = np.concatenate((r1, r2, r3, r4))
    all_electrodes = all_electrodes_concat.reshape((4, 32))
    all_electrodes = np.flipud(all_electrodes.T)

    if filename is not None:
        prb_gen.generate_prb_file(filename=filename,
                                  all_electrodes_array=all_electrodes,
                                  channel_number=128)

    return all_electrodes
Esempio n. 3
0
def create_32channels_nn_prb(filename=None, bad_channels=None):
    """
    This function produces a grid with the electrodes positions of
    Neuronexus A1x32-Poly3-5mm-25s-177-CM32 silicone probe
    Parameters
    ----------
    filename -- the filename (with path) of the .prb file for klustakwik
    bad_channels -- a list or numpy array with channels you may want to disregard
    Returns
    -------
    all_electrodes --
    channel_positions -- a Pandas Series with the electrodes positions (in
    two dimensions)
    """

    electrode_amplifier_index_on_grid = np.array([-1, 0, -1,
                                                  -1, -1, -1,
                                                  -1, 31, -1,
                                                  24, -1, 7,
                                                  -1, 1, -1,
                                                  21, -1, 10,
                                                  -1, 30, -1,
                                                  25, -1, 6,
                                                  -1, 15, -1,
                                                  20, -1, 11,
                                                  -1, 16, -1,
                                                  26, -1, 5,
                                                  -1, 14, -1,
                                                  19, -1, 12,
                                                  -1, 17, -1,
                                                  27, -1, 4,
                                                  -1, 8, -1,
                                                  18, -1, 13,
                                                  -1, 23, -1,
                                                  28, -1, 3,
                                                  -1, 9, -1,
                                                  29, -1, 2,
                                                  -1, 22, -1])


    all_electrodes = electrode_amplifier_index_on_grid.reshape((23, 3))
    if filename is not None:
        prb_gen.generate_prb_file(filename=filename, all_electrodes_array=all_electrodes, channel_number=32,
                                  steps_r=3, steps_c=3)


    electrode_coordinate_grid = list(itertools.product(np.arange(1, 24), np.arange(1, 4)))
    electrode_coordinate_grid = [tuple(reversed(x)) for x in electrode_coordinate_grid]
    electrode_amplifier_name_on_grid = np.array(["Int" + str(x) for x in electrode_amplifier_index_on_grid])
    indices_arrays = [electrode_amplifier_index_on_grid.tolist(), electrode_amplifier_name_on_grid.tolist()]
    indices_tuples = list(zip(*indices_arrays))
    channel_position_indices = pd.MultiIndex.from_tuples(indices_tuples, names=['Numbers', 'Strings'])
    channel_positions = pd.Series(electrode_coordinate_grid, index=channel_position_indices)
    channel_positions.columns = ['Positions']
    channel_positions = channel_positions.reset_index(level=None, drop=False, name='Positions')
    if bad_channels is not None:
        channel_positions = channel_positions[~channel_positions.Numbers.isin(bad_channels)]

    return all_electrodes, channel_positions
Esempio n. 4
0
def create_128channels_imec_prb(filename=None, bad_channels=None):

    r1 = np.array([
        103, 101, 99, 97, 95, 93, 91, 89, 87, 70, 66, 84, 82, 80, 108, 110, 47,
        45, 43, 41, 1, 61, 57, 36, 34, 32, 30, 28, 26, 24, 22, 20
    ])
    r2 = np.array([
        106, 104, 115, 117, 119, 121, 123, 125, 127, 71, 67, 74, 76, 78, 114,
        112, 49, 51, 53, 55, 2, 62, 58, 4, 6, 8, 10, 12, 14, 21, 19, 16
    ])
    r3 = np.array([
        102, 100, 98, 96, 94, 92, 90, 88, 86, 72, 68, 65, 85, 83, 81, 111, 46,
        44, 42, 40, 38, 63, 59, 39, 37, 35, 33, 31, 29, 27, 25, 23
    ])
    r4 = np.array([
        109, 107, 105, 116, 118, 120, 122, 124, 126, 73, 69, 64, 75, 77, 79,
        113, 48, 50, 52, 54, 56, 0, 60, 3, 5, 7, 9, 11, 13, 15, 18, -1
    ])

    all_electrodes_concat = np.concatenate((r1, r2, r3, r4))
    all_electrodes = all_electrodes_concat.reshape((4, 32))
    all_electrodes = np.flipud(all_electrodes.T)

    if filename is not None:
        prb_gen.generate_prb_file(filename=filename,
                                  all_electrodes_array=all_electrodes,
                                  channel_number=128)

    electrode_coordinate_grid = list(
        itertools.product(np.arange(1, 32), np.arange(1, 5)))
    electrode_coordinate_grid = [
        tuple(reversed(x)) for x in electrode_coordinate_grid
    ]
    electrode_amplifier_index_on_grid = all_electrodes_concat
    electrode_amplifier_name_on_grid = np.array(
        ["Int" + str(x) for x in electrode_amplifier_index_on_grid])
    indices_arrays = [
        electrode_amplifier_index_on_grid.tolist(),
        electrode_amplifier_name_on_grid.tolist()
    ]
    indices_tuples = list(zip(*indices_arrays))
    channel_position_indices = pd.MultiIndex.from_tuples(
        indices_tuples, names=['Numbers', 'Strings'])
    channel_positions = pd.Series(electrode_coordinate_grid,
                                  index=channel_position_indices)
    channel_positions.columns = ['Positions']
    channel_positions = channel_positions.reset_index(level=None,
                                                      drop=False,
                                                      name='Positions')
    if bad_channels is not None:
        channel_positions = channel_positions[~channel_positions.Numbers.
                                              isin(bad_channels)]

    return all_electrodes, channel_positions
def create_1440channels_neuroseeker_prb(base_info_folder,
                                        connected_channels_filename,
                                        prb_filename=None):
    x_coords = np.squeeze(
        np.load(join(base_info_folder,
                     'neuroseeker_channel_coordinates_x.npy')))
    y_coords = np.squeeze(
        np.load(join(base_info_folder,
                     'neuroseeker_channel_coordinates_y.npy')))
    connected = np.squeeze(
        np.load(join(base_info_folder, connected_channels_filename)))
    bad_channels = np.squeeze(np.argwhere(connected == False).astype(np.int))

    r1 = np.array([[i, i + 1] for i in np.arange(0, 1433, 8)])
    r1 = r1.reshape(r1.size)
    r2 = np.array([[i, i + 1] for i in np.arange(2, 1435, 8)])
    r2 = r2.reshape(r1.size)
    r3 = np.array([[i, i + 1] for i in np.arange(4, 1437, 8)])
    r3 = r3.reshape(r1.size)
    r4 = np.array([[i, i + 1] for i in np.arange(6, 1439, 8)])
    r4 = r4.reshape(r1.size)

    all_electrodes_concat = np.concatenate((r1, r2, r3, r4))
    all_electrodes = all_electrodes_concat.reshape((4, 360))

    if prb_filename is not None:
        prb_gen.generate_prb_file(filename=prb_filename,
                                  all_electrodes_array=all_electrodes)

    electrode_coordinate_grid = [i for i in list(zip(x_coords, y_coords))]

    electrode_amplifier_index_on_grid = np.arange(
        len(electrode_coordinate_grid))
    electrode_amplifier_name_on_grid = np.array(
        ["Int" + str(x) for x in electrode_amplifier_index_on_grid])
    indices_arrays = [
        electrode_amplifier_index_on_grid.tolist(),
        electrode_amplifier_name_on_grid.tolist()
    ]
    indices_tuples = list(zip(*indices_arrays))
    channel_position_indices = pd.MultiIndex.from_tuples(
        indices_tuples, names=['Numbers', 'Strings'])
    channel_positions = pd.Series(electrode_coordinate_grid,
                                  index=channel_position_indices)
    channel_positions.columns = ['Positions']
    channel_positions = channel_positions.reset_index(level=None,
                                                      drop=False,
                                                      name='Positions')
    channel_positions = channel_positions[~channel_positions.Numbers.
                                          isin(bad_channels)]

    return all_electrodes, channel_positions
def create_128channels_imec_prb(filename=None, bad_channels=None):

    r1 = np.array([103,	101, 99,	97,	95,	93,	91,	89,	87,	70,	66,	84,	82,	80,	108,	110,	47,	45,	43,	41,	1,61,	57,
                   36,	34,	32,	30,	28,	26,	24,	22,	20])
    r2 = np.array([106, 104, 115, 117, 119, 121, 123, 125, 127, 71, 67, 74, 76, 78, 114, 112,
                   49, 51, 53, 55, 2, 62, 58, 4, 6, 8, 10, 12, 14, 21, 19, 16])
    r3 = np.array([102, 100, 98, 96, 94, 92, 90, 88, 86, 72, 68, 65, 85, 83, 81, 111, 46, 44, 42, 40, 38, 63, 59,
                   39, 37, 35, 33, 31, 29, 27, 25, 23])
    r4 = np.array([109, 107, 105, 116, 118, 120, 122, 124, 126, 73, 69, 64, 75, 77, 79, 113,
                   48, 50, 52, 54, 56, 0, 60, 3, 5, 7, 9, 11, 13, 15, 18,-1])

    all_electrodes_concat = np.concatenate((r1, r2, r3, r4))
    all_electrodes = all_electrodes_concat.reshape((4, 32))
    all_electrodes = np.flipud(all_electrodes.T)

    if filename is not None:
        prb_gen.generate_prb_file(filename=filename, all_electrodes_array=all_electrodes, channel_number=128)

    return all_electrodes
def create_32channels_nn_prb(filename=None, bad_channels=None):
    """
    This function produces a grid with the electrodes positions of
    Neuronexus A1x32-Poly3-5mm-25s-177-CM32 silicone probe

    Parameters
    ----------
    filename -- the filename (with path) of the .prb file for klustakwik
    bad_channels -- a list or numpy array with channels you may want to disregard

    Returns
    -------
    all_electrodes --
    channel_positions -- a Pandas Series with the electrodes positions (in
    two dimensions)
    """

    electrode_amplifier_index_on_grid = np.array([-1, 0, -1,
                                                  -1, -1, -1,
                                                  -1, 31, -1,
                                                  24, -1, 7,
                                                  -1, 1, -1,
                                                  21, -1, 10,
                                                  -1, 30, -1,
                                                  25, -1, 6,
                                                  -1, 15, -1,
                                                  20, -1, 11,
                                                  -1, 16, -1,
                                                  26, -1, 5,
                                                  -1, 14, -1,
                                                  19, -1, 12,
                                                  -1, 17, -1,
                                                  27, -1, 4,
                                                  -1, 8, -1,
                                                  18, -1, 13,
                                                  -1, 23, -1,
                                                  28, -1, 3,
                                                  -1, 9, -1,
                                                  29, -1, 2,
                                                  -1, 22, -1])


    all_electrodes = electrode_amplifier_index_on_grid.reshape((23, 3))
    if filename is not None:
        prb_gen.generate_prb_file(filename=filename, all_electrodes_array=all_electrodes, channel_number=32,
                                  steps_r=3, steps_c=3)


    electrode_coordinate_grid = list(itertools.product(np.arange(1, 24), np.arange(1, 4)))
    electrode_coordinate_grid = [tuple(reversed(x)) for x in electrode_coordinate_grid]
    electrode_amplifier_name_on_grid = np.array(["Int" + str(x) for x in electrode_amplifier_index_on_grid])
    indices_arrays = [electrode_amplifier_index_on_grid.tolist(), electrode_amplifier_name_on_grid.tolist()]
    indices_tuples = list(zip(*indices_arrays))
    channel_position_indices = pd.MultiIndex.from_tuples(indices_tuples, names=['Numbers', 'Strings'])
    channel_positions = pd.Series(electrode_coordinate_grid, index=channel_position_indices)
    channel_positions.columns = ['Positions']
    channel_positions = channel_positions.reset_index(level=None, drop=False, name='Positions')
    if bad_channels is not None:
        channel_positions = channel_positions[~channel_positions.Numbers.isin(bad_channels)]

    return all_electrodes, channel_positions
def create_256channels_imec_prb(filename=None,
                                steps_r=2,
                                steps_c=2,
                                bad_channels=None):
    r1 = np.array(
        [163, 232, 236, 240, 249, 199, 193, 220, 36, 61, 1, 8, 12, 47, 41])
    r2 = np.array(
        [162, 212, 206, 244, 202, 198, 229, 222, 29, 25, 2, 5, 16, 46, 42])
    r3 = np.array(
        [217, 211, 207, 245, 251, 255, 228, 225, 35, 60, 55, 9, 17, 20, 95])
    r4 = np.array(
        [161, 233, 237, 241, 203, 197, 192, 223, 37, 58, 54, 6, 51, 45, 40])
    r5 = np.array(
        [216, 234, 205, 242, 201, 195, 218, 224, 28, 24, 3, 13, 50, 21, 39])
    r6 = np.array(
        [215, 210, 204, 246, 252, 231, 227, 32, 63, 59, 53, 14, 18, 22, 94])
    r7 = np.array(
        [160, 235, 238, 247, 200, 196, 219, 33, 27, 57, 7, 10, 48, 44, 38])
    r8 = np.array(
        [213, 209, 239, 248, 253, 194, 221, 30, 26, 0, 4, 11, 49, 43, 93])
    r9 = np.array([
        168, 159, 154, 181, 145, 140, 191, 131, 125, 120, 67, 111, 106, 77, 97
    ])
    r10 = np.array([
        172, 175, 153, 182, 185, 139, 167, 164, 90, 119, 114, 71, 105, 100, 81
    ])
    r11 = np.array(
        [169, 157, 179, 148, 143, 189, 134, 129, 123, 65, 68, 109, 75, 78, 84])
    r12 = np.array([
        173, 156, 151, 183, 142, 137, 166, 128, 122, 117, 69, 108, 103, 79, 85
    ])
    r13 = np.array([
        170, 176, 152, 147, 186, 138, 133, 127, 89, 118, 113, 72, 104, 99, 82
    ])
    r14 = np.array([
        171, 177, 180, 146, 187, 190, 132, 126, 121, 66, 112, 107, 76, 98, 86
    ])
    r15 = np.array(
        [174, 155, 150, 184, 141, 136, 165, 91, 88, 116, 70, 73, 102, 80, 83])
    r16 = np.array([
        158, 178, 149, 144, 188, 135, 130, 124, 64, 115, 110, 74, 101, 96, 87
    ])
    r17 = np.array(
        [214, 208, 243, 250, 254, 230, 226, 34, 62, 56, 52, 15, 19, 23, 92])

    all_electrodes_concat = np.concatenate(
        (r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16,
         r17))
    all_electrodes = all_electrodes_concat.reshape((17, 15))

    #all_electrodes = np.flipud(all_electrodes.T)

    electrode_coordinate_grid = list(
        itertools.product(np.arange(1, 18), np.arange(1, 16)))
    electrode_coordinate_grid = [
        tuple(reversed(x)) for x in electrode_coordinate_grid
    ]
    electrode_amplifier_index_on_grid = all_electrodes_concat
    electrode_amplifier_name_on_grid = np.array(
        ["Int" + str(x) for x in electrode_amplifier_index_on_grid])
    indices_arrays = [
        electrode_amplifier_index_on_grid.tolist(),
        electrode_amplifier_name_on_grid.tolist()
    ]
    indices_tuples = list(zip(*indices_arrays))

    channel_position_indices = pd.MultiIndex.from_tuples(
        indices_tuples, names=['Numbers', 'Strings'])
    channel_positions = pd.Series(electrode_coordinate_grid,
                                  index=channel_position_indices)
    channel_positions.columns = ['Positions']
    channel_positions = channel_positions.reset_index(level=None,
                                                      drop=False,
                                                      name='Positions')
    if bad_channels is not None:
        #channel_positions = channel_positions[~channel_positions.Numbers.isin(bad_channels)]
        channel_positions[channel_positions.Numbers.isin(bad_channels)] = -1
        bad_channels_mask = np.reshape(np.in1d(all_electrodes, bad_channels),
                                       (32, 4))
        min_one_val = np.empty_like(bad_channels)
        min_one_val.fill(-1)
        np.place(all_electrodes, bad_channels_mask, min_one_val)

    if filename is not None:
        prb_gen.generate_prb_file(filename=filename,
                                  all_electrodes_array=all_electrodes,
                                  steps_r=steps_r,
                                  steps_c=steps_c)

    return all_electrodes, channel_positions
all_true = number_of_juxta
precision = tp / all_pos
recall = tp / all_true
f_factor = 2 * (precision * recall) / (precision + recall)
print('Precision = {}, Recall = {}, F1 factor = {}'.format(
    precision, recall, f_factor))

# ________________________________________
# ONE OFF FUNCTIONS
# ________________________________________

# Generate prb file ---------------
all_electrodes = np.array([0, 1, 2, 3]).reshape((2, 2))
prb_filename = join(base_folder, 'Analysis', 'KlustaKwik', 'tetrode.prb')
prb_gen.generate_prb_file(filename=prb_filename,
                          all_electrodes_array=all_electrodes,
                          steps_r=2,
                          steps_c=2)
# ---------------------------------

# SPIKEDETECT AND PCA---------------------
# filter all data
high_pass_freq = 500
filtered_data_type = np.float64
temp_unfiltered = extra_data
temp_unfiltered = temp_unfiltered.astype(filtered_data_type)
iir_params = {'order': 4, 'ftype': 'butter', 'padlen': 0}
extra_data_hp = filters.filter_data(temp_unfiltered,
                                    sampling_freq,
                                    l_freq=high_pass_freq,
                                    h_freq=None,
                                    method='iir',