In [1]:
import pandas as pd

In [2]:
df = pd.read_csv('NiPOD-ProbeSpec-denormalized.csv')

In [44]:
df[df.DesignType=='Tetrode']


Out[44]:
DesignName FirstChannelYSpacing NumChannel NumShank NumSitePerShank OtherParameters PackageID ShankHeight ShankSpace ShankStartingXLocation ... ShankWidth SiteArea TetrodeOffsetLeft TetrodeOffsetRight TetrodeOffsetUp TrueShankLength TrueSiteSpacing DesignType PackageName ProbeType
829 A4x1-tet-3mm-150-150-121-Z16 80 16 4 1 NaN 16 500 35 50 ... 50 121 5 3 5 3 150 Tetrode Z16 - a4x1tet A-Style Probe
830 A4x1-tet-3mm-150-150-312-Z16 80 16 4 1 NaN 16 500 35 50 ... 50 312 5 3 5 3 150 Tetrode Z16 - a4x1tet A-Style Probe
858 A4x2-tet-5mm-150-200-312-A16pb32 80 32 4 2 NaN 225 500 35 50 ... 50 312 5 3 5 5 150 Tetrode A16pb32- a4x2tet A-Style Probe
965 Q1x1-tet-10mm-312-Q4 80 4 1 4 NaN 369 500 35 50 ... 50 312 5 3 5 10 200 Tetrode Q4 - Q1x1tet_A16 A-Style Probe
966 Q1x1-tet-10mm-121-Q4 80 4 1 4 NaN 369 500 35 50 ... 50 121 5 3 5 10 200 Tetrode Q4 - Q1x1tet_A16 A-Style Probe
967 Q1x1-tet-10mm-312-Q4 80 4 1 4 NaN 369 500 35 50 ... 50 312 5 3 5 10 200 Tetrode Q4 - Q1x1tet_A16 A-Style Probe
968 Q1x1-tet-18mm-121-Q4 80 4 1 4 NaN 369 500 35 50 ... 50 121 5 3 5 18 200 Tetrode Q4 - Q1x1tet_A16 A-Style Probe
969 Q1x1-tet-18mm-312-Q4 80 4 1 4 NaN 369 500 35 50 ... 50 312 5 3 5 18 200 Tetrode Q4 - Q1x1tet_A16 A-Style Probe
970 A8x1-tet-2mm-200-312-A32 80 32 8 1 NaN 26 500 35 50 ... 50 312 5 3 5 2 200 Tetrode A32 - a8x1tet A-Style Probe
971 A8x1-tet-2mm-200-121-A32 80 32 8 1 NaN 26 500 35 50 ... 50 121 5 3 5 2 200 Tetrode A32 - a8x1tet A-Style Probe
972 A8x1-tet-2mm-200-312-Buzsaki32 80 32 8 1 NaN 177 500 35 50 ... 50 312 5 3 5 2 200 Tetrode Buzsaki32- a8x1 tet A-Style Probe
973 A8x1-tet-2mm-200-312-C32 80 32 8 1 NaN 152 500 35 50 ... 50 312 5 3 5 2 200 Tetrode C32 - a8x1tet A-Style Probe
974 A8x1-tet-2mm-200-312-CM32 80 32 8 1 NaN 32 500 35 50 ... 50 312 5 3 5 2 200 Tetrode CM32 - a8x1tet A-Style Probe
975 A8x1-tet-2mm-200-312-H32_21mm 80 32 8 1 NaN 99 500 35 50 ... 50 312 5 3 5 2 200 Tetrode H32 -a8x1tet A-Style Probe
976 A8x1-tet-2mm-200-121-H32_21mm 80 32 8 1 NaN 99 500 35 50 ... 50 121 5 3 5 2 200 Tetrode H32 -a8x1tet A-Style Probe
977 A8x1-tet-2mm-200-312-HC32_21mm 80 32 8 1 NaN 158 500 35 50 ... 50 312 5 3 5 2 200 Tetrode HC32 - a8x1tet A-Style Probe
978 A8x1-tet-2mm-200-312-HP32_21mm 80 32 8 1 NaN 105 500 35 50 ... 50 312 5 3 5 2 200 Tetrode HP32 - a8x1tet A-Style Probe
979 A8x1-tet-2mm-200-312-MRCM32 80 32 8 1 NaN 123 500 35 50 ... 50 312 5 3 5 2 200 Tetrode MRCM32 - a8x1tet A-Style Probe
980 A8x1-tet-2mm-200-312-Z32 80 32 8 1 NaN 46 500 35 50 ... 50 312 5 3 5 2 200 Tetrode Z32 - a8x1tet A-Style Probe
981 A2x2-tet-3mm-150-150-121-A16 80 16 2 2 NaN 3 500 35 50 ... 50 121 5 3 5 3 150 Tetrode A16 - a2x2tet A-Style Probe
982 A2x2-tet-3mm-150-150-312-A16 80 16 2 2 NaN 3 500 35 50 ... 50 312 5 3 5 3 150 Tetrode A16 - a2x2tet A-Style Probe
983 A2x2-tet-3mm-150-150-121-C16 80 16 2 2 NaN 19 500 35 50 ... 50 121 5 3 5 3 150 Tetrode C16 - c2x2tet A-Style Probe
984 A2x2-tet-3mm-150-150-312-C16 80 16 2 2 NaN 19 500 35 50 ... 50 312 5 3 5 3 150 Tetrode C16 - c2x2tet A-Style Probe
985 A2x2-tet-3mm-150-150-121-CM16 80 16 2 2 NaN 7 500 35 50 ... 50 121 5 3 5 3 150 Tetrode CM16 - a2x2tet A-Style Probe
986 A2x2-tet-3mm-150-150-312-CM16 80 16 2 2 NaN 7 500 35 50 ... 50 312 5 3 5 3 150 Tetrode CM16 - a2x2tet A-Style Probe
987 A2x2-tet-3mm-150-150-121-CM16LP 80 16 2 2 NaN 92 500 35 50 ... 50 121 5 3 5 3 150 Tetrode CM16LP - a2x2tet A-Style Probe
988 A2x2-tet-3mm-150-150-312-CM16LP 80 16 2 2 NaN 92 500 35 50 ... 50 312 5 3 5 3 150 Tetrode CM16LP - a2x2tet A-Style Probe
989 A2x2-tet-3mm-150-150-121-F16 80 16 2 2 NaN 11 500 35 50 ... 50 121 5 3 5 3 150 Tetrode F16 - a2x2tet A-Style Probe
990 A2x2-tet-3mm-150-150-312-F16 80 16 2 2 NaN 11 500 35 50 ... 50 312 5 3 5 3 150 Tetrode F16 - a2x2tet A-Style Probe
991 A2x2-tet-3mm-150-150-121-H16_21mm 80 16 2 2 NaN 56 500 35 50 ... 50 121 5 3 5 3 150 Tetrode H16 - a2x2tet A-Style Probe
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1061 A4x2-tet-7mm-500-400-312-HC32_21mm 80 32 4 2 NaN 156 500 35 50 ... 50 312 5 3 5 5 500 Tetrode HC32 - a4x2tet A-Style Probe
1062 A4x2-tet-5mm-150-200-121-HP32_21mm 80 32 4 2 NaN 104 500 35 50 ... 50 121 5 3 5 5 150 Tetrode HP32 - a4x2tet A-Style Probe
1063 A4x2-tet-5mm-150-200-312-HP32_21mm 80 32 4 2 NaN 104 500 35 50 ... 50 312 5 3 5 5 150 Tetrode HP32 - a4x2tet A-Style Probe
1064 A4x2-tet-5mm-500-400-121-HP32_21mm 80 32 4 2 NaN 104 500 35 50 ... 50 121 5 3 5 5 500 Tetrode HP32 - a4x2tet A-Style Probe
1065 A4x2-tet-5mm-500-400-312-HP32_21mm 80 32 4 2 NaN 104 500 35 50 ... 50 312 5 3 5 5 500 Tetrode HP32 - a4x2tet A-Style Probe
1066 A4x2-tet-7mm-500-400-121-HP32_21mm 80 32 4 2 NaN 104 500 35 50 ... 50 121 5 3 5 5 500 Tetrode HP32 - a4x2tet A-Style Probe
1067 A4x2-tet-7mm-500-400-312-HP32_21mm 80 32 4 2 NaN 104 500 35 50 ... 50 312 5 3 5 5 500 Tetrode HP32 - a4x2tet A-Style Probe
1068 A4x2-tet-5mm-150-200-121-MRCM32 80 32 4 2 NaN 122 500 35 50 ... 50 121 5 3 5 5 150 Tetrode MRCM32 - a4x2tet A-Style Probe
1069 A4x2-tet-5mm-150-200-312-MRCM32 80 32 4 2 NaN 122 500 35 50 ... 50 312 5 3 5 5 150 Tetrode MRCM32 - a4x2tet A-Style Probe
1070 A4x2-tet-5mm-500-400-121-MRCM32 80 32 4 2 NaN 122 500 35 50 ... 50 121 5 3 5 5 500 Tetrode MRCM32 - a4x2tet A-Style Probe
1071 A4x2-tet-5mm-500-400-312-MRCM32 80 32 4 2 NaN 122 500 35 50 ... 50 312 5 3 5 5 500 Tetrode MRCM32 - a4x2tet A-Style Probe
1072 A4x2-tet-7mm-500-400-121-MRCM32 80 32 4 2 NaN 122 500 35 50 ... 50 121 5 3 5 5 500 Tetrode MRCM32 - a4x2tet A-Style Probe
1073 A4x2-tet-7mm-500-400-312-MRCM32 80 32 4 2 NaN 122 500 35 50 ... 50 312 5 3 5 5 500 Tetrode MRCM32 - a4x2tet A-Style Probe
1074 A4x2-tet-5mm-150-200-121-Z32 80 32 4 2 NaN 45 500 35 50 ... 50 121 5 3 5 5 150 Tetrode Z32 - a4x2tet A-Style Probe
1075 A4x2-tet-5mm-150-200-312-Z32 80 32 4 2 NaN 45 500 35 50 ... 50 312 5 3 5 5 150 Tetrode Z32 - a4x2tet A-Style Probe
1076 A4x2-tet-5mm-500-400-121-Z32 80 32 4 2 NaN 45 500 35 50 ... 50 121 5 3 5 5 500 Tetrode Z32 - a4x2tet A-Style Probe
1077 A4x2-tet-5mm-500-400-312-Z32 80 32 4 2 NaN 45 500 35 50 ... 50 312 5 3 5 5 500 Tetrode Z32 - a4x2tet A-Style Probe
1078 A4x2-tet-7mm-500-400-121-Z32 80 32 4 2 NaN 45 500 35 50 ... 50 121 5 3 5 5 500 Tetrode Z32 - a4x2tet A-Style Probe
1079 A4x2-tet-7mm-500-400-312-Z32 80 32 4 2 NaN 45 500 35 50 ... 50 312 5 3 5 5 500 Tetrode Z32 - a4x2tet A-Style Probe
1080 A2x2-tet-3mm-150-150-121-OA16 80 16 2 2 NaN 294 500 35 50 ... 50 121 5 3 5 3 150 Tetrode OA16 - a2x2tet A-Style Probe
1081 A4x2-tet-5mm-500-400-312-OA32 80 32 4 2 NaN 324 500 35 50 ... 50 312 5 3 5 5 500 Tetrode OA32 - a4x2tet A-Style Probe
1082 A4x2-tet-5mm-150-200-312-OA32 80 32 4 2 NaN 324 500 35 50 ... 50 312 5 3 5 5 150 Tetrode OA32 - a4x2tet A-Style Probe
1083 A4x2-tet-5mm-500-400-121-OA32 80 32 4 2 NaN 324 500 35 50 ... 50 121 5 3 5 5 500 Tetrode OA32 - a4x2tet A-Style Probe
1084 Q1x1-tet-10mm-121-Q4 80 4 1 4 NaN 370 500 35 50 ... 50 121 5 3 5 10 200 Tetrode Q4 - Q1x1tet_A32 A-Style Probe
1085 Q1x1-tet-10mm-121-Q4 80 4 1 4 NaN 371 500 35 50 ... 50 121 5 3 5 10 200 Tetrode Q4 - Q1x1tet_OM16 A-Style Probe
1086 Q1x1-tet-10mm-121-Q4 80 4 1 4 NaN 372 500 35 50 ... 50 121 5 3 5 10 200 Tetrode Q4 - Q1x1tet_OM32 A-Style Probe
1231 C2x2-tet-3mm-150-150-121-C16 80 16 2 2 NaN 19 500 35 50 ... 50 121 5 3 5 3 150 Tetrode C16 - c2x2tet C-Style Probe
1232 C2x2-tet-3mm-150-150-312-C16 80 16 2 2 NaN 19 500 35 50 ... 50 312 5 3 5 3 150 Tetrode C16 - c2x2tet C-Style Probe
1233 C2x2-tet-3mm-150-150-121-MRC16 80 16 2 2 NaN 72 500 35 50 ... 50 121 5 3 5 3 150 Tetrode MRC16 - c2x2tet C-Style Probe
1234 C2x2-tet-3mm-150-150-312-MRC16 80 16 2 2 NaN 72 500 35 50 ... 50 312 5 3 5 3 150 Tetrode MRC16 - c2x2tet C-Style Probe

