-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfet_bin_to_text.py
executable file
·56 lines (41 loc) · 1.23 KB
/
fet_bin_to_text.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
#!/usr/bin/env python
from sys import argv
import numpy as np
from matplotlib import pyplot
import os
from iutils import *
from call_log import *
import struct
if len(argv) < 3:
print 'USAGE: (1)<fet file base> (2)<tetrode config>'
exit(0)
BASE = argv[1]
# read tetrode config
ft = open(argv[2])
ntet = int(ft.readline())
PCNS = []
for i in range(ntet):
PCNS.append(int(ft.readline()) * 2)
ft.readline()
print 'Numbers of channels per tetrode:', PCNS
tetr = 0
while os.path.isfile(BASE + str(tetr)):
fo = open(BASE.replace('fetb', 'fet') + str(tetr), 'w')
PCN = PCNS[tetr]
fo.write('%d\n' % (PCN + 5))
FETN = PCNS[tetr] + 4
fmt = FETN * 'f' + 'i'
struct_size = 4 * (FETN + 1)
f = open(BASE+str(tetr))
while True:
spikebin = f.read(struct_size)
if not spikebin:
break
fet = struct.unpack(fmt, spikebin)
# write multiplied X50 and rounded features:
fo.write(PCN*'%d ' % tuple([int(fe*50) for fe in fet[:PCN]]))
fo.write((5*'%d ' + '\n') % tuple([int(fe) for fe in fet[PCN: PCN+5]]))
fo.close()
tetr += 1
print 'Done tetrode %d/%d' % (tetr, ntet)
print 'Done, file %s does not exist' % (BASE + str(tetr))