forked from IntrAnatSEEGSoftware/IntrAnat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bipoleSEEGColors.py
267 lines (220 loc) · 19 KB
/
bipoleSEEGColors.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# -*-coding:utf-8 -*
import sys, os, pickle, glob, numpy, re, string, time, subprocess, json, copy, csv
from soma.qt_gui.qt_backend import QtGui, QtCore, uic, Qt
from numpy import *
from math import sqrt
from collections import OrderedDict
from soma import aims
from brainvisa import axon
#from soma.aims.spmnormalizationreader import readSpmNormalization
from brainvisa import anatomist
from brainvisa.data import neuroHierarchy
import brainvisa.registration as registration
from externalprocesses import *
from referentialconverter import ReferentialConverter
import pdb
#Main Class
class bipoleSEEGColors(QtGui.QDialog):
def __init__(self,locateData = None,indv_pat=True,group_subsample=None):
QtGui.QWidget.__init__(self)
self.ui = uic.loadUi("bipoleLabelsDisplay.ui", self)
self.setWindowTitle('Stimulation Observation - NOT FOR MEDICAL USE')
self.locaData =locateData #Data from locatesElectrode.py
self.a=self.locaData.a #Anatomist Object
self.ui.lowHz_radiobutton.toggled.connect(self.updateBipoleDisplay)
self.ui.highHz_radiobutton.toggled.connect(self.updateBipoleDisplay)
self.ui.bothHz_radiobutton.toggled.connect(self.updateBipoleDisplay)
self.ui.fontColor_radiobutton.toggled.connect(self.updateBipoleDisplay)
self.ui.backColor_radiobutton.toggled.connect(self.updateBipoleDisplay)
by_default_list = ['Motor','Sensitive','Sensory','Vegetative','Emotional','Experiencial','Superior functions']
self.final_list_color = by_default_list #detect differencies ? but how because there is other column that should not be taken
model= QtGui.QStandardItemModel(len(self.final_list_color), 1)
for index,i_list in enumerate(self.final_list_color):
item = QtGui.QStandardItem(i_list)
item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
item.setData(QtCore.Qt.Unchecked, QtCore.Qt.CheckStateRole)
model.setItem(index+1, 0, item)
self.ui.list_backColor_Condition.setModel(model)
self.ui.list_backColor_Condition.setEnabled(False)
self.ui.list_backColor_Condition.clicked.connect(self.updateBipoleDisplay)
self.mode_indv = indv_pat
self.subsample_group = group_subsample
self.updateBipoleDisplay()
def updateBipoleDisplay(self):
infoHztoshow = [self.ui.lowHz_radiobutton.isChecked(),self.ui.highHz_radiobutton.isChecked(),self.ui.bothHz_radiobutton.isChecked()]
infoHzselected = [x for x in range(len(infoHztoshow)) if infoHztoshow[x] == True]
colortoshow = [self.ui.fontColor_radiobutton.isChecked(),self.ui.backColor_radiobutton.isChecked()]
colorselected = [x for x in range(len(colortoshow)) if colortoshow[x] == True]
if self.mode_indv:
bipoleObjects= dict([(self.locaData.bipoles[x]['name'],self.locaData.bipoles[x]['elecModel'].getAnatomistObjects()[0]) for x in range(len(self.locaData.bipoles))])
dataSEEG = self.locaData.bipoleLabels['contacts']
else:
bipoleObjects = self.locaData.bipolesmeshes
dataSEEG = {}
datatomodify = {}
for index_subsample in self.subsample_group:
(subject,bipole) = index_subsample.split(' : ')
if subject not in list(datatomodify.keys()):
datatomodify.update({subject:[]})
datatomodify[subject].append(bipole)
for subj in list(datatomodify.keys()):
#if subj not in dataSEEG.keys():
#dataSEEG.update({subj:{}})
for index_bipole in datatomodify[subj]:
matches_bipoles = [x for x in range(len(self.locaData.testDataSubjects[subj]['seeg_label_all'])) if self.locaData.testDataSubjects[subj]['seeg_label_all'][x][0] == index_bipole]
#new_name = subj + ' : ' + self.locaData.testDataSubjects[subj]['seeg_label_all'][index_cont][0]
if len(matches_bipoles)>0:
for index_matches_bipoles in matches_bipoles:
new_name = subj + ' : ' + self.locaData.testDataSubjects[subj]['seeg_label_all'][index_matches_bipoles][0]
if new_name not in list(dataSEEG.keys()):
dataSEEG.update({new_name:{'cell':{}}})
dataSEEG[new_name]['cell'].update({self.locaData.testDataSubjects[subj]['seeg_label_all'][index_matches_bipoles][1]:{}})
for x in self.final_list_color:
if x in self.locaData.testDataSubjects[subj]['seeg_label_all'][index_matches_bipoles][3]:
dataSEEG[new_name]['cell'][self.locaData.testDataSubjects[subj]['seeg_label_all'][index_matches_bipoles][1]].update({x:{'value':'something'}})
else:
dataSEEG[new_name]['cell'][self.locaData.testDataSubjects[subj]['seeg_label_all'][index_matches_bipoles][1]].update({x:{'value':0}})
if self.locaData.testDataSubjects[subj]['seeg_label_all'][index_matches_bipoles][2] == 'no response':
dataSEEG[new_name]['cell'][self.locaData.testDataSubjects[subj]['seeg_label_all'][index_matches_bipoles][1]].update({'Type of response':{'fontcolor':[255,0,0,0]}})
elif self.locaData.testDataSubjects[subj]['seeg_label_all'][index_matches_bipoles][2] == 'seizure sensation':
dataSEEG[new_name]['cell'][self.locaData.testDataSubjects[subj]['seeg_label_all'][index_matches_bipoles][1]].update({'Type of response':{'fontcolor':[255,255,0,0]}})
elif self.locaData.testDataSubjects[subj]['seeg_label_all'][index_matches_bipoles][2] == 'pathological':
dataSEEG[new_name]['cell'][self.locaData.testDataSubjects[subj]['seeg_label_all'][index_matches_bipoles][1]].update({'Type of response':{'fontcolor':[255,0,0,255]}})
if colorselected[0] == 1:
self.ui.list_backColor_Condition.setEnabled(True)
default_backColor = {'Sensory': [255, 0, 176, 80], 'Sensitive': [255, 0, 112, 192], 'Superior functions': [255, 148, 82, 0], 'Motor': [255, 255, 0, 0], 'Emotional': [255, 112, 48, 160], 'Vegetative': [255, 255, 192, 0], 'Experiencial': [255, 255, 133, 255]}
backColor = {}
Model = self.ui.list_backColor_Condition.model()
for index in range(Model.rowCount()-1):
Item = Model.item(index+1)
if Item.checkState():
if self.mode_indv:
backColor.update({str(Item.text()):self.locaData.bipoleLabels['title'][str(Item.text())]['title_backcolor'][:]})
else:
backColor.update({str(Item.text()):default_backColor[str(Item.text())]})
else:
backColor.update({str(Item.text()):[255,150,150,150]})
for index_contacts in range(len(list(dataSEEG.keys()))):
#if self.locaData.bipoleLabels['contacts'].keys()[index_contacts] == u'R02 - R01':
if ('1 Hz' in list(dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell'].keys())) and (infoHzselected[0] == 0):#(self.locaData.bipoleLabels['contacts'][self.locaData.bipoleLabels['contacts'].keys()[index_contacts]]['cell'].keys()[0] == u'1 Hz' ) and (infoHzselected[0] == 0 or infoHzselected[0] == 2):
#enComp = [self.locaData.bipoleLabels['contacts'][self.locaData.bipoleLabels['contacts'].keys()[index_contacts]]['cell']['1 Hz'][x]['value'] for x in self.final_list_color]
enComp = [True if dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell']['1 Hz'][x]['value'] != 0 else False for x in self.final_list_color]
try:
indexTrue = enComp.index(True)
indexesTrue = [i for i,j in enumerate(enComp) if j == True]
selected_color = [kk for kk,vv in list(backColor.items()) if vv != [255,150,150,150]]
valueselectedcolor = [self.final_list_color.index(selected_color[i]) for i in range(len(selected_color))]
commonSelect = list(set(indexesTrue) & set(valueselectedcolor))
if len(commonSelect)>1:
colorn = QtGui.QColor.fromRgb(255,255,255,255)
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
else:
colorn = QtGui.QColor.fromRgb(backColor[self.final_list_color[commonSelect[0]]][1],backColor[self.final_list_color[commonSelect[0]]][2],backColor[self.final_list_color[commonSelect[0]]][3],backColor[self.final_list_color[commonSelect[0]]][0])
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
except:
#no response after stimulation
colorn = QtGui.QColor.fromRgb(0,0,0,255)
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
elif ('1 Hz' not in list(dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell'].keys())) and (infoHzselected[0] == 0):
colorn = QtGui.QColor.fromRgb(150,150,150,255)
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
elif ('50 Hz' in list(dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell'].keys())) and (infoHzselected[0] == 1):
enComp = [True if dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell']['50 Hz'][x]['value'] != 0 else False for x in self.final_list_color]
try:
indexTrue = enComp.index(True)
indexesTrue = [i for i,j in enumerate(enComp) if j == True]
selected_color = [kk for kk,vv in list(backColor.items()) if vv != [255,150,150,150]]
valueselectedcolor = [self.final_list_color.index(selected_color[i]) for i in range(len(selected_color))]
commonSelect = list(set(indexesTrue) & set(valueselectedcolor))
if len(commonSelect)>1:
colorn = QtGui.QColor.fromRgb(255,255,255,255)
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
else:
colorn = QtGui.QColor.fromRgb(backColor[self.final_list_color[commonSelect[0]]][1],backColor[self.final_list_color[commonSelect[0]]][2],backColor[self.final_list_color[commonSelect[0]]][3],backColor[self.final_list_color[commonSelect[0]]][0])
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
except:
#no response after stimulation
colorn = QtGui.QColor.fromRgb(0,0,0,255)
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
elif ('50 Hz' not in list(dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell'].keys())) and (infoHzselected[0] == 1):
colorn = QtGui.QColor.fromRgb(150,150,150,255)
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
elif infoHzselected[0] == 2:
if '1 Hz' in list(dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell'].keys()):
enComp1Hz = [True if dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell']['1 Hz'][x]['value'] != 0 else False for x in self.final_list_color]
else:
enComp1Hz = [False for i in range(len(self.final_list_color))]
if '50 Hz' in list(dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell'].keys()):
enComp50Hz = [True if dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell']['50 Hz'][x]['value'] != 0 else False for x in self.final_list_color]
else:
enComp50Hz = [False for i in range(len(self.final_list_color))]
enCompBoth = numpy.logical_or(enComp1Hz,enComp50Hz).tolist()
try:
indexTrue = enCompBoth.index(True)
indexesTrue = [i for i,j in enumerate(enCompBoth) if j == True]
selected_color = [kk for kk,vv in list(backColor.items()) if vv != [255,150,150,150]]
valueselectedcolor = [self.final_list_color.index(selected_color[i]) for i in range(len(selected_color))]
commonSelect = list(set(indexesTrue) & set(valueselectedcolor))
if len(commonSelect)>1:
colorn = QtGui.QColor.fromRgb(255,255,255,255)
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
else:
colorn = QtGui.QColor.fromRgb(backColor[self.final_list_color[commonSelect[0]]][1],backColor[self.final_list_color[commonSelect[0]]][2],backColor[self.final_list_color[commonSelect[0]]][3],backColor[self.final_list_color[commonSelect[0]]][0])
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
except:
#no response after stimulation
colorn = QtGui.QColor.fromRgb(0,0,0,255)
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
#pdb.set_trace() #color = QtGui.QColor.fromRgb(250,0,0,100) r g b alpha
#self.a.setMaterial(newCyl, diffuse=[color.redF(), color.greenF(), color.blueF(), color.alphaF()]) newCyl <anatomist.cpp.ASurface_3 object at 0xa0ff0e0>
else:
self.ui.list_backColor_Condition.setEnabled(False)
for index_contacts in range(len(list(dataSEEG.keys()))):
#self.locaData.bipoleLabels['contacts'][self.locaData.bipoleLabels['contacts'].keys()[1]]['line']['fontcolor']
if ('1 Hz' in list(dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell'].keys())) and (infoHzselected[0] == 0):
fontColorLine = dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell']['1 Hz']['Type of response']['fontcolor']
if fontColorLine[1] == 0 and fontColorLine[2] == 0 and fontColorLine[3]==0:
fontColorLine = [255,0,0,0]
colorn = QtGui.QColor.fromRgb(fontColorLine[1],fontColorLine[2],fontColorLine[3],fontColorLine[0])
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
elif ('1 Hz' not in list(dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell'].keys())) and (infoHzselected[0] == 0):
colorn = QtGui.QColor.fromRgb(150,150,150,255)
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
elif ('50 Hz' in list(dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell'].keys())) and (infoHzselected[0] == 1):
fontColorLine = dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell']['50 Hz']['Type of response']['fontcolor']
if fontColorLine[1] == 0 and fontColorLine[2] == 0 and fontColorLine[3]==0:
fontColorLine = [255,0,0,0]
colorn = QtGui.QColor.fromRgb(fontColorLine[1],fontColorLine[2],fontColorLine[3],fontColorLine[0])
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
elif ('50 Hz' not in list(dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell'].keys())) and (infoHzselected[0] == 1):
colorn = QtGui.QColor.fromRgb(150,150,150,255)
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
if infoHzselected[0]==2:
if ('1 Hz' in list(dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell'].keys())):
fontColorLine1 = dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell']['1 Hz']['Type of response']['fontcolor']
if fontColorLine1[1] == 0 and fontColorLine1[2] == 0 and fontColorLine1[3]==0:
fontColorLine1 = [255,0,0,0]
else:
fontColorLine1 = [0,0,0,0]
if ('50 Hz' in list(dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell'].keys())):
fontColorLine50 = dataSEEG[list(dataSEEG.keys())[index_contacts]]['cell']['50 Hz']['Type of response']['fontcolor']
if fontColorLine50[1] == 0 and fontColorLine50[2] == 0 and fontColorLine50[3]==0:
fontColorLine50 = [255,0,0,0]
else:
fontColorLine50 = [0,0,0,0]
fontColorBoth =numpy.minimum((numpy.array(fontColorLine50) + numpy.array(fontColorLine1)),255).tolist()
colorn = QtGui.QColor.fromRgb(fontColorBoth[1],fontColorBoth[2],fontColorBoth[3],fontColorBoth[0])
bipoleObjects[list(dataSEEG.keys())[index_contacts]].setMaterial(diffuse=[colorn.redF(), colorn.greenF(), colorn.blueF(), colorn.alphaF()])
def closeEvent(self, event):
self.quit(event)
def quit(self, event=None):
reply = QtGui.QMessageBox.question(self, 'Quit',"Quit bipole colors editor ?", QtGui.QMessageBox.Yes |QtGui.QMessageBox.No, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
if event is None:
self.a.quit()
else:
event.accept()
else:
event.ignore()
if __name__=="__main__":
a=QtGui.QApplication(sys.argv)