129 rows × 21 columns


In [65]:
(df.DesignType.apply(lambda s: 'Linear' in s)).sum()


Out[65]:
1107

In [66]:
isomura_indx = df.DesignName.apply(lambda s: 'Isomura' in s)
df[isomura_indx]


Out[66]:
DesignName FirstChannelYSpacing NumChannel NumShank NumSitePerShank OtherParameters PackageID ShankHeight ShankSpace ShankStartingXLocation ... ShankWidth SiteArea TetrodeOffsetLeft TetrodeOffsetRight TetrodeOffsetUp TrueShankLength TrueSiteSpacing DesignType PackageName ProbeType
821 Isomura16_v2-A16 80 16 1 16 NaN 287 720 33 50 ... 50 177 5 3 5 10 100 Linear Isomura16_v2-A16 A-Style Probe

1 rows × 21 columns


In [61]:
probe = df.loc[700]
probe


Out[61]:
DesignName                 A4x4-3mm-50-125-177-CM16LP
FirstChannelYSpacing                               80
NumChannel                                         16
NumShank                                            4
NumSitePerShank                                     4
OtherParameters                                   NaN
PackageID                                          91
ShankHeight                                       500
ShankSpace                                         35
ShankStartingXLocation                             50
ShankStartingYLocation                            100
ShankWidth                                         50
SiteArea                                          177
TetrodeOffsetLeft                                   5
TetrodeOffsetRight                                  3
TetrodeOffsetUp                                     5
TrueShankLength                                     3
TrueSiteSpacing                                    50
DesignType                                     Linear
PackageName                             CM16LP - a4x4
ProbeType                               A-Style Probe
Name: 700, dtype: object

