-
Notifications
You must be signed in to change notification settings - Fork 0
/
firing_rates_intervals.py
executable file
·52 lines (38 loc) · 1.21 KB
/
firing_rates_intervals.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 python2
from sys import argv
import numpy as np
from matplotlib import pyplot as plt
import os
from iutils import *
from call_log import *
from scipy import stats
if len(argv) < 4:
print 'USAGE: (1)<clu/res base> (2)<interval timestamps> (3)<output path>'
print 'CALCULATE FIRING RATE IN GIVEN INTERVALS (CURRENTLY READING TIMETAMPS OF 100MS INTERVAL STARTS)'
exit(0)
argv = resolve_vars(argv)
BASE = argv[1]
OUTPATH = argv[3]
istarts = np.loadtxt(argv[2])
clu = np.loadtxt(BASE + 'clu', dtype=np.int)
res = np.loadtxt(BASE + 'res', dtype=np.int)
intervals = [[st, st+2400] for st in istarts]
ires = 0
# NEXT OR CURRENT INTERVAL
ii = 0
scounts = [0] * (np.max(clu) + 1)
INSIDE = True
while ii < len(intervals):
while ires < len(res) and res[ires] < intervals[ii][0]:
if not INSIDE:
scounts[clu[ires]] += 1
ires += 1
while ires < len(res) and res[ires] < intervals[ii][1]:
if INSIDE:
scounts[clu[ires]] += 1
ires += 1
ii += 1
#dursec = (res[-1] - (np.sum([ ii[1] - ii[0] for ii in intervals]))) / 24000.0
dursec = (np.sum([ ii[1] - ii[0] for ii in intervals])) / 24000.0
rates = np.array(scounts) / dursec
np.savetxt(OUTPATH, rates)