-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclures_merge_tetrodes_by_sessions.py
executable file
·52 lines (38 loc) · 1.3 KB
/
clures_merge_tetrodes_by_sessions.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
#!/usr/bin/env python3
from sys import argv
import numpy as np
from matplotlib import pyplot as plt
import os
#from call_log import *
if len(argv) < 2:
print('USAGE: (1)<basename: of daywise parfile and des/desen>')
exit(0)
# read from par: # of tetrodes and basenames
BASE = argv[1]
if BASE[-1] != '.' : BASE += '.'
parlines = open(BASE + 'par').readlines()
ntet = int(parlines[2].split()[0])
print('ntet', ntet)
sesbases = [s[:-1] + '.' for s in parlines[4+ntet:]]
for sesbase in sesbases:
print('Merge tetrodes for session', sesbase)
clushift = 0
for t in range(1, ntet + 1):
print('t', t, 'clushift', clushift)
res = np.loadtxt(sesbase + 'res.' + str(t), dtype=int)
clu = np.loadtxt(sesbase + 'clu.' + str(t), dtype=int)
nclu = clu[0]
clu = clu[1:]
clu[clu>1] += clushift
clushift += nclu - 1
res = res.reshape(-1,1)
clu = clu.reshape(-1,1)
if t == 1:
merged = np.hstack([clu,res])
else:
merged = np.vstack([merged, np.hstack([clu,res])])
nclu = int(max(merged[:,0]))
merged = merged[merged[:,1].argsort(),:]
print('merged head', merged[:4,:])
np.savetxt(sesbase + 'clu', [nclu] + list(merged[:,0]), fmt='%d')
np.savetxt(sesbase + 'res', merged[:,1], fmt='%d')