-
Notifications
You must be signed in to change notification settings - Fork 3
/
distance_connection_info.py
134 lines (100 loc) · 4.26 KB
/
distance_connection_info.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import sys
import numpy as np
import pandas as pd
import h5py
from bmtools.cli.plugins.util.util import relation_matrix
f = h5py.File('outputECP/spikes.h5')
spikes = pd.DataFrame({'node_ids':f['spikes']['BLA']['node_ids'],'timestamps':f['spikes']['BLA']['timestamps']})
edges = None
def conn_info(**kwargs):
global edges
_edges = kwargs["edges"]
source_id_type = kwargs["sid"]
target_id_type = kwargs["tid"]
source_id = kwargs["source_id"]
target_id = kwargs["target_id"]
t_list = kwargs["target_nodes"]
s_list = kwargs["source_nodes"]
if edges is None: #want to accumulate connections
edges = _edges
else:
edges = edges.append(_edges).drop_duplicates()
#center_x = kwargs["center_x"]
#center_y = kwargs["center_y"]
#center_z = kwargs["center_z"]
#step = kwargs["step"]
#iterations = kwargs["iterations"]
center_x = 600
center_y = 600
center_z = 600
iterations = 13
step = 25
ms = 15000
skip_ms = 5000
cons = edges[(edges[source_id_type] == source_id) & (edges[target_id_type]==target_id)]
# Disable this next assignment ifor most normal situatipns
cons = edges[(edges[target_id_type]==target_id)]
#total_cons = cons.count().source_node_id
#import pdb;pdb.set_trace()
print(source_id + " -> " + target_id + " step " + str(step*2))
print("from locations => to locations : n number of cells : connections mean (std) : spikes mean (std)")
biggest_jump = 0
biggest_jump_str = ""
last = 0
last_str = ""
dist = np.linalg.norm(edges[['target_pos_x', 'target_pos_y', 'target_pos_z']].values.astype(float)-edges[['source_pos_x', 'source_pos_y', 'source_pos_z']].values.astype(float),axis=1)
for inner_dist in range(step,iterations*step,step):
#cube
min_x = center_x - inner_dist
max_x = center_x + inner_dist
min_y = center_y - inner_dist
max_y = center_y + inner_dist
min_z = center_z - inner_dist
max_z = center_z + inner_dist
connections = cons[(cons['target_pos_x'] > min_x) & (cons['target_pos_y'] > min_x ) & (cons['target_pos_z'] > min_z)
& (cons['target_pos_x'] < max_x) & (cons['target_pos_y'] < max_y ) & (cons['target_pos_z'] < max_z)]
connection_counts = connections['target_node_id'].value_counts()
mean_connections = connection_counts.mean()
std_connections = connection_counts.std()
cells = list(connections.drop_duplicates(subset=['target_node_id'])['target_node_id'])
num_cells = len(cells)
cell_spikes = spikes[spikes['node_ids'].isin(cells)]
#skip the first few ms
cell_spikes = cell_spikes[cell_spikes['timestamps']>skip_ms]
spike_counts = cell_spikes.node_ids.value_counts()
total_seconds = (ms-skip_ms)/1000
spike_counts_per_second = spike_counts / total_seconds
spikes_mean = spike_counts_per_second.mean()
spikes_std = spike_counts_per_second.std()
location_str = str((min_x,min_y,min_z)) + "=>" + str((max_x,max_y,max_z))
print(location_str + " : " + str(num_cells) +" cells : {:.2f}".format(mean_connections) + " ({:.2f})".format(std_connections) +
": {:.2f}".format(spikes_mean) + " ({:.2f})".format(spikes_std))
if last-spikes_mean > biggest_jump:
biggest_jump = last-spikes_mean
biggest_jump_str = last_str + " and " + location_str
last = spikes_mean
last_str = location_str
print("Biggest jump (" + "{:.2f}".format(biggest_jump) + ") occurs between " + biggest_jump_str)
return 0
def run(config):
nodes = None
edges = None
sources = ['BLA','shell']
targets = ['BLA']
sids = ['model_type','model_type']
#sids = ['a_name']
tids = ['a_name']
prepend_pop = True
#center_x = 300
#center_y = 300
#center_z = 300
#iterations = 13
#step = 25
#print("\ttotal\tuni\tbi")
ret = relation_matrix(config,nodes,edges,sources,targets,sids,tids,prepend_pop,relation_func=conn_info)
return
if __name__ == '__main__':
if __file__ != sys.argv[-1]:
run(sys.argv[-1])
else:
run('simulation_configECP.json')