forked from SvenBo90/Py2DSpectroscopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixelInformationWindow.py
265 lines (207 loc) · 11.6 KB
/
pixelInformationWindow.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
# general imports
import numpy
# import PyQt5 elements
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QGridLayout, QMainWindow, QTableWidgetItem, QWidget
# import UI
from UIs.pixelInformationWidgetUi import UiPixelInformationWidget
class PixelInformationWidget(QWidget):
def __init__(self, parent, map_handle):
# call widget init
QWidget.__init__(self, parent)
# link app
self._app = QApplication.instance()
# link map handle
self._map = map_handle
# load and set up UI
self.ui = UiPixelInformationWidget(self)
def clear(self):
# clear the table
self.ui.pixel_information_table_widget.clear()
def update_data(self):
# get map dimension
dimension = self._map.get_dimension()
# get data names
data_names = self._map.get_data_names()
# get fit data
fit_functions, fit_initial_parameters, fit_optimized_parameters = self._map.get_fit()
n_parameters = 4*numpy.sum(numpy.int_(fit_functions == 1)) + \
4*numpy.sum(numpy.int_(fit_functions == 2)) + \
5*numpy.sum(numpy.int_(fit_functions == 3))
# update table
self.ui.pixel_information_table_widget.setRowCount(3+len(data_names)+n_parameters+dimension)
self.ui.pixel_information_table_widget.setColumnCount(2)
self.ui.pixel_information_table_widget.horizontalHeader().setStretchLastSection(True)
self.ui.pixel_information_table_widget.horizontalHeader().hide()
self.ui.pixel_information_table_widget.verticalHeader().hide()
# add pixel number
focused_pixel = self._map.get_focus()
if dimension == 1:
name_widget = QTableWidgetItem('x pixel')
name_widget.setFlags(Qt.ItemIsEnabled)
data_widget = QTableWidgetItem(str(focused_pixel[0]))
data_widget.setFlags(Qt.ItemIsEnabled)
self.ui.pixel_information_table_widget.setItem(0, 0, name_widget)
self.ui.pixel_information_table_widget.setItem(0, 1, data_widget)
else:
name_widget = QTableWidgetItem('x pixel')
name_widget.setFlags(Qt.ItemIsEnabled)
data_widget = QTableWidgetItem(str(focused_pixel[0]))
data_widget.setFlags(Qt.ItemIsEnabled)
self.ui.pixel_information_table_widget.setItem(0, 0, name_widget)
self.ui.pixel_information_table_widget.setItem(0, 1, data_widget)
name_widget = QTableWidgetItem('y pixel')
name_widget.setFlags(Qt.ItemIsEnabled)
data_widget = QTableWidgetItem(str(focused_pixel[1]))
data_widget.setFlags(Qt.ItemIsEnabled)
self.ui.pixel_information_table_widget.setItem(1, 0, name_widget)
self.ui.pixel_information_table_widget.setItem(1, 1, data_widget)
# add data derived from spectra
names = {0: '-- integral', 1: '-- mean', 2: '-- maximum'}
for i in range(len(names)):
name_widget = QTableWidgetItem(names[i])
name_widget.setFlags(Qt.ItemIsEnabled)
data_value = self._map.get_data(data_index=i+1, pixel=-2)
data_widget = QTableWidgetItem(str(data_value))
data_widget.setFlags(Qt.ItemIsEnabled)
self.ui.pixel_information_table_widget.setItem(dimension+i, 0, name_widget)
self.ui.pixel_information_table_widget.setItem(dimension+i, 1, data_widget)
for data_id, data_name in data_names.items():
# name column
name_widget = QTableWidgetItem(data_name)
name_widget.setFlags(Qt.ItemIsEnabled)
# data column
data_value = self._map.get_data(data_index=4+data_id, pixel=-2)
data_widget = QTableWidgetItem(str(data_value))
data_widget.setFlags(Qt.ItemIsEnabled)
# add widgets to table
self.ui.pixel_information_table_widget.setItem(3+data_id+dimension, 0, name_widget)
self.ui.pixel_information_table_widget.setItem(3+data_id+dimension, 1, data_widget)
j_parameter = 0
for i_peak in range(len(fit_functions)):
if fit_functions[i_peak] > 0:
# intensity
name_widget = QTableWidgetItem('I'+str(i_peak+1))
name_widget.setFlags(Qt.ItemIsEnabled)
data_widget = QTableWidgetItem(str(fit_optimized_parameters[i_peak, 0]))
data_widget.setFlags(Qt.ItemIsEnabled)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 0, name_widget)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 1, data_widget)
j_parameter += 1
# wavelength
name_widget = QTableWidgetItem('ε'+str(i_peak+1))
name_widget.setFlags(Qt.ItemIsEnabled)
data_widget = QTableWidgetItem(str(fit_optimized_parameters[i_peak, 1]))
data_widget.setFlags(Qt.ItemIsEnabled)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 0, name_widget)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 1, data_widget)
j_parameter += 1
if fit_functions[i_peak] == 1:
# gamma
name_widget = QTableWidgetItem('γ'+str(i_peak+1))
name_widget.setFlags(Qt.ItemIsEnabled)
data_widget = QTableWidgetItem(str(1000*fit_optimized_parameters[i_peak, 2]))
data_widget.setFlags(Qt.ItemIsEnabled)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 0, name_widget)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 1, data_widget)
j_parameter += 1
# FWHM
name_widget = QTableWidgetItem('FWHM'+str(i_peak+1))
name_widget.setFlags(Qt.ItemIsEnabled)
data_widget = QTableWidgetItem(str(2*1000*fit_optimized_parameters[i_peak, 2]))
data_widget.setFlags(Qt.ItemIsEnabled)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 0, name_widget)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 1, data_widget)
j_parameter += 1
if fit_functions[i_peak] == 2:
# sigma
name_widget = QTableWidgetItem('σ'+str(i_peak+1))
name_widget.setFlags(Qt.ItemIsEnabled)
data_widget = QTableWidgetItem(str(1000*fit_optimized_parameters[i_peak, 2]))
data_widget.setFlags(Qt.ItemIsEnabled)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 0, name_widget)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 1, data_widget)
j_parameter += 1
# FWHM
name_widget = QTableWidgetItem('FWHM'+str(i_peak+1))
name_widget.setFlags(Qt.ItemIsEnabled)
data_widget = QTableWidgetItem(str(2.35482*1000*fit_optimized_parameters[i_peak, 2]))
data_widget.setFlags(Qt.ItemIsEnabled)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 0, name_widget)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 1, data_widget)
j_parameter += 1
if fit_functions[i_peak] == 3:
# sigma
name_widget = QTableWidgetItem('σ'+str(i_peak+1))
name_widget.setFlags(Qt.ItemIsEnabled)
data_widget = QTableWidgetItem(str(1000*fit_optimized_parameters[i_peak, 2]))
data_widget.setFlags(Qt.ItemIsEnabled)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 0, name_widget)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 1, data_widget)
j_parameter += 1
# gamma
name_widget = QTableWidgetItem('γ'+str(i_peak+1))
name_widget.setFlags(Qt.ItemIsEnabled)
data_widget = QTableWidgetItem(str(1000*fit_optimized_parameters[i_peak, 3]))
data_widget.setFlags(Qt.ItemIsEnabled)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 0, name_widget)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 1, data_widget)
j_parameter += 1
# FWHM
name_widget = QTableWidgetItem('FWHM'+str(i_peak+1))
name_widget.setFlags(Qt.ItemIsEnabled)
sigma = 1000*fit_optimized_parameters[i_peak, 2]
gamma = 1000*fit_optimized_parameters[i_peak, 3]
data_widget = QTableWidgetItem(str(0.5346*2.*gamma+numpy.sqrt(0.2166*4.*gamma**2.+2.35482**2.*sigma**2.)))
data_widget.setFlags(Qt.ItemIsEnabled)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 0, name_widget)
self.ui.pixel_information_table_widget.setItem(3+len(data_names)+j_parameter+dimension, 1, data_widget)
j_parameter += 1
class PixelInformationWindow(QMainWindow):
def __init__(self, parent=None):
# call widget init
QWidget.__init__(self, parent)
# link app
self._app = QApplication.instance()
# dictionary for pixel information widgets
self._pixel_information_widgets = {}
self._current_widget = None
# central widget
self.central_widget = QWidget(self)
self.central_widget.setObjectName("central_widget")
self.setCentralWidget(self.central_widget)
# grid layout
self.grid_layout = QGridLayout(self.central_widget)
self.grid_layout.setObjectName("grid_layout")
# set window title
self.setWindowTitle("Pixel Information")
def add_widget(self, map_id):
# get map handle
map_handle = self._app.maps.get_map(map_id)
# add a widget to the widgets list
self._pixel_information_widgets[map_handle.get_id()] = PixelInformationWidget(self, map_handle)
self.grid_layout.addWidget(self._pixel_information_widgets[map_handle.get_id()])
def change_widget(self, map_id):
# get map handle
map_handle = self._app.maps.get_map(map_id)
# hide all widgets
for key in self._pixel_information_widgets.keys():
self._pixel_information_widgets[key].setVisible(False)
# make the widget for the select map visible
self._pixel_information_widgets[map_handle.get_id()].setVisible(True)
self._current_widget = self._pixel_information_widgets[map_handle.get_id()]
def get_current_widget(self):
# return the current widget
return self._current_widget
def remove_widget(self, map_id):
# remove the widget of the deleted map
self._pixel_information_widgets[map_id].setParent(None)
self._pixel_information_widgets[map_id].deleteLater()
del self._pixel_information_widgets[map_id]
# close the window if there are no more maps
if len(self._pixel_information_widgets) == 0:
self._current_widget = None
self.close()
def update_data(self, map_id):
# update pixel information widget data
self._pixel_information_widgets[map_id].update_data()