-
Notifications
You must be signed in to change notification settings - Fork 3
/
convert_spikesmatrix.py
56 lines (42 loc) · 1.51 KB
/
convert_spikesmatrix.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
import h5py
import numpy as np
import matplotlib.pyplot as plt
scale=1
maxtime = 15000
def convert(num_pn,inp='./spikesmatrix_op_ryt', out='../vpsi_inh_spikes.h5'):
matlab_file = open(inp, 'r')
lines = matlab_file.readlines()
matlab_file.close()
vpsi = h5py.File(out, 'w')
vpsi_spikes = vpsi.create_group("spikes")
vpsi_spikes_vp = vpsi_spikes.create_group("vpsi_inh")
spikes_node_ids = []
spikes_timestamps = []
count = 0
for line in lines:
times = line.strip().split('\t')
if len(times)==1 and times[0]=='':
count = count + 1
continue # There were no spikes for this cell
times = [int(time) for time in times if int(time) < maxtime]
times.sort()
ids = [count for _ in range(len(times))]
spikes_timestamps = spikes_timestamps + times
spikes_node_ids = spikes_node_ids + ids
count = count + 1
nodes=np.array(spikes_node_ids).astype(int)
timestamps=np.array(spikes_timestamps).astype(float)
vpsi_spikes_vp.create_dataset("node_ids", data=nodes)
vpsi_spikes_vp.create_dataset("timestamps", data=timestamps)
vpsi.close()
# plot a scatter plot
fig, ax = plt.subplots()
ax.scatter(timestamps,nodes,s=2)
ax.set_xlabel('Spike Timestamp', fontsize=12)
ax.set_ylabel('Affrent Neuron ID', fontsize=12)
ax.set_title('8Hz Input', fontsize=12)
#ax.grid(True)
fig.tight_layout()
plt.show()
if __name__ == '__main__':
convert(num_pn=800*scale)