-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump_population_vectors_around_timestamps.py
executable file
·73 lines (54 loc) · 1.9 KB
/
dump_population_vectors_around_timestamps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
from iutils import *
import numpy as np
from sys import argv
def get_population_vectors_around_timestamps(swrs, res, clu, WIN, SN, SINGLE_VEC, cmap, overlap):
ires = 0
popvecs = []
cused = sum(cmap > 0) + 1
print 'Using %d cells' % cused
print '%d events' % len(swrs)
for swi in range(0, len(swrs)):
swr = swrs[swi]
while res[ires] < swr - WIN:
ires += 1
# if going to skip
if res[ires] >= swr + WIN:
if SINGLE_VEC:
popvecs.append(np.zeros((cused, 1)))
print 'SKIP - no windows around %d' % swr
# TODO: non-full windows: skipp or fill until the end ?
while res[ires] < swr + WIN:
popvec = np.zeros((cused, 1))
for i in range(ires, ires + SN):
if cmap[clu[i]] >= 0:
popvec[cmap[clu[i]]] += 1
if NORM:
popvec[:,0] -= means
popvec[:,0] /= stds
popvecs.append(popvec)
if SINGLE_VEC:
break
ires += SN - overlap
return popvecs
#===================================================================================================================================
if len(argv) < 10:
print 'Usage: ' + argv[0] + ' (1)<dir with all.clu/res> (2)<timestamps file> (3)<WIN around> (4)<spike number> (5)<path to norm file or - > (6)<0/1 - single vector per timestampp> (7)<path to cmap> (8)<output path> (9)<spike windows overlap>'
print 'Dump population vectors around given timestamps +- WIN, or only one window if specified'
exit(0)
swrs = read_int_array(argv[2])
res = read_int_list(argv[1] + 'all.res')
clu = read_int_list(argv[1] + 'all.clu')
WIN = int(argv[3])
SN = int(argv[4])
NORM = argv[5] != '-'
if NORM:
print 'Read normalizers ...'
norm = read_float_array(argv[5])
means = norm[:, 0]
stds = norm[:, 1]
SINGLE_VEC = bool(int(argv[6]))
cmap = read_int_array(argv[7])
OVERLAP = int(argv[9])
popvecs = get_population_vectors_around_timestamps(swrs, res, clu, WIN, SN, SINGLE_VEC, cmap, OVERLAP)
write_array(popvecs, argv[8])