-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkBasedConnSignificanceTest.py
More file actions
125 lines (77 loc) · 4.45 KB
/
NetworkBasedConnSignificanceTest.py
File metadata and controls
125 lines (77 loc) · 4.45 KB
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
import numpy as np
import pickle
import scipy.stats as sps
import Modules.GRConnPy as GRC
from Utils import Local
from Utils import Constants
from Utils import SciPlot as SP
from tqdm import tqdm
from Utils.InputVariables import CalculationVars as CV
from Utils.InputVariables import CommonVars as CoV
########################################################### Define Parameters ###########################################################
group_labels = Constants.LocalDataConstants.Labels['groups']
data_labels = Constants.LocalDataConstants.Labels['data_block']
ConKers = CV.NetBaseConnSigTest['ConKers']
overlap_ratio = CV.NetBaseConnSigTest['OLR']
win_length = CV.NetBaseConnSigTest['WinLen']
NOIs = CV.NetBaseConnSigTest['NOIs']
Bands = CV.NetBaseConnSigTest['Bands']
OutSource = CV.NetBaseConnSigTest['OutSource']
st = CV.NetBaseConnSigTest['st']
ft = CV.NetBaseConnSigTest['ft']
Fs = CoV.SamplingFrequency
confile_dir = Constants.LocalDataConstants.directories['n_confile_dir']
sp = int((st + 0.4) * Fs)
fp = int((ft + 0.4) * Fs)
NB = ft = CV.NetBaseConnSigTest['NB']
TB = Constants.LocalDataConstants.DefaulValues['trial_in_block']
########################################################### Load Available Data ###########################################################
BehavioralData, _ = Local.ExperimentDataLoader()
SOI = Local.AvailableSubjects()
################################################## Divide Subject into DEP and CTRL Groups ###########################################################
Sub_G = [[], []] # first element is CTRL Group Members and the Second one the DEP Group
for i, sub_i in enumerate(SOI[0]):
if BehavioralData['BDI'][sub_i] < 10:
Sub_G[0].append([i, sub_i])
else:
Sub_G[1].append([i, sub_i])
########################################################## Generate Connectivity Data ###########################################################
event_numbers = [3] # Stim Onset
event_numbers = CV.NetBaseConnSigTest['Events']
specs = {
'orders_matrix': CV.NetBaseConnSigTest['OrderMat'],
'overlap_ratio': overlap_ratio,
'window_length': win_length,
'start time': st,
'end time': ft,
'DecompKern': CV.NetBaseConnSigTest['DecompKern'],
'CorrCalcFunct': CV.NetBaseConnSigTest['CorrCalcFunct'],
'AmpBand': CV.NetBaseConnSigTest['AmpBand'],
'PhaseBand': CV.NetBaseConnSigTest['PhaseBand'],
}
for event in event_numbers:
raw_data, data_lengths = Local.ClusteredEEGLoader(event = event)
event_name = Constants.LocalDataConstants.names['events'][event]
print("The Event is " + event_name)
SaveFileDir = Local.HandleDir(confile_dir + '\\' + event_name)
for NOI in NOIs:
SaveFileDir = Local.HandleDir(confile_dir + '\\' + event_name + '\\' + NOI)
for kernel in ConKers:
SaveFileDir = Local.HandleDir(confile_dir + '\\' + event_name + '\\' + NOI + '\\' + kernel)
for Band_i, Band in enumerate(Bands):
if Local.BandAvailable(kernel, Band):
SaveFileDir = Local.HandleDir(confile_dir + '\\' + event_name + '\\' + NOI + '\\' + kernel + '\\' + Band)
tConDataDict = {}
for i, sub_i in tqdm(enumerate(SOI[0])):
print("subject " + str(i))
dl = int(data_lengths[i])
data = sps.zscore(raw_data[i][:, :, sp : fp], axis = -1)
Samples = SP.DeterminedBlockSampling(dl, NumBlock = NB, NumSample_inBlock = TB)
divData = np.mean(data[Samples], axis = 1)
sub_Data = GRC.ConnectionSignificance(divData, kernel = kernel, Band = Band, overlap_ratio = specs['overlap_ratio'], window_length = specs['window_length'], orders_matrix = specs['orders_matrix'], inc_channels = Constants.LocalDataConstants.NetworksOfInterest[NOI], AmpBand = 'Gamma', PhaseBand = 'Theta', PhaseAmplitudeCorrelateCalc = 'ModulationIndex')
tConDataDict[str(SOI[1][i])] = sub_Data
SaveFileName, version_number = Local.HandleFileName(SaveFileDir, specs)
with open(SaveFileDir + "\\" + SaveFileName, 'wb') as f:
pickle.dump(tConDataDict, f, protocol=pickle.HIGHEST_PROTOCOL)
print("Version " + str(version_number) + " of File Saved")
SaveFileDir = Local.HandleDir(confile_dir + '\\SignificanceTest_' + event_name)