-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPosNegDiscNetworkBasedConnPlot.py
More file actions
165 lines (90 loc) · 6.28 KB
/
PosNegDiscNetworkBasedConnPlot.py
File metadata and controls
165 lines (90 loc) · 6.28 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import numpy as np
import matplotlib.pyplot as plt
from Utils import Local
from Utils import Constants
from Utils import SciPlot as SP
from Utils.InputVariables import PlotVars as PV
from Utils.InputVariables import CommonVars as CoV
########################################################### Define Parameters ###########################################################
DataName = PV.NetBaseConnPlot['DataName']
NodeNames = Constants.LocalDataConstants.names[DataName + 'ClusterNames']
group_labels = Constants.LocalDataConstants.Labels['groups']
data_labels = ['Pos', 'Neg']
confile_dir = Constants.LocalDataConstants.directories['n_confile_dir']
PlotSave_dir = Constants.LocalDataConstants.directories['plotSave_dir']
ConKers = PV.NetBaseConnPlot['ConKers']
NOIs = PV.NetBaseConnPlot['NOIs']
Bands = PV.NetBaseConnPlot['Bands']
VerNum = PV.NetBaseConnPlot['VersionNumber']
Fs = CoV.SamplingFrequency
NB = 2
########################################################### Load Available Data ###########################################################
BehavioralData, Performance_data = 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 ###########################################################
events = ['Pos', 'Neg']
event_name = 'PosNeg'
print("The Event is " + event_name)
for NOI in NOIs:
for kernel in ConKers:
for Band_i, Band in enumerate(Bands):
if Local.BandAvailable(kernel, Band):
Data = []
VersionSpecs = []
for event in events:
Data_t, VersionSpecs_t = Local.HandleDataLoad(confile_dir + '\\' + event + '\\' + NOI + '\\' + kernel + '\\' + Band, version_number = VerNum)
Data.append(Data_t)
VersionSpecs.append(VersionSpecs_t)
assert VersionSpecs[0] == VersionSpecs[1], "Data's Version Specs Must be Matched!"
VersionSpecs = VersionSpecs[0]
st = VersionSpecs['Start Time']
ft = VersionSpecs['End Time']
win_length = VersionSpecs['Window_Length']
overlap_ratio = VersionSpecs['Overlap_Ratio']
time_p = SP.TimeVectorGenerator(st, ft, Fs, win_length, overlap_ratio, TimePos = PV.NetBaseConnPlot['TimePosition'])
DataGroups = [[[Data[FB_Sign][str(SOI[1][sub_i[0]])] for FB_Sign in range(2)] for sub_i in SubSub_G] for SubSub_G in Sub_G]
Channels = Constants.LocalDataConstants.NetworksOfInterest[DataName][NOI]
for Tr_i, TrCh in enumerate(Channels):
if Constants.DC_Constants.Properties[kernel]['directed']:
SLChannels = Channels
else:
SLChannels = Channels[:Tr_i]
for Re_i, ReCh in enumerate(SLChannels):
if TrCh != ReCh or Constants.DC_Constants.Properties[kernel]['SelfLoop']:
Data4Plot = [np.array(DataGroups[G_i])[:, :, :, Tr_i, Re_i] for G_i in range(len(DataGroups))]
fig, axs = plt.subplots(2, 2, layout = 'constrained', sharey = True, sharex = True, figsize = (10, 7))
for Gi, DataGroup in enumerate(Data4Plot):
for BN in range(NB):
DataBlock = DataGroup[:, BN, :]
y_U, y_L = SP.ConfidenceBoundsGen(DataBlock)
axs[Gi, 0].plot(time_p[:DataBlock.shape[-1]], np.mean(DataBlock, axis = 0), label = data_labels[BN])
axs[Gi, 0].fill_between(time_p[:DataBlock.shape[-1]], y_U, y_L, alpha = 0.2)
axs[BN, 1].plot(time_p[:DataBlock.shape[-1]], np.mean(DataBlock, axis = 0), label = group_labels[Gi])
axs[BN, 1].fill_between(time_p[:DataBlock.shape[-1]], y_U, y_L, alpha = 0.2)
for i in range(2):
axs[i, 0].set_title(group_labels[i])
axs[i, 1].set_title(data_labels[i])
for j in range(2):
axs[i, j].legend()
plt.setp(axs, xlim = [time_p[0], time_p[:DataBlock.shape[-1]][-1]])
fig.supxlabel("time (s)")
if DataName != 'July':
SavePlotDir = Local.HandleDir(PlotSave_dir + '\\' + event_name + '\\' + NOI + '\\' + DataName + '\\' + kernel + '\\' + Band)
else:
SavePlotDir = Local.HandleDir(PlotSave_dir + '\\' + event_name + '\\' + NOI + '\\' + kernel + '\\' + Band)
if not Constants.DC_Constants.Properties[kernel]['directed']:
fig.suptitle("Temporal dynamic of " + str(kernel) + " locked on " + event_name + " Onset\nClusters " + NodeNames[TrCh] + " and " + NodeNames[ReCh] + " in " + Band + " Band", fontsize = 15)
plt.savefig(SavePlotDir + "\defParam_" + NodeNames[TrCh] + "_" + NodeNames[ReCh] + ".png", format="png")
print("Saved")
else:
fig.suptitle("Temporal dynamic of " + str(kernel) + " locked on " + event_name + " Onset\nTransmitter is " + NodeNames[TrCh] + " and Receiver is " + NodeNames[ReCh] + " in " + Band + " Band", fontsize = 15)
fig.savefig(SavePlotDir + "\defParam_Tr_" + NodeNames[TrCh] + "_Rec_" + NodeNames[ReCh] + ".png", format="png")
print("Saved")
plt.close(fig)