In [20]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [35]:
df.DesignType.unique()


Out[35]:
array(['Linear', 'Custom', 'Tetrode'], dtype=object)

In [58]:
sqrt(25**2 / 2)


Out[58]:
17.663521732655695

In [71]:
from scipy import spatial
def get_graph_from_geometry(geometry):
    # let's transform the geometry into lists of channel names and coordinates
    chans,coords = zip(*[(ch,xy) for ch,xy in geometry.iteritems()])
    # we'll perform the triangulation and extract the
    try:
        tri = spatial.Delaunay(coords)
    except:
        x,y = zip(*coords)
        coords = list(coords)
        coords.append((max(x)+1,max(y)+1))
        tri = spatial.Delaunay(coords)
    # then build the list of edges from the triangulation
    indices, indptr = tri.vertex_neighbor_vertices
    edges = []
    for k in range(indices.shape[0]-1):
        for j in indptr[indices[k]:indices[k+1]]:
            try:
                edges.append((chans[k],chans[j]))
            except IndexError:
                # ignore dummy site
                pass
    return edges

def build_geometries(channel_groups):
    for gr, group in channel_groups.iteritems():
        group['graph'] = get_graph_from_geometry(group['geometry'])
    return channel_groups

def get_probe_channel_groups(probe):
    if probe.DesignType=='Linear':
        channel_groups = {}
        for shank in range(int(probe.NumShank)):
            channel_groups[shank] = {}
            sites = shank*int(probe.NumSitePerShank) + np.arange(int(probe.NumSitePerShank))
            x_locs = [0.0 for s in sites]
            y_locs = [probe.TrueSiteSpacing * s for s in sites]
            channel_groups[shank]['channels'] = list(sites)
            channel_groups[shank]['geometry'] = {s:(x,y) for s,x,y in zip(sites,x_locs,y_locs)}
    return build_geometries(channel_groups)

from pprint import pformat
def save_probe(channel_groups,name):
    with open(name+'.prb', 'w') as f:
        f.write('channel_groups = ' + pformat(channel_groups))

In [72]:
get_probe_channel_groups(probe)


Out[72]:
{0: {'channels': [0, 1, 2, 3],
  'geometry': {0: (0.0, 0.0),
   1: (0.0, 50.0),
   2: (0.0, 100.0),
   3: (0.0, 150.0)},
  'graph': [(0, 1), (1, 0), (1, 2), (2, 3), (2, 1), (3, 2)]},
 1: {'channels': [4, 5, 6, 7],
  'geometry': {4: (0.0, 200.0),
   5: (0.0, 250.0),
   6: (0.0, 300.0),
   7: (0.0, 350.0)},
  'graph': [(4, 5), (5, 4), (5, 6), (6, 7), (6, 5), (7, 6)]},
 2: {'channels': [8, 9, 10, 11],
  'geometry': {8: (0.0, 400.0),
   9: (0.0, 450.0),
   10: (0.0, 500.0),
   11: (0.0, 550.0)},
  'graph': [(8, 9), (9, 8), (9, 10), (10, 11), (10, 9), (11, 10)]},
 3: {'channels': [12, 13, 14, 15],
  'geometry': {12: (0.0, 600.0),
   13: (0.0, 650.0),
   14: (0.0, 700.0),
   15: (0.0, 750.0)},
  'graph': [(12, 13), (13, 12), (13, 14), (14, 15), (14, 13), (15, 14)]}}

In [89]:
for p,probe in df.iterrows():
#     if p==0: print probe.DesignName
    try:
        channel_groups = get_probe_channel_groups(probe)
        save_probe(channel_groups,probe.DesignName)
    except:
        pass

In [87]:
cd ~/Dropbox/Projects/niPOD-database


C:\Users\jkiggins\Dropbox\Projects\niPOD-database

In [90]:
cd probe_files


C:\Users\jkiggins\Dropbox\Projects\niPOD-database\probe_files