-
Notifications
You must be signed in to change notification settings - Fork 2
/
dic_dump.py
77 lines (70 loc) · 2.46 KB
/
dic_dump.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
from multiR import *
import pickle
import os
import nibabel as nib
import numpy as np
def my_function(t):
# print(t,I,s,eps)
T1 = I.trajectories[s]
T2 = I.trajectories[t]
connectEventList, disconnectEventList = findConnectDisconnectEvents(T1, T2, eps)
return (connectEventList, disconnectEventList, t)
trkfolderO = '/home/shailja/Winter2021/Connectome/Data/old_trks/eps4_occ_mid_L/' #output folder to dump the disctionary
trkfolderI = '/home/shailja/Winter2021/Connectome/Data/old_trks/trk_occ_mid_L' #input track files
eps = 4 #granularity parameter
import pickle
# print(trkpath +".pickle")
trknamelist = os.listdir(trkfolderI)
for i in range(len(trknamelist)):
# try:
trkname = trknamelist[i]
trkpathI = os.path.join(trkfolderI, trkname)
trk = nib.streamlines.load(trkpathI)
streamlines = trk.streamlines
I = create_image(streamlines, eps )
# dic_T = {}
dic_T = {}
for s in range(len(I.trajectories)):
T1 = I.trajectories[s]
dic_T[s] = {}
k1 = 0
e1 = Event("appear", s)
dic_T[s][k1] = [e1]
k2 = len(T1.points) - 1
e2 = Event("disappear", s)
dic_T[s][k2] = [e2]
# print(I)
for s in range(len(I.trajectories)):
myList = [i for i in range(s+1, len(I.trajectories))]
inputs = tqdm(myList)
pool = mp.Pool(processes = num_cores)
processed_list = pool.map(my_function, inputs)
pool.close()
for i in range(len(processed_list)):
connectEventList = processed_list[i][0]
disconnectEventList = processed_list[i][1]
t = processed_list[i][2]
for c in connectEventList:
# print(c)
e = Event("connect",s, t, c[0], c[1])
if dic_T[s].get(c[0]):
dic_T[s][c[0]].append(e)
else:
dic_T[s][c[0]] = [e]
if dic_T[t].get(c[1]):
dic_T[t][c[1]].append(e)
else:
dic_T[t][c[1]] =[e]
for c in disconnectEventList:
e = Event("disconnect",s, t, c[0], c[1])
if dic_T[s].get(c[0]):
dic_T[s][c[0]].append(e)
else:
dic_T[s][c[0]] = [e]
if dic_T[t].get(c[1]):
dic_T[t][c[1]].append(e)
else:
dic_T[t][c[1]] =[e]
# print(dic_T)
with open(trkfolderO+trkname+".pickle", 'wb') as handle:
pickle.dump(dic_T, handle, protocol=pickle.HIGHEST_PROTOCOL)