pyTEMlib 0.2020.11.1__py3-none-any.whl → 0.2024.9.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pyTEMlib might be problematic. Click here for more details.

Files changed (60) hide show
  1. pyTEMlib/__init__.py +11 -11
  2. pyTEMlib/animation.py +631 -0
  3. pyTEMlib/atom_tools.py +240 -245
  4. pyTEMlib/config_dir.py +57 -33
  5. pyTEMlib/core_loss_widget.py +658 -0
  6. pyTEMlib/crystal_tools.py +1255 -0
  7. pyTEMlib/diffraction_plot.py +756 -0
  8. pyTEMlib/dynamic_scattering.py +293 -0
  9. pyTEMlib/eds_tools.py +609 -0
  10. pyTEMlib/eels_dialog.py +749 -491
  11. pyTEMlib/{interactive_eels.py → eels_dialog_utilities.py} +1199 -1177
  12. pyTEMlib/eels_tools.py +2031 -1698
  13. pyTEMlib/file_tools.py +1276 -560
  14. pyTEMlib/file_tools_qt.py +193 -0
  15. pyTEMlib/graph_tools.py +1166 -450
  16. pyTEMlib/graph_viz.py +449 -0
  17. pyTEMlib/image_dialog.py +158 -0
  18. pyTEMlib/image_dlg.py +146 -232
  19. pyTEMlib/image_tools.py +1399 -1028
  20. pyTEMlib/info_widget.py +933 -0
  21. pyTEMlib/interactive_image.py +1 -226
  22. pyTEMlib/kinematic_scattering.py +1196 -0
  23. pyTEMlib/low_loss_widget.py +176 -0
  24. pyTEMlib/microscope.py +61 -81
  25. pyTEMlib/peak_dialog.py +1047 -410
  26. pyTEMlib/peak_dlg.py +286 -242
  27. pyTEMlib/probe_tools.py +653 -207
  28. pyTEMlib/sidpy_tools.py +153 -136
  29. pyTEMlib/simulation_tools.py +104 -87
  30. pyTEMlib/version.py +6 -3
  31. pyTEMlib/xrpa_x_sections.py +20972 -0
  32. {pyTEMlib-0.2020.11.1.dist-info → pyTEMlib-0.2024.9.0.dist-info}/LICENSE +21 -21
  33. pyTEMlib-0.2024.9.0.dist-info/METADATA +92 -0
  34. pyTEMlib-0.2024.9.0.dist-info/RECORD +37 -0
  35. {pyTEMlib-0.2020.11.1.dist-info → pyTEMlib-0.2024.9.0.dist-info}/WHEEL +5 -5
  36. {pyTEMlib-0.2020.11.1.dist-info → pyTEMlib-0.2024.9.0.dist-info}/entry_points.txt +0 -1
  37. pyTEMlib/KinsCat.py +0 -2758
  38. pyTEMlib/__version__.py +0 -2
  39. pyTEMlib/data/TEMlibrc +0 -68
  40. pyTEMlib/data/edges_db.csv +0 -189
  41. pyTEMlib/data/edges_db.pkl +0 -0
  42. pyTEMlib/data/fparam.txt +0 -103
  43. pyTEMlib/data/microscopes.csv +0 -7
  44. pyTEMlib/data/microscopes.xml +0 -167
  45. pyTEMlib/data/path.txt +0 -1
  46. pyTEMlib/defaults_parser.py +0 -90
  47. pyTEMlib/dm3_reader.py +0 -613
  48. pyTEMlib/edges_db.py +0 -76
  49. pyTEMlib/eels_dlg.py +0 -224
  50. pyTEMlib/hdf_utils.py +0 -483
  51. pyTEMlib/image_tools1.py +0 -2194
  52. pyTEMlib/info_dialog.py +0 -237
  53. pyTEMlib/info_dlg.py +0 -202
  54. pyTEMlib/nion_reader.py +0 -297
  55. pyTEMlib/nsi_reader.py +0 -170
  56. pyTEMlib/structure_tools.py +0 -316
  57. pyTEMlib/test.py +0 -2072
  58. pyTEMlib-0.2020.11.1.dist-info/METADATA +0 -20
  59. pyTEMlib-0.2020.11.1.dist-info/RECORD +0 -45
  60. {pyTEMlib-0.2020.11.1.dist-info → pyTEMlib-0.2024.9.0.dist-info}/top_level.txt +0 -0
pyTEMlib/test.py DELETED
@@ -1,2072 +0,0 @@
1
- #####################################################################
2
- #
3
- # Part of Quantifit
4
- #
5
- ### SI Dialog
6
- ### contains the dialog of the Spectrum Image
7
- # - Set Slider : this does all the update things - rename for consistency
8
- # - doAllClick : analyses full SI data set
9
- # - onStoreClick: outpu in CVS file format
10
- #
11
- # #### Spectrum Image Analysis options effects 'SetSlider' and 'DoAll'
12
- # - QuantifitcheckClick
13
- # - LLcheckClick
14
- # - PeakFitClick
15
- # - EfixClick
16
- #
17
- ####################################################################
18
-
19
- from PyQt5.QtCore import *
20
- from PyQt5.QtGui import *
21
- from PyQt5.QtWidgets import *
22
-
23
- import numpy as np
24
- from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as Canvas
25
- from matplotlib.figure import Figure
26
- import math as math
27
- from matplotlib.widgets import RectangleSelector
28
- import matplotlib.gridspec as gridspec
29
- import matplotlib as mpl
30
- from mpl_toolkits.axes_grid1 import make_axes_locatable
31
-
32
- import os as os
33
-
34
- import pyqtgraph as pg
35
-
36
-
37
- # import pyqtgraph.opengl as gl
38
-
39
-
40
- class MySICanvas(Canvas):
41
- def __init__(self, parent, width=10, height=10, dpi=100):
42
- self.figure = Figure(figsize=(width, height), dpi=dpi)
43
- self.figure.subplots_adjust(bottom=.2)
44
- Canvas.__init__(self, self.figure)
45
- self.setParent(parent)
46
-
47
- Canvas.setSizePolicy(self,
48
- QSizePolicy.Expanding,
49
- QSizePolicy.Expanding)
50
-
51
- Canvas.updateGeometry(self)
52
-
53
-
54
- class SIDialog(QWidget):
55
- def __init__(self, parent):
56
- super(SIDialog, self).__init__(parent)
57
- self.parent = parent
58
- self.debug = 0
59
-
60
- foreMem = self.parent.tags['QF']['Fore']
61
- tags = self.parent.tags['QF'][str(foreMem)]
62
- si = self.parent.tags['QF']['SI'] = {}
63
-
64
- # self.nb = wx.aui.AuiNotebook(self)
65
- # sizer = wx.BoxSizer()
66
- si['Xsum'] = 0
67
- si['Ysum'] = 0
68
- si['Ssum'] = 0
69
-
70
- si['Xsize'] = 1
71
- si['Ysize'] = 1
72
-
73
- si['Xpos'] = 1
74
- si['Ypos'] = 1
75
- si['binning'] = 1
76
- si['Sliding Aver'] = 0
77
-
78
- si['select'] = []
79
- si['rectangles'] = {}
80
- self.rect = 0
81
- self.select = []
82
- self.col = QColor(0, 0, 0)
83
-
84
- '''
85
- self.square = QFrame(self)
86
- self.square.setGeometry(10, 70, 220, 220)
87
- self.square.setStyleSheet("QWidget { background-color: %s }" %
88
- self.col.name())
89
- '''
90
- self.plotSIwin = MySICanvas(self.parent, width=10, height=10, dpi=70)
91
-
92
- # Defining a plot instance (axes) and asigning a variable to it
93
- self.plotSIwin.axes = self.plotSIwin.figure.add_subplot(1, 1, 1)
94
- self.plotSIwin.axes.set_axis_off()
95
- # self.plotSIwin.axes.hold(False)
96
-
97
- cid = self.plotSIwin.mpl_connect('button_press_event', self.onMouseButtonClick)
98
-
99
- # cid = self.plotSIwin.mpl_connect('button_release_event', self.onMouseReleaseClick)
100
-
101
- plotLayout = QGridLayout()
102
-
103
- # Ading SI image and sliders to the layout
104
- plotLayout.addWidget(self.plotSIwin, 0, 0)
105
-
106
- self.slider1 = QSlider(Qt.Horizontal, self)
107
-
108
- self.slider2 = QSlider(Qt.Vertical, self)
109
-
110
- self.slider1.valueChanged[int].connect(self.sliderUpdate)
111
- self.slider1.setMinimum(1)
112
-
113
- self.slider2.valueChanged[int].connect(self.sliderUpdate)
114
- self.slider2.setMinimum(1)
115
-
116
- plotLayout.addWidget(self.slider2, 0, 1)
117
- plotLayout.addWidget(self.slider1, 1, 0)
118
-
119
- # making a single widget out of image and slider
120
- siPlot = QWidget()
121
- siPlot.setLayout(plotLayout)
122
-
123
- layout = QGridLayout()
124
- layout.setVerticalSpacing(2)
125
- # self.setMaximumHeight(500)
126
-
127
- self.label = QLabel()
128
- self.label.setText(
129
- "<font style='color: white;background: blue;'> Spectrum Image Sliders </font>")
130
- layout.addWidget(self.label, 0, 0, 1, 3)
131
- layout.addWidget(siPlot, 1, 0, 1, 3)
132
-
133
- i = 10
134
- self.Xcheck = QCheckBox('sum X')
135
- layout.addWidget(self.Xcheck, i, 0)
136
- self.Xcheck.clicked.connect(self.XcheckClick)
137
-
138
- self.Ycheck = QCheckBox('sum Y')
139
- layout.addWidget(self.Ycheck, i, 1)
140
- self.Ycheck.clicked.connect(self.YcheckClick)
141
-
142
- self.Scheck = QCheckBox('selected')
143
- layout.addWidget(self.Scheck, i, 2)
144
- self.Scheck.clicked.connect(self.selectSumClick)
145
-
146
- i += 1
147
- self.sScheck = QCheckBox('show Sum')
148
- layout.addWidget(self.sScheck, i, 0)
149
- self.sScheck.setChecked(True)
150
- self.sScheck.clicked.connect(self.showSUMclick)
151
-
152
- self.sZcheck = QCheckBox('show Z')
153
- layout.addWidget(self.sZcheck, i, 1)
154
- self.sZcheck.clicked.connect(self.showZclick)
155
-
156
- self.sBcheck = QCheckBox('show BF')
157
- layout.addWidget(self.sBcheck, i, 2)
158
- self.sBcheck.clicked.connect(self.showBFclick)
159
-
160
- i += 1
161
- self.label2 = QLabel()
162
- self.label2.setText(
163
- "<font style='color: white;background: blue;'> Spectrum Image Processing </font>")
164
- layout.addWidget(self.label2, i, 0, 1, 3)
165
- self.setLayout(layout)
166
-
167
- i += 1
168
- self.QBinLabel = QLabel('Binning')
169
- layout.addWidget(self.QBinLabel, i, 0)
170
- self.binList = ['1x1', '2x2', '4x4']
171
- self.BinEList = QComboBox()
172
- self.BinEList.setEditable(False)
173
- self.BinEList.addItems(self.binList)
174
- self.BinEList.activated[str].connect(self.OnBinListEnter)
175
- layout.addWidget(self.BinEList, i, 1)
176
- self.QSlidecheck = QCheckBox('Sliding')
177
- layout.addWidget(self.QSlidecheck, i, 2)
178
- self.QSlidecheck.clicked.connect(self.SlidecheckClick)
179
-
180
- i += 1
181
- self.Qcheck = QCheckBox('QFit')
182
- layout.addWidget(self.Qcheck, i, 0)
183
- self.Qcheck.clicked.connect(self.QuantifitcheckClick)
184
-
185
- self.doAllButton = QPushButton("Do All")
186
- layout.addWidget(self.doAllButton, i, 1)
187
- self.doAllButton.clicked.connect(self.doAllClick)
188
-
189
- self.Lcheck = QCheckBox('LL')
190
- layout.addWidget(self.Lcheck, i, 2)
191
- self.Lcheck.clicked.connect(self.LLcheckClick)
192
-
193
- i += 1
194
-
195
- self.Pcheck = QCheckBox('PFit')
196
- layout.addWidget(self.Pcheck, i, 0)
197
- self.Pcheck.clicked.connect(self.PeakFitClick)
198
-
199
- self.storeButton = QPushButton("Store")
200
- layout.addWidget(self.storeButton, i, 1)
201
- # do not do anything, this is a dummy button
202
- self.storeButton.clicked.connect(self.OnStoreClick)
203
-
204
- self.Echeck = QCheckBox('Fix E')
205
- layout.addWidget(self.Echeck, i, 2)
206
- self.Echeck.clicked.connect(self.EfixClick)
207
-
208
- #
209
- # respond to changes in slider position ...
210
- #
211
- # self.Bind(wx.EVT_SLIDER, self.sliderUpdate)
212
-
213
- # self.SetSizerAndFit(sizer)
214
-
215
- self.setSlider()
216
-
217
- '''
218
- ####################################
219
- # Set Values
220
- ####################################
221
- self.R_outcheck.SetValue(parent.Rout)
222
- self.S_outcheck.SetValue(parent.Sout)
223
- self.R_verbosecheck.SetValue(parent.Vout)
224
- '''
225
-
226
- def OnBinListEnter(self):
227
- si = self.parent.tags['QF']['SI']
228
- eNum = self.BinEList.currentIndex()
229
- if eNum == 0:
230
- si['binning'] = 1
231
- if eNum == 1:
232
- si['binning'] = 2
233
- if eNum == 2:
234
- si['binning'] = 4
235
- print(eNum, self.binList[eNum])
236
-
237
- def SlidecheckClick(self):
238
- self.parent.tags['QF']['SI']['Sliding Aver'] = self.QSlidecheck.isChecked()
239
-
240
- def OnStoreClick(self):
241
- foreMem = self.parent.tags['QF']['Fore']
242
- qf = self.parent.tags['QF'][str(foreMem)]
243
- si = self.parent.tags['QF']['SI']
244
-
245
- height = si['data'].shape[1]
246
- width = si['data'].shape[0]
247
-
248
- if si['Xsum'] + si['Ysum'] > 0:
249
- if 'LS' not in qf['Results']:
250
- qf['Results']['LS'] = {}
251
- res = qf['Results']['LS']
252
- datashape = 1
253
- else:
254
- if 'SI' not in qf['Results']:
255
- qf['Results']['SI'] = {}
256
- res = qf['Results']['SI']
257
- datashape = 2
258
-
259
- eNum = qf['whichEdge']
260
- if eNum == 6:
261
- gtags = qf['GF']['LL']
262
- else:
263
- gtags = qf['GF'][str(eNum)]
264
- self.LLGauss = 0
265
- '''
266
- if si['Pcheck']:
267
- if qf['plotmode'] == 1: # output in number of electrons
268
- scaleP = scaleP* qf['norm']
269
- unit = ' [# e-]'
270
-
271
- if qf['plotmode'] == 2: # output in areal density
272
- multp = 1e10 # xsec is in barns = 10^28 m2 = 10^10 nm2
273
- scaleP = scaleP* qf['norm']*multp ## check this
274
- unit = ' [# atoms/nm2]'
275
- res['unitGFa'+str(eNum)] = unit # Gerd implement
276
- res['scaleGFa'+str(eNum)] = scaleP
277
- nGauss = gtags['numGauss']
278
- x = int(si('Xpos'))
279
- y = int(si('Ypos'))
280
-
281
- for i in range(int(nGauss)):
282
- res['GF'+str(eNum)][x,y,i*3] = gtags['gaussF'][str(i)]['peakPos']
283
- res['GF'+str(eNum)][x,y,i*3+1] = gtags['gaussF'][str(i)]['peakAmpl'] * scaleP
284
- res['GF'+str(eNum)][x,y,i*3+2] = gtags['gaussF'][str(i)]['peakWidth']
285
-
286
- #plotSIoutput(self)
287
-
288
- if si['Qcheck']:
289
- res['GF']=self.pQF
290
- self.pQF[i,j,:] = self.parent.spec[foreMem].FitModel(0)
291
- '''
292
- import csv
293
- if datashape == 1:
294
- with open(qf['filename'] + '-LS.csv', 'w', newline='') as csvfile:
295
- xlwriter = csv.writer(csvfile, dialect='excel', delimiter=',', )
296
- xlwriter.writerow(['File Name', qf['filename']])
297
- res = qf['Results']['LS']
298
-
299
- xlwriter.writerow(['X-Scale', res['xscale']])
300
- xlwriter.writerow(['Y-units', res['unit']])
301
- xlwriter.writerow(['Y-scale', res['scale']])
302
- xlwriter.writerow(['Y-scaleP', res['scaleP']])
303
-
304
- #########################
305
- # Write titles
306
- #########################
307
-
308
- columns = 0
309
- title = []
310
- title.append('distance [' + si['Xunit'] + ']')
311
-
312
- if si['Qcheck'] > 0:
313
-
314
- for i in range(int(qf['numberOfEdges'])):
315
- columns += 1
316
- title.append(res['QF-legend'][str(i)])
317
- columns += 1
318
- title.append('SUM')
319
- for i in range(int(qf['numberOfEdges'])):
320
- columns += 1
321
- title.append(res['QF-legend'][str(i)] + '[atom%]')
322
- if si['Efix']:
323
- columns += 1
324
- title.append('Eshift')
325
- if si['LLcheck']:
326
- columns += 1
327
- title.append('ZL width')
328
- if si['Pcheck']:
329
- for i in range(int(gtags['numGauss'])):
330
- columns += 1
331
- title.append('Peak ' + str(i + 1) + ' Position Edge' + str(eNum))
332
- columns += 1
333
- title.append('Peak ' + str(i + 1) + ' Area Edge' + str(eNum))
334
- columns += 1
335
- title.append('Peak ' + str(i + 1) + ' Width Edge' + str(eNum))
336
-
337
- xlwriter.writerow(title)
338
- #########################
339
- # Write Values
340
- #########################
341
-
342
- for l in range(res['Length']):
343
- value = []
344
-
345
- value.append('=' + str(l) + '*$B$2')
346
- if si['Qcheck'] > 0:
347
- numE = int(qf['numberOfEdges'])
348
- sumE = 0
349
- for i in range(numE):
350
- value.append('=' + str(res['QF'][l, i]) + '*$B$4')
351
- sumE += res['QF'][l, i]
352
- value.append('=' + str(sumE) + '*$B$4')
353
- for i in range(numE):
354
- value.append('=' + str(res['QF'][l, i] / sumE * 100.0))
355
-
356
- if si['Pcheck']:
357
- for i in range(int(gtags['numGauss'])):
358
- value.append('=' + str(res['GFp' + str(eNum)][l, i]))
359
- value.append('=' + str(res['GFa' + str(eNum)][l, i]) + '*$B$5')
360
- value.append('=' + str(res['GFw' + str(eNum)][l, i]))
361
-
362
- xlwriter.writerow(value)
363
- if datashape == 2:
364
-
365
- with open(qf['filename'] + '-IM.csv', 'w', newline='') as csvfile:
366
- xlwriter = csv.writer(csvfile, dialect='excel', delimiter=',', )
367
- xlwriter.writerow(['File Name', qf['filename']])
368
- # xlwriter.writerow(['X-Scale',xscale])
369
- # xlwriter.writerow(['Z-units',res['unit']])
370
- # xlwriter.writerow(['Z-scale',res['scale']])
371
- # xlwriter.writerow(['Z-scaleP',res['scaleP']])
372
-
373
- for i in range(si['numOutImages']):
374
- imI = si['images'][str(i)]
375
- xlwriter.writerow([str(imI['name'])])
376
- im = imI['image']
377
- for j in range(im.shape[1]):
378
- xlwriter.writerow(im[:, j])
379
-
380
- def setSlider(self):
381
- # print('setslider')
382
-
383
- foreMem = self.parent.tags['QF']['Fore']
384
- qf = self.parent.tags['QF'][str(foreMem)].tags
385
-
386
- si = self.parent.tags['QF']['SI']
387
-
388
- if 'LLSI' not in qf:
389
- qf['LLSI'] = 'False'
390
-
391
- def line_select_callback(eclick, erelease):
392
- 'eclick and erelease are the press and release events'
393
- x1, y1 = eclick.xdata, eclick.ydata
394
- x2, y2 = erelease.xdata, erelease.ydata
395
-
396
- if self.debug > 0:
397
- print("(%3.2f, %3.2f) --> (%3.2f, %3.2f)" % (x1, y1, x2, y2))
398
- print(" The button you used were: %s %s" % (eclick.button, erelease.button))
399
-
400
- if x1 > x2:
401
- x1 = int(x2 + 0.5)
402
- x2 = int(x1 + 0.5)
403
- else:
404
- x1 = int(x1 + 0.5)
405
- x2 = int(x2 + 0.5)
406
- if y1 > y2:
407
- y1 = int(y2 + 0.5)
408
- y2 = int(y1 + 0.5)
409
- else:
410
- y1 = int(y1 + 0.5)
411
- y2 = int(y2 + 0.5)
412
-
413
- if erelease.button == 3:
414
- if self.parent.tags['QF']['SI']['Ssum'] > 0:
415
- print("(%3.2f, %3.2f) --> (%3.2f, %3.2f)" % (x1, y1, x2, y2))
416
- for i in range(x1, x2):
417
- for j in range(y1, y2):
418
- if (i, j) not in si['select']:
419
- si['select'].append((i, j))
420
- self.rect += 1
421
- si['rectangles'][str(self.rect)] = [x1, y1, x2 - x1, y2 - y1]
422
- # print( si['select'])
423
- self.setSlider()
424
-
425
- if erelease.button == 1:
426
- if self.parent.tags['QF']['SI']['Ssum'] > 0:
427
- si['select'] = []
428
- print("(%d, %d) --> (%d, %d)" % (x1, y1, x2, y2))
429
- for i in range(x1, x2):
430
- for j in range(y1, y2):
431
- self.rect = 0
432
- if (i, j) not in si['select']:
433
- si['select'].append((i, j))
434
- self.rect = 1
435
- si['rectangles'][str(self.rect)] = [x1, y1, x2 - x1, y2 - y1]
436
- print(si['select'])
437
- self.setSlider()
438
-
439
- def toggle_selector(event):
440
- if self.debug > 0:
441
- print(' Key pressed.')
442
- if event.key() in ['Q', 'q'] and toggle_selector.RS.active:
443
- print(' RectangleSelector deactivated.')
444
- toggle_selector.RS.set_active(False)
445
- if event.key() in ['A', 'a'] and not toggle_selector.RS.active:
446
- print(' RectangleSelector activated.')
447
- toggle_selector.RS.set_active(True)
448
-
449
- if 'Xpos' in si:
450
-
451
- # if self.debug > 0:
452
- # print(si['Xpos'],si['Ypos'])
453
- if si['Xpos'] < 1:
454
- si['Xpos'] = 1
455
- if si['Ypos'] < 1:
456
- si['Ypos'] = 1
457
- self.slider1.setMaximum(si['Xsize'])
458
- self.slider1.setMinimum(1)
459
- self.slider2.setMinimum(1)
460
- self.slider2.setMaximum(si['Ysize'])
461
- self.slider2.setInvertedAppearance(True)
462
- self.slider1.setTracking(True)
463
- self.slider2.setTracking(True)
464
- self.slider2.setTickPosition(QSlider.TicksRight)
465
- # self.slider2.setTickInterval(1)
466
- self.slider1.setTickPosition(QSlider.TicksBelow)
467
-
468
- ene = np.array(qf['ene']).copy()
469
-
470
- # self.plotSIwin.axes.hold(False)
471
-
472
- if 'data' in si:
473
-
474
- if len(si['data']) == 0:
475
- return
476
- if len(ene) != si['data'].shape[2]:
477
- qf.update(self.parent.tags['QF']['SI']['specTags'])
478
- ene = np.array(qf['ene']).copy()
479
-
480
- # print('print image')
481
- height = si['data'].shape[1]
482
- width = si['data'].shape[0]
483
-
484
- LSdisplay = False
485
- if height == 1:
486
- LSdisplay = True
487
- if self.debug > 0:
488
- print('LS display')
489
- im = np.zeros((width, height, 3))
490
- title = []
491
- numOutImages = 0
492
- if 'showZ' not in si:
493
- si['showZ'] = False
494
-
495
- self.showZ = si['showZ']
496
-
497
- if 'showBF' not in si:
498
- si['showBF'] = False
499
-
500
- self.showBF = si['showBF']
501
-
502
- if 'showSum' not in si:
503
- si['showSum'] = False
504
-
505
- self.showSum = si['showSum']
506
-
507
- self.showZa = 0
508
- self.showBFa = 0
509
- self.showSuma = 0
510
-
511
- if self.showZ:
512
- self.showZa = 1
513
- # im[:,:,numOutImages] = np.array(si['Zcontrast']).copy()
514
- title.append('Z-contrast')
515
- numOutImages += 1
516
- if self.debug > 0:
517
- print('add Z')
518
-
519
- if self.showBF:
520
- self.showBFa = 1
521
- # im[:,:,numOutImages] = (si['BrightField'])
522
- title.append('Bright Field')
523
- numOutImages += 1
524
-
525
- if self.showSum or numOutImages == 0:
526
- self.showSa = 1
527
- self.showSum = True
528
- im[:, :, numOutImages] = np.sum(si['data'], axis=2)
529
- title.append('sum')
530
- numOutImages += 1
531
- pl = self.plotSIwin
532
- pl.figure.clear()
533
-
534
- if LSdisplay:
535
- axes = pl.figure.add_subplot(1, 1, 1)
536
- data = np.sum(si['data'], axis=2)
537
- axes.plot(range(1, width + 1), data[:, 0])
538
- if self.debug > 0:
539
- print('at do spectrum')
540
- si['Ypos'] = 1
541
- qf['spec'] = np.array(si['data'][si['Xpos'] - 1, 0, :]).copy()
542
- axes.plot(si['Xpos'], data[si['Xpos'] - 1, 0], 'o')
543
- qf['name'] = 'Spect. ' + str(si['Xpos'])
544
-
545
- # self.parent.SelectDialog.MemoryAssign(qf['spec'],ene,foreMem,1,qf['name'],qf)
546
- # self.plotSIwin.draw()
547
-
548
- else:
549
- debug = 0
550
- # print('Should not be here')
551
- ########### Determine Best Grid Layout #########
552
- grid_x = int(np.sqrt(height * width * numOutImages) / height + 0.5)
553
- if grid_x < 1:
554
- grid_x = 1
555
-
556
- grid_y = math.ceil(numOutImages / grid_x)
557
- if self.debug > 0:
558
- print(numOutImages, grid_x, grid_y)
559
-
560
- gs = gridspec.GridSpec(grid_x, grid_y)
561
-
562
- ######## initialize plot #####
563
- pl.figure.set_tight_layout(True)
564
-
565
- axes = []
566
- myImage = []
567
- index = 0
568
-
569
- ## plot figures
570
- for i in range(grid_x):
571
- for j in range(grid_y):
572
-
573
- axes.append(pl.figure.add_subplot(gs[i, j]))
574
- if self.debug > 0:
575
- print('index & numoutimages', index, numOutImages)
576
-
577
- if self.showZa > 0:
578
- myImage.append(axes[index].imshow(np.transpose(si['Zcontrast']), origin='upper', ))
579
- self.showZa = 0
580
- axes[index].set_title(title[index])
581
- elif self.showBFa > 0:
582
- myImage.append(axes[index].imshow(np.transpose(si['BrigthField']), origin='upper', ))
583
- self.showBFa = 0
584
- axes[index].set_title(title[index])
585
- elif self.showSa > 0:
586
- myImage.append(axes[index].imshow(np.transpose(im[:, :, index]), origin='upper', ))
587
- # pl.figure.colorbar(myImage[index], ax=axes[index], orientation='vertical')
588
- axes[index].set_title(title[index])
589
- if self.debug > 0:
590
- print(myImage[index])
591
-
592
- index += 1
593
- if index == numOutImages:
594
- break
595
- if index == numOutImages:
596
- if self.debug > 0:
597
- print(index)
598
- print(im[:, :, index - 1])
599
- print('drawing')
600
- pl.draw()
601
- break
602
-
603
- if self.debug > 0:
604
- print('past drawing')
605
- # self.plotSIwin.axes.hold(True)
606
-
607
- # Make select array
608
- for i in range(numOutImages):
609
- if self.debug > 0:
610
- print(i, numOutImages)
611
- myImage[i].set_extent((0.5, width + 0.5, height + 0.5, 0.5))
612
-
613
- axes[i].set_xlim(0.5, width + 0.5)
614
- axes[i].set_ylim(height + 0.5, +0.5)
615
-
616
- if self.debug > 0:
617
- print('set limits drawing')
618
-
619
- '''
620
- if len(self.select) == 0:
621
- self.select = np.zeros((height, width),'uint8')
622
- if height != self.select.shape[0]:
623
- del(self.select)
624
- self.select = np.zeros((height, width),'uint8')
625
- if width != self.select.shape[1] :
626
- del(self.select)
627
- self.select = np.zeros((height, width),'uint8')
628
- '''
629
-
630
- qf['expTime'] = si['expTime']
631
- if si['Xsum'] + si['Ysum'] == 0:
632
- if self.debug > 0:
633
- print('at do spectrum')
634
- if 'spec' not in qf:
635
- print('no spec')
636
- qf['spec'] = np.zeros(len(qf['spec']))
637
-
638
- for k in range(si['binning']):
639
- for l in range(si['binning']):
640
- if i + l < si['data'].shape[0]:
641
- if j + k < si['data'].shape[1]:
642
- qf['spec'] = qf['spec'] + np.array(
643
- si['data'][si['Xpos'] - 1 + k, si['Ypos'] - 1 + l, :])
644
- qf['expTime'] = si['expTime'] * si['binning'] * si['binning']
645
- if qf['LLSI'] == 'True':
646
- qf['LorentzLL'] = np.array(si['LLdata'][si['Xpos'] - 1, si['Ypos'] - 1, :]).copy()
647
- for i in range(numOutImages):
648
- axes[i].plot(si['Xpos'], si['Ypos'], 'o')
649
- qf['name'] = 'Spect. ' + str(si['Xpos']) + ',' + str(si['Ypos'])
650
-
651
- elif si['Xsum'] > 0:
652
- if self.debug > 0:
653
- print('xsum')
654
- for j in range(numOutImages):
655
- for i in range(1, si['data'].shape[0] + 1):
656
- axes[j].plot(i, si['Ypos'], 'o')
657
- cts = np.array(np.sum(si['data'], axis=0))
658
- qf['spec'] = np.array(cts[si['Ypos'] - 1]).copy()
659
- qf['name'] = 'Row ' + str(si['Ypos'])
660
- qf['expTime'] = si['expTime'] * si['data'].shape[0]
661
-
662
- if qf['LLSI'] == 'True':
663
- llcts = np.array(np.sum(si['LLdata'], axis=0))
664
- qf['LorentzLL'] = np.array(llcts[si['Ypos'] - 1]).copy()
665
-
666
- if si['Ysum'] > 0:
667
- for j in range(numOutImages):
668
- for i in range(1, si['data'].shape[1] + 1):
669
- axes[j].plot(si['Xpos'], i, 'o')
670
- cts = np.array(np.sum(si['data'], axis=1))
671
- qf['expTime'] = si['expTime'] * si['data'].shape[1]
672
-
673
- qf['spec'] = np.array(cts[si['Xpos'] - 1]).copy()
674
- qf['name'] = 'Column ' + str(si['Xpos'])
675
-
676
- if qf['LLSI'] == 'True':
677
- llcts = np.array(np.sum(si['LLdata'], axis=1))
678
- qf['LorentzLL'] = np.array(llcts[si['Xpos'] - 1]).copy()
679
-
680
- if si['Ssum'] > 0:
681
- if self.rect > 0:
682
- self.parent.text2.insertPlainText('\n rectangles of Selected Spectra: ')
683
- for i in range(self.rect):
684
- pos = si['rectangles'][str(i + 1)]
685
- self.parent.text2.insertPlainText(str(pos[2]) + ' x ' + str(pos[3]) + ',')
686
- rect = mpl.patches.Rectangle((pos[0], pos[1]), pos[2], pos[3], alpha=0.350, ec='black',
687
- fc="Blue")
688
- for j in range(numOutImages):
689
- axes[j].add_patch(rect)
690
- spec = np.zeros(len(qf['spec']))
691
- self.parent.text2.insertPlainText('\n Selected Spectra: ')
692
- k = 0
693
- for pos in si['select']:
694
- k += 1
695
- fp = np.array(si['data'][pos[0] - 1, pos[1] - 1, :])
696
- if si['Efix']:
697
- pG = self.parent.tags['QF'][foreMem].fixE(fp)
698
- if k == 1:
699
- qf['ene'] = qf['ene'] - pG[1]
700
-
701
- else:
702
- x = qf['ene'] - pG[1]
703
- fp = np.interp(x, qf['ene'], fp)
704
- spec = spec + fp # Gerd May need a -1
705
-
706
- self.parent.text2.insertPlainText(str(pos) + ' , ')
707
- qf['expTime'] = si['expTime'] * k
708
-
709
- qf['spec'] = spec
710
- qf['name'] = 'Selected'
711
-
712
- toggle_selector.RS = RectangleSelector(axes[0], line_select_callback,
713
- drawtype='box', useblit=True,
714
- button=[1, 3], # don't use middle button
715
- minspanx=5, minspany=5,
716
- spancoords='pixels')
717
- self.plotSIwin.mpl_connect('key_press_event', toggle_selector)
718
-
719
-
720
-
721
- else:
722
- if self.debug > 0:
723
- print('no data did not do anything')
724
- return
725
-
726
- self.parent.tags['QF'][str(foreMem)].SetConv()
727
- # MemoryAssign(self,key,mem,fore,bank,name,spectrum)
728
- self.parent.SelectDialog.MemoryAssign('spec', foreMem, 1, 'QF', qf['name'], foreMem)
729
- # print(self.parent.tags['QF'][]
730
- ypos = si['Ypos']
731
- self.slider1.setValue(si['Xpos'])
732
-
733
- self.slider2.setValue(ypos)
734
- si['Ypos'] = ypos
735
-
736
- self.plotSIwin.draw()
737
-
738
- ## Current Spectrum Analysis
739
-
740
- if 'LLcheck' not in si:
741
- si['LLcheck'] = False
742
- if 'Qcheck' not in si:
743
- si['Qcheck'] = False
744
- if 'Pcheck' not in si:
745
- si['Pcheck'] = False
746
- if 'Efix' not in si:
747
- si['Efix'] = False
748
-
749
- self.Lcheck.setCheckState(si['LLcheck'])
750
- self.Qcheck.setCheckState(si['Qcheck'])
751
- self.Pcheck.setCheckState(si['Pcheck'])
752
- self.Echeck.setCheckState(si['Efix'])
753
- self.Xcheck.setCheckState(si['Xsum'])
754
- # print ('XSum ' , si['Xsum'])
755
- self.Ycheck.setCheckState(si['Ysum'])
756
- self.sZcheck.setCheckState(si['showZ'])
757
- self.sBcheck.setCheckState(si['showBF'])
758
- self.sScheck.setCheckState(si['showSum'])
759
-
760
- if si['Efix']:
761
- self.parent.LLDialog.OnEFixClick()
762
- if si['LLcheck']:
763
- self.parent.LLDialog.OnSSDClick()
764
-
765
- if si['Qcheck']:
766
- self.parent.QuantifitDialog.QuantifitClick()
767
- if self.debug > 0:
768
- print('Qcheck')
769
- if si['Pcheck']:
770
- self.parent.gFitDialog.GaussFitClick()
771
-
772
- self.parent.text2.ensureCursorVisible()
773
- self.parent.plotUpdate('Select')
774
- self.parent.tags['QF']['SI']['specTags'] = qf
775
- if self.debug > 0:
776
- print('update')
777
-
778
- def keyPressEvent(self, event):
779
-
780
- si = self.parent.tags['QF']['SI']
781
- # QMessageBox.information(None,"Received Key Press Event!!","You Pressed: "+ event.text())
782
- signals = ['u', 'd', 'l', 'r', '4', '2', '8', '6']
783
- move = event.text()
784
-
785
- # print(event.text())
786
- # print(event.key())
787
-
788
- if '1' in si['rectangles']:
789
- print(si['rectangles']['1'])
790
- if event.text() not in signals:
791
- if event.key() == 16777234:
792
- move = 'left'
793
- elif event.key() == 16777236:
794
- move = 'right'
795
- elif event.key() == 16777235:
796
- move = 'up'
797
- elif event.key() == 16777237:
798
- move = 'down'
799
- else:
800
- if move == '2' or move == 'd':
801
- move = 'down'
802
- elif move == '8' or move == 'u':
803
- move = 'up'
804
- elif move == '4' or move == 'l':
805
- move = 'left'
806
- elif move == '6' or move == 'r':
807
- move = 'right'
808
- if self.rect == 1:
809
- if move == 'left':
810
- print('event l')
811
- si['rectangles'][str(1)][0] = si['rectangles'][str(1)][0] - 1
812
- if si['rectangles'][str(1)][0] < 1:
813
- si['rectangles'][str(1)][0] = 1
814
- elif move == 'right':
815
- print('event r')
816
- si['rectangles'][str(1)][0] = si['rectangles'][str(1)][0] + 1
817
- if si['rectangles'][str(1)][0] < 1:
818
- si['rectangles'][str(1)][0] = 1
819
- elif move == 'up':
820
- print('event u')
821
- si['rectangles'][str(1)][1] = si['rectangles'][str(1)][1] - 1
822
- if si['rectangles'][str(1)][1] < 1:
823
- si['rectangles'][str(1)][1] = 1
824
- elif move == 'down':
825
- print('event d')
826
- si['rectangles'][str(1)][1] = si['rectangles'][str(1)][1] + 1
827
- if si['rectangles'][str(1)][1] < 1:
828
- si['rectangles'][str(1)][1] = 1
829
- si['select'] = []
830
- for i in range(si['rectangles'][str(1)][0], si['rectangles'][str(1)][0] + si['rectangles'][str(1)][2]):
831
- for j in range(si['rectangles'][str(1)][1], si['rectangles'][str(1)][1] + si['rectangles'][str(1)][3]):
832
- si['select'].append((i, j))
833
- self.setSlider()
834
- else:
835
- if 'Xpos' in si:
836
- if move == 'left':
837
- si['Xpos'] -= 1
838
- if move == 'right':
839
- si['Xpos'] += 1
840
- if si['Xpos'] > si['data'].shape[0]:
841
- si['Xpos'] = si['data'].shape[0]
842
- if move == 'up':
843
- si['Ypos'] -= 1
844
- if move == 'down':
845
- si['Ypos'] += 1
846
- if si['Ypos'] > si['data'].shape[1]:
847
- si['Ypos'] = si['data'].shape[1]
848
- self.setSlider()
849
- # self.slider1.setValue(si['Xpos'])
850
- # self.slider2.setValue(si['Ypos'])
851
-
852
- def QuantifitcheckClick(self):
853
- self.parent.tags['QF']['SI']['Qcheck'] = self.Qcheck.isChecked()
854
-
855
- def LLcheckClick(self):
856
- self.parent.tags['QF']['SI']['LLcheck'] = self.Lcheck.isChecked()
857
-
858
- def PeakFitClick(self):
859
- self.parent.tags['QF']['SI']['Pcheck'] = self.Pcheck.isChecked()
860
-
861
- def EfixClick(self):
862
- self.parent.tags['QF']['SI']['Efix'] = self.Echeck.isChecked()
863
-
864
- def showBFclick(self):
865
- self.showBF = self.sBcheck.isChecked()
866
- si = self.parent.tags['QF']['SI']
867
-
868
- if 'showBF' not in si:
869
- si['showBF'] = True
870
-
871
- if si['showBF']:
872
- si['showBF'] = False
873
- else:
874
- si['showBF'] = True
875
-
876
- self.showBF = si['showBF']
877
-
878
- if self.showBF:
879
-
880
- if len(si['BrightField']) == 0:
881
- if self.debug > 0:
882
- print(' read image')
883
- try:
884
- path = settings.value("path")
885
- if self.debug > 0:
886
- print('Found path ' + path)
887
- except:
888
- print('path not read')
889
- filename, filters = QFileDialog.getOpenFileName(self,
890
- 'Open a Bright field Image', self.parent.path,
891
- 'DM files (*.dm3);;QF files (*.qf3);;QF session (*.qfs);;All Files (*.*)')
892
-
893
- self.parent.path, fname = os.path.split(filename)
894
- extension = os.path.splitext(filename)[1][1:]
895
- if extension == 'dm3':
896
- si['BrightField'] = self.parent.readdm3Image(filename)
897
- self.setSlider()
898
- else:
899
- self.sBcheck.toggle()
900
- self.showBF = False
901
- si['showBF'] = self.showBF
902
- return
903
- self.setSlider()
904
-
905
- def showZclick(self):
906
-
907
- self.showZ = self.sZcheck.isChecked()
908
- si = self.parent.tags['QF']['SI']
909
-
910
- if 'showZ' not in si:
911
- si['showZ'] = True
912
-
913
- if si['showZ']:
914
- si['showZ'] = False
915
- else:
916
- si['showZ'] = True
917
-
918
- self.showZ = si['showZ']
919
- if self.showZ:
920
- if len(si['Zcontrast']) == 0:
921
- if self.debug > 0:
922
- print(' read Zcontrast image')
923
- try:
924
- path = settings.value("path")
925
- if self.debug > 0:
926
- print('Found path ' + path)
927
- except:
928
- print('path not read')
929
- filename, filters = QFileDialog.getOpenFileName(self,
930
- 'Open a spectrum', self.parent.path,
931
- 'DM files (*.dm3);;QF files (*.qf3);;QF session (*.qfs);;All Files (*.*)')
932
-
933
- self.path, fname = os.path.split(filename)
934
- extension = os.path.splitext(filename)[1][1:]
935
- if extension == 'dm3':
936
- si['Zcontrast'] = self.parent.readdm3Image(filename)
937
- self.setSlider()
938
- else:
939
- self.sZcheck.toggle()
940
- self.showZ = False
941
- si['showZ'] = self.showZ
942
- return
943
-
944
- self.setSlider()
945
-
946
- # 0516
947
-
948
- def showSUMclick(self):
949
- si = self.parent.tags['QF']['SI']
950
- if 'showSum' not in si:
951
- si['showSum'] = True
952
-
953
- if si['showSum']:
954
- si['showSum'] = False
955
- else:
956
- si['showSum'] = True
957
- self.showSum = self.sScheck.isChecked()
958
- self.showSum = si['showSum']
959
- self.setSlider()
960
-
961
- #########################################
962
- ### 1D data plotting #############
963
- #####################################
964
- def plotSI(self):
965
- print('1D data plotting')
966
- foreMem = self.parent.tags['QF']['Fore']
967
- qf = self.parent.tags['QF'][str(foreMem)].tags
968
- si = self.parent.tags['QF']['SI']
969
-
970
- eNum = qf['whichEdge']
971
- if eNum == 6:
972
- gtags = qf['GF']['LL']
973
- else:
974
- gtags = qf['GF'][str(eNum)]
975
- self.LLGauss = 0
976
-
977
- height = si['data'].shape[1]
978
- width = si['data'].shape[0]
979
-
980
- spec = qf['spec']
981
-
982
- # we do LS data first and define resolution dictionary as such
983
- if 'LS' not in qf['Results']:
984
- return
985
- res = qf['Results']['LS']
986
-
987
- xscale = res['xscale']
988
- dimen = res['Length']
989
-
990
- # Here OUTPUT BEGINS
991
-
992
- if self.parent.tab.tabText(2) == 'SI':
993
- plot = pg.PlotItem()
994
-
995
- self.parent.plotParamWindow3 = pg.GraphicsWindow()
996
- plot = self.parent.plotParamWindow3
997
- plot3 = QWidget()
998
- plotLayout3 = QVBoxLayout()
999
- plotLayout3.addWidget(plot)
1000
- plot3.setLayout(plotLayout3)
1001
-
1002
- self.parent.tab.removeTab(2)
1003
- self.parent.tab.insertTab(2, plot3, 'SI LS')
1004
-
1005
- self.parent.tab.setCurrentIndex(2)
1006
- plot = self.parent.plotParamWindow3
1007
- # plot.clear()
1008
- col = self.parent.tags['QF']['Colors']
1009
- lin = self.parent.tags['QF']['LineWidth']
1010
-
1011
- # Enable antialiasing for prettier plots
1012
- pg.setConfigOptions(antialias=True)
1013
-
1014
- #########################################################
1015
- ## Output to SI Window
1016
- #########################################################
1017
-
1018
- scale = np.ones((dimen))
1019
- scaleP = 1.0
1020
- unit = 'counts'
1021
- if si['Qcheck']:
1022
-
1023
- if qf['plotmode'] == 0: # output in atom %
1024
- if np.sum(self.pQF[:, 0:qf['numberOfEdges']], axis=1).any == 0:
1025
- scale = scale * 100.0 / (np.sum(self.pQF[:, 0:qf['numberOfEdges']], axis=1) + 1)
1026
- else:
1027
- scale = scale * 100.0 / (np.sum(self.pQF[:, 0:qf['numberOfEdges']], axis=1) + 1)
1028
- unit = ' [atom %]'
1029
- if qf['plotmode'] == 1: # output in number of electrons
1030
- scale = scale * qf['norm']
1031
- unit = ' [# e-]'
1032
-
1033
- if qf['plotmode'] == 2: # output in areal density
1034
- multp = 1e10 # xsec is in barns = 10^28 m2 = 10^10 nm2
1035
- scale = scale * qf['norm'] * multp ## check this
1036
- unit = ' [# atoms/nm2]'
1037
-
1038
- if si['Pcheck']:
1039
- if qf['plotmode'] == 1: # output in number of electrons
1040
- scaleP = scaleP * qf['norm']
1041
- unit = ' [# e-]'
1042
-
1043
- if qf['plotmode'] == 2: # output in areal density
1044
- multp = 1e10 # xsec is in barns = 10^28 m2 = 10^10 nm2
1045
- scaleP = scaleP * qf['norm'] * multp ## check this
1046
- unit = ' [# atoms/nm2]'
1047
-
1048
- res['unit'] = unit
1049
- res['scale'] = scale
1050
- res['scaleP'] = scaleP
1051
-
1052
- bins = np.linspace(0, dimen * xscale, dimen) # *height/len(data)
1053
-
1054
- # Here OUTPUT BEGINS
1055
-
1056
- plot = self.parent.plotParamWindow3
1057
- # plot.figure.clear()
1058
- col = self.parent.tags['QF']['Colors']
1059
- lin = self.parent.tags['QF']['LineWidth']
1060
-
1061
- numOutImages = 0
1062
-
1063
- if si['Qcheck'] > 0:
1064
- numOutImages = 1
1065
- '''
1066
- if si['Pcheck']:
1067
- plot.axes = plot.figure.add_subplot(numOutImages+3,1,numOutImages+1)
1068
- else:
1069
- plot.axes = plot.figure.add_subplot(1,1,1)
1070
- '''
1071
- res['QF-legend'] = {}
1072
- self.parent.text2.insertPlainText('\n Edge \t Median (' + unit + ') \t median abs dev \t std dev')
1073
- p1 = plot.addPlot(title=' Chemical Composition')
1074
- for i in range(int(qf['numberOfEdges'])):
1075
- titleStr = qf['edgeXtags'][str(i)]['element']
1076
- titleStr += '-'
1077
- titleStr += qf['edgeXtags'][str(i)]['subshell']
1078
- res['QF-legend'][str(i)] = titleStr
1079
- # plot.axes.plot(bins, res['QF'][:,i]*scale ,color=col[str(numOutImages)],linewidth = lin[str(numOutImages)], label =titleStr)
1080
- # curve = pg.PlotCurveItem(bins, res['QF'][:,i]*scale, stepMode=False, fillLevel=0, pen = ( col[str(i)]), brush=(col[str(foreMem)]), padding = 0)
1081
-
1082
- curve1 = pg.PlotCurveItem(bins, res['QF'][:, i] * scale, stepMode=False, padding=0, name=titleStr)
1083
- curve1.setPen(pg.mkPen(col[str(i)], width=lin[str(i)]))
1084
- # plot.addItem(curve1)
1085
- self.parent.text2.insertPlainText('\n {0:s} \t {1:3.3f} eV \t {2:3.3f} \t {3:3.3f}'
1086
- .format(titleStr, np.median(res['QF'][:, i] * scale), np.median(
1087
- abs(res['QF'][:, i] * scale - np.median(res['QF'][:, i] * scale)) / 0.6745),
1088
- float(np.std(res['QF'][:, i] * scale))))
1089
-
1090
- p1.plot(bins, res['QF'][:, i] * scale, pen=(col[str(i)]))
1091
- # p1.setPen(pg.mkPen(col[str(i)], width=lin[str(i)]))
1092
- numOutImages += 1
1093
- # plot.show()
1094
- print(i)
1095
- if self.parent.show:
1096
- p1.addLegend()
1097
- '''if si['showZ'] >0:
1098
- ## create a new ViewBox, link the right axis to its coordinate system
1099
- p2 = pg.ViewBox()
1100
- plot.showAxis('right')
1101
- plot.scene().addItem(p2)
1102
- plot.getAxis('right').linkToView(p2)
1103
- p2.setXLink(plot)
1104
- plot.getAxis('right').setLabel('Z-contrast', color='#0000ff')
1105
- p2.addItem((curve1))
1106
- '''
1107
- p1.setLabel('bottom', "distance", units='nm') # si['Xunit'])
1108
- p1.setLabel('left', "chemical compositon", units=res['unit'])
1109
- plot.nextRow()
1110
- if si['Pcheck']:
1111
-
1112
- self.parent.text2.insertPlainText('\n Peak \t parameter \t Median \t median abs dev \t std dev')
1113
-
1114
- p1 = plot.addPlot(title=' Peak Position')
1115
- plot.nextRow()
1116
- p2 = plot.addPlot(title=' Peak Area ')
1117
- plot.nextRow()
1118
- p3 = plot.addPlot(title=' Peak Width')
1119
-
1120
- plot.nextRow()
1121
- # plot.axes1 = plot.figure.add_subplot(numOutImages+3,1,numOutImages+1)
1122
- # plot.axes2 = plot.figure.add_subplot(numOutImages+3,1,numOutImages+2)
1123
- # plot.axes3 = plot.figure.add_subplot(numOutImages+3,1,numOutImages+3)
1124
- for i in range(int(gtags['numGauss'])):
1125
- titleStr = ' Peak ' + str(i + 1)
1126
- p1.plot(bins, res['GFp' + str(eNum)][:, i], pen=col[str(i)], linewidth=lin[str(numOutImages)],
1127
- name=titleStr)
1128
- p2.plot(bins, res['GFa' + str(eNum)][:, i] * scaleP, pen=col[str(i)], linewidth=lin[str(numOutImages)],
1129
- name=titleStr)
1130
- p3.plot(bins, res['GFw' + str(eNum)][:, i], pen=col[str(i)], linewidth=lin[str(numOutImages)],
1131
- name=titleStr)
1132
-
1133
- self.parent.text2.insertPlainText('\n {0:2d} \t position \t {1:3.3f} eV \t {2:3.3f} \t {3:3.3f}'
1134
- .format(i, np.median(res['GFp' + str(eNum)][:, i]), np.median(
1135
- abs(res['GFp' + str(eNum)][:, i] - np.median(res['GFp' + str(eNum)][:, i])) / 0.6745),
1136
- float(np.std(res['GFp' + str(eNum)][:, i]))))
1137
- self.parent.text2.insertPlainText('\n \t width \t {1:3.3f} eV \t {2:3.3f} \t {3:3.3f}'
1138
- .format(i, np.median(res['GFw' + str(eNum)][:, i]), np.median(
1139
- abs(res['GFw' + str(eNum)][:, i] - np.median(res['GFw' + str(eNum)][:, i])) / 0.6745),
1140
- float(np.std(res['GFw' + str(eNum)][:, i]))))
1141
- self.parent.text2.insertPlainText('\n \t area \t {1:3.3f} \t {2:3.3f} \t {3:3.3f}'
1142
- .format(unit, np.median(res['GFa' + str(eNum)][:, i]) * scaleP,
1143
- np.median(abs(res['GFa' + str(eNum)][:, i] - np.median(
1144
- res['GFa' + str(eNum)][:, i])) / 0.6745) * scaleP,
1145
- float(np.std(res['GFa' + str(eNum)][:, i])) * scaleP))
1146
-
1147
- numOutImages += 1
1148
-
1149
- print(si['Xunit'])
1150
- p3.setLabel('bottom', "distance", units='nm') # si['Xunit'])
1151
- p1.setLabel('left', "position", units='eV')
1152
- p2.setLabel('left', "area", units=unit)
1153
- p3.setLabel('left', "width", units='eV')
1154
-
1155
- if self.parent.show:
1156
- p1.addLegend()
1157
- p2.addLegend()
1158
- p3.addLegend()
1159
-
1160
- if self.showZ > 0:
1161
- p1 = plot.addPlot(title='Image')
1162
- plot.nextRow()
1163
- numOutImages = 0
1164
- if si['Xsum']:
1165
- data = np.sum(si['Zcontrast'], axis=0)
1166
- else:
1167
- data = np.sum(si['Zcontrast'], axis=1)
1168
- data = data - data.min()
1169
- sc = 100.0 / np.max(data)
1170
- bins = np.linspace(0, dimen * xscale, len(data)) # *height/len(data)
1171
- p1.plot(bins, data * sc, pen=col[str(numOutImages)], linewidth=lin[str(numOutImages)], name='Z contrast')
1172
-
1173
- if self.debug > 0:
1174
- print(len(data), len(bins), data.shape, sc)
1175
- if si['showSum'] > 0:
1176
- numOutImages += 1
1177
- ssum = np.sum(si['data'], axis=2)
1178
- if si['Xsum']:
1179
- data = np.sum(ssum, axis=0)
1180
- else:
1181
- data = np.sum(ssum, axis=1)
1182
- data = data - data.min()
1183
- sc = 100.0 / np.max(data)
1184
- p1.plot(bins, data * sc, pen=col[str(numOutImages)], linewidth=lin[str(numOutImages)],
1185
- name='Spectrum Sum')
1186
-
1187
- p1.setLabel('left', 'Contrast', units='%')
1188
- if self.parent.show:
1189
- p1.addLegend()
1190
-
1191
- self.parent.text2.ensureCursorVisible()
1192
- # plot.draw()
1193
-
1194
- if 'Sout' not in self.parent.tags:
1195
- self.parent.tags['Sout'] = False
1196
-
1197
- if self.parent.tags['Sout']:
1198
- import csv
1199
- with open(qf['filename'] + '-LS.csv', 'w', newline='') as csvfile:
1200
- xlwriter = csv.writer(csvfile, dialect='excel', delimiter=',', )
1201
- xlwriter.writerow(['File Name', qf['filename']])
1202
-
1203
- xlwriter.writerow(['X-Scale', xscale])
1204
- xlwriter.writerow(['Y-units', res['unit']])
1205
- xlwriter.writerow(['Y-scale', res['scale']])
1206
- xlwriter.writerow(['Y-scaleP', res['scaleP']])
1207
-
1208
- #########################
1209
- # Write titles
1210
- #########################
1211
-
1212
- columns = 0
1213
- title = []
1214
- title.append('distance [' + si['Xunit'] + ']')
1215
-
1216
- if si['Qcheck'] > 0:
1217
-
1218
- for i in range(int(qf['numberOfEdges'])):
1219
- columns += 1
1220
- title.append(res['QF-legend'][str(i)])
1221
- columns += 1
1222
- title.append('SUM')
1223
- for i in range(int(qf['numberOfEdges'])):
1224
- columns += 1
1225
- title.append(res['QF-legend'][str(i)] + '[atom%]')
1226
- if si['Efix']:
1227
- column += 1
1228
- title.append('Eshift')
1229
- if si['LLcheck']:
1230
- column += 1
1231
- title.append('ZL width')
1232
- if si['Pcheck']:
1233
- for i in range(int(gtags['numGauss'])):
1234
- column += 1
1235
- title.append('Peak ' + str(i + 1) + ' Position Edge' + str(eNum))
1236
- column += 1
1237
- title.append('Peak ' + str(i + 1) + ' Area Edge' + str(eNum))
1238
- column += 1
1239
- title.append('Peak ' + str(i + 1) + ' Width Edge' + str(eNum))
1240
-
1241
- xlwriter.writerow(title)
1242
- #########################
1243
- # Write Values
1244
- #########################
1245
-
1246
- for l in range(dimen):
1247
- value = []
1248
-
1249
- value.append('=' + str(l) + '*$B$2')
1250
- if si['Qcheck'] > 0:
1251
- numE = int(qf['numberOfEdges'])
1252
- sumE = 0
1253
- for i in range(numE):
1254
- value.append('=' + str(res['QF'][l, i]) + '*$B$4')
1255
- sumE += res['QF'][l, i]
1256
- value.append('=' + str(sumE) + '*$B$4')
1257
- for i in range(numE):
1258
- value.append('=' + str(res['QF'][l, i] / sumE * 100.0))
1259
-
1260
- if si['Pcheck']:
1261
- for i in range(int(gtags['numGauss'])):
1262
- value.append('=' + str(res['GFp' + str(eNum)][l, i]))
1263
- value.append('=' + str(res['GFa' + str(eNum)][l, i]) + '*$B$5')
1264
- value.append('=' + str(res['GFw' + str(eNum)][l, i]))
1265
-
1266
- xlwriter.writerow(value)
1267
-
1268
- def doAllClick(self):
1269
-
1270
- ## Define dictionaries and important dimensions
1271
-
1272
- foreMem = self.parent.tags['QF']['Fore']
1273
- qf = self.parent.tags['QF'][str(foreMem)].tags
1274
- qfspec = self.parent.tags['QF'][str(foreMem)]
1275
-
1276
- multSpec = qf['norm']
1277
- multS = qf['multS']
1278
- multFac = multSpec * multS
1279
-
1280
- si = self.parent.tags['QF']['SI']
1281
- if 'SI' not in qf['Results']:
1282
- qf['Results']['SI'] = {}
1283
- height = si['data'].shape[1]
1284
- width = si['data'].shape[0]
1285
-
1286
- spec = qf['spec']
1287
-
1288
- # we do LS data first and define resolution dictionary as such
1289
- if 'LS' not in qf['Results']:
1290
- qf['Results']['LS'] = {}
1291
- res = qf['Results']['LS']
1292
-
1293
- eNum = qf['whichEdge']
1294
- if eNum == 6:
1295
- gtags = qf['GF']['LL']
1296
- if eNum == 7:
1297
- gtags = qf['GF']['EG']
1298
- else:
1299
- gtags = qf['GF'][str(eNum)]
1300
- self.LLGauss = 0
1301
-
1302
- if si['Xsum'] + si['Ysum'] > 0:
1303
- ##########################################
1304
- ####### 1 D Data Analysis ################
1305
- ##########################################
1306
- if (si['Xsum'] + si['Ysum']) > 1:
1307
- qf['name'] = 'SI Sum'
1308
- qf['spec'] = np.array(np.sum(cts, axis=0))
1309
- return
1310
- xscale = float(si['Xscale'])
1311
-
1312
- # dimension of Output arrays or matrices
1313
-
1314
- if si['Xsum'] > 0:
1315
- data = np.sum(si['data'], axis=0)
1316
- dimen = height
1317
- res['X'] = 1
1318
- res['Y'] = 0
1319
- if si['Ysum'] > 0:
1320
- data = np.sum(si['data'], axis=1)
1321
- dimen = width
1322
- res['X'] = 0
1323
- res['Y'] = 1
1324
-
1325
- if si['Efix']:
1326
- self.pELL = np.zeros((dimen, 2))
1327
- if si['LLcheck'] > 0:
1328
- self.pZL = np.zeros((dimen, 9))
1329
-
1330
- if si['Qcheck'] > 0:
1331
- self.pQF = np.zeros((dimen, 13))
1332
-
1333
- if si['Pcheck']:
1334
- p = self.parent.gFitDialog.GaussFit(qf['spec'], qf['spec'], qf['pGF'])
1335
-
1336
- s = len(p)
1337
- self.pGF = np.zeros((dimen, s))
1338
- self.pGFp = np.zeros((dimen, s))
1339
- self.pGFa = np.zeros((dimen, s))
1340
- self.pGFw = np.zeros((dimen, s))
1341
-
1342
- # --------------------------------------------------
1343
- # Main loop over data
1344
- # --------------------------------------------------
1345
- for i in range(dimen):
1346
-
1347
- qf['spec'] = data[i, :].copy()
1348
-
1349
- if si['Efix']:
1350
- pG = self.parent.spec[foreMem].fixE(qf['spec'])
1351
- self.pELL[i, j, :] = pG
1352
- qf['ene'] = qf['ene'] - pG[1]
1353
- print('Efix ', qf['ene'][0])
1354
-
1355
- if si['LLcheck']:
1356
- # self.parent.LLDialog.OnResolutionClick()
1357
- # print(qf['pZL'])
1358
- tmfp = self.parent.spec[foreMem].doSSD(qf['spec'])
1359
- # self.parent.LLDialog.OnSSDClick()
1360
- self.pZL[i, 0] = tmfp
1361
- self.pZL[i, 1] = qf['ZL FWHM']
1362
- self.pZL[i, 2] = qf['ZL Max']
1363
- self.pZL[i, 3] = qf['Drude P Pos']
1364
- self.pZL[i, 4] = qf['Drude P Width']
1365
- self.pZL[i, 5] = qf['Drude P thick']
1366
- self.pZL[i, 6] = qf['Drude P Assym']
1367
- self.pZL[i, 7] = qf['Drude P Probab'] * 100.0
1368
- self.pZL[i, 8] = qf['Drude P IMFP']
1369
-
1370
- if si['Qcheck']:
1371
- self.pQF[i, :] = np.array(self.parent.spec[foreMem].FitModel(0))[0:13]
1372
-
1373
- if si['Pcheck']:
1374
- self.pGF[i, :] = p[0:s]
1375
- p = self.parent.gFitDialog.GaussFit(qf['spec'], qf['spec'], qf['pGF'])
1376
- if self.debug > 0:
1377
- print('Spec ', i, ': ', p[0], p[1], p[2])
1378
- # self.parent.gFitDialog.GaussFitClick()
1379
- self.pGF[i, :] = p[0:s] # qf['pGF']
1380
- for j in range(int(gtags['numGauss'])):
1381
- self.pGFp[i, j] = p[3 * j]
1382
- self.pGFa[i, j] = p[3 * j + 1]
1383
- self.pGFw[i, j] = p[3 * j + 2]
1384
-
1385
- # print(self.pQF[i,:])
1386
-
1387
- #########################################################
1388
- ## Save output to Result Dictionary
1389
- #########################################################
1390
- res['Length'] = dimen
1391
- res['xscale'] = xscale
1392
- if si['Efix']:
1393
- res['Efix'] = self.pELL
1394
-
1395
- if si['LLcheck']:
1396
- res['LL'] = self.pZL
1397
-
1398
- if si['Pcheck']:
1399
- res['GFp' + str(eNum)] = self.pGFp
1400
- res['GFa' + str(eNum)] = self.pGFa * multFac / 10000.0
1401
- res['GFw' + str(eNum)] = self.pGFw
1402
-
1403
- if si['Qcheck']:
1404
- res['QF'] = self.pQF
1405
-
1406
- # if si['LLcheck'] == 0:
1407
- # self.pZL = np.zeros((dimen,9))
1408
-
1409
- # reset to original state
1410
-
1411
- qf['spec'] = spec
1412
- self.setSlider()
1413
- self.plotSI()
1414
- return
1415
-
1416
- ############################################
1417
- ## 2D SI Evaluation
1418
- #############################################
1419
-
1420
- numOutImages = 0
1421
- if 'SI' not in qf['Results']:
1422
- qf['Results']['SI'] = {}
1423
-
1424
- res = qf['Results']['SI']
1425
- if self.showSum:
1426
- numOutImages += 1 # sum of spectra
1427
-
1428
- if self.showZ:
1429
- numOutImages += 1
1430
- if self.showBF:
1431
- numOutImages += 1
1432
-
1433
- oimages = numOutImages
1434
-
1435
- if si['Efix']:
1436
- self.pELL = np.zeros((width, height, 2))
1437
- # numOutImages = oimages+ 2
1438
- numOutImages += 2
1439
-
1440
- pos = np.zeros((width, height))
1441
-
1442
- if si['LLcheck'] > 0:
1443
- self.pZL = np.zeros((width, height, 9))
1444
- pos = np.zeros((width, height))
1445
-
1446
- numOutImages += 9
1447
- if si['Qcheck'] > 0:
1448
- self.pQF = np.zeros((width, height, 13))
1449
- pos = np.zeros((width, height))
1450
- # numOutImages = oimages+int(qf['numberOfEdges'])
1451
- numOutImages += int(qf['numberOfEdges'])
1452
- if si['Pcheck']:
1453
- nGauss = gtags['numGauss']
1454
- p = self.parent.gFitDialog.GaussFit(qf['spec'], qf['spec'], qf['pGF'])
1455
-
1456
- s = len(p)
1457
- self.pGF = np.zeros((width, height, s))
1458
- # numOutImages = int(gtags['numGauss'])*3 #but we take position only now
1459
- numOutImages += int(nGauss * 3) # we could also use other values like times xsec.
1460
-
1461
- p = np.zeros(s)
1462
- ritesh = 0
1463
-
1464
- si['numOutImages'] = numOutImages
1465
-
1466
- step = si['binning']
1467
- stepI = step
1468
- if si['Sliding Aver'] > 0:
1469
- stepI = 1
1470
- ene = qf['ene']
1471
-
1472
- for j in range(0, height, stepI):
1473
- print('spectrum image line: ', j)
1474
- if self.debug > 0:
1475
- self.parent.status.showMessage(" row: " + str(j))
1476
- # print('row ',j)
1477
- for i in range(0, width, stepI):
1478
-
1479
- if ritesh:
1480
- if i + j == 0:
1481
- i = i + 1
1482
- print('Omitting first spectrum, do second twice')
1483
-
1484
- qf['spec'] = np.zeros(len(qf['spec']))
1485
- for k in range(step):
1486
- for l in range(step):
1487
- if i + l < si['data'].shape[0]:
1488
- if j + k < si['data'].shape[1]:
1489
- qf['spec'] = qf['spec'] + si['data'][i + l, j + k, :]
1490
-
1491
- if si['Efix']:
1492
- qf['ene'] = ene.copy()
1493
- qf['offset'] = ene[0]
1494
- pG = qfspec.fixE(qf['spec'])
1495
- self.pELL[i, j, :] = pG
1496
- qf['ene'] = ene - pG[1]
1497
- # print(qf['ene'][0],ene[0], pG)
1498
-
1499
- if si['LLcheck']:
1500
- # self.parent.LLDialog.OnResolutionClick()
1501
- # print(qf['pZL'])
1502
-
1503
- tmfp = qfspec.doSSD(qf['spec'])
1504
- # tmfp = self.parent.LLDialog.OnSSDClick()
1505
-
1506
- self.pZL[i, j, 0] = tmfp
1507
- self.pZL[i, j, 1] = qf['ZL FWHM']
1508
- self.pZL[i, j, 2] = qf['ZL Max']
1509
- self.pZL[i, j, 3] = qf['Drude P Pos']
1510
- self.pZL[i, j, 4] = qf['Drude P Width']
1511
- self.pZL[i, j, 5] = qf['Drude P thick']
1512
- # print(i,j,qf['Drude P thick'])
1513
- self.pZL[i, j, 6] = qf['Drude P Assym']
1514
- self.pZL[i, j, 7] = qf['Drude P Probab'] * 100.0
1515
- self.pZL[i, j, 8] = qf['Drude P IMFP']
1516
-
1517
- if si['Qcheck']:
1518
- # print (i,j)
1519
- self.pQF[i, j, :] = np.array(qfspec.FitModel(0))[0:13]
1520
-
1521
- if self.debug > 0:
1522
- print(self.pQF[i, j, :])
1523
-
1524
- if si['Pcheck']:
1525
-
1526
- self.pGF[i, j, :] = p
1527
-
1528
- p = self.parent.gFitDialog.GaussFit(qf['spec'], qf['spec'], qf['pGF'])
1529
- nGauss = gtags['numGauss']
1530
- for i in range(int(nGauss)):
1531
- p[i * 3 + 1] = p[i * 3 + 1] * multFac
1532
-
1533
- if self.debug > 0:
1534
- print(j, i, qf['ene'][0], p[0], p[1], p[2])
1535
-
1536
- # self.parent.gFitDialog.GaussFitClick()
1537
- self.pGF[i, j, :] = p # qf['pGF']
1538
-
1539
- # reset to original state
1540
-
1541
- qf['spec'] = spec
1542
- self.setSlider()
1543
-
1544
- ##########################
1545
- # Store results
1546
- ##########################
1547
-
1548
- ##########################
1549
- # Output to SI window
1550
- ##########################
1551
-
1552
- # Estimate Grid Layout
1553
- grid_y = int(np.sqrt(height * width * numOutImages) / height + 0.5)
1554
- if grid_y > 4:
1555
- grid_y = 4
1556
-
1557
- grid_x = math.ceil(numOutImages / grid_y)
1558
- if grid_x > 4:
1559
- grid_x = 4
1560
-
1561
- if si['Pcheck']:
1562
- nGauss = gtags['numGauss']
1563
- grid_x = int(3)
1564
- grid_y = int(nGauss)
1565
- if grid_y > 4:
1566
- grid_y = 4
1567
-
1568
- if self.debug > 0:
1569
- print(numOutImages, grid_x, grid_y)
1570
-
1571
- im = np.zeros((width, height, numOutImages))
1572
- title = []
1573
-
1574
- showZa = 0
1575
- showBFa = 0
1576
- showSa = 0
1577
-
1578
- #########################################################
1579
- ## Save output to Result Dictionary
1580
- #########################################################
1581
-
1582
- if si['Efix']:
1583
- res['Efix'] = self.pELL
1584
-
1585
- if si['LLcheck']:
1586
- res['LL'] = self.pZL
1587
-
1588
- if si['Pcheck']:
1589
- res['GF' + str(eNum)] = self.pGF
1590
-
1591
- if si['Qcheck']:
1592
- res['GF'] = self.pQF
1593
-
1594
- index = 0
1595
- ## using median and median absolute deviation as a robust statistical measure instead of mean and standard deviation
1596
- ## These robust statistic is necessary for our noisy data with outlayers
1597
- ## median absolute deviation is scaled for consistency to standard deviation
1598
- if si['Pcheck']:
1599
- self.parent.text2.insertPlainText(
1600
- '\n Peak \t parameter \t Median value \t median absolute deviation \t Standard deviation')
1601
- nGauss = gtags['numGauss']
1602
- for i in range(int(nGauss)):
1603
- im[:, :, i * 3] = self.pGF[:, :, i * 3]
1604
- title.append('Peak ' + str(i + 1) + ' position')
1605
- self.parent.text2.insertPlainText('\n {0:2d} \t position \t {1:3.3f} eV \t {2:3.3f} \t {3:3.3f}'
1606
- .format(i + 1, np.median(im[:, :, i * 3]),
1607
- np.median(abs(
1608
- im[:, :, i * 3] - np.median(im[:, :, i * 3])) / 0.6745),
1609
- float(np.std(im[:, :,
1610
- i * 3])))) # 0.6745 consistence scale factor to standard deviation
1611
- self.pGF[:, :, i * 3 + 1] = abs(self.pGF[:, :, i * 3 + 1])
1612
- im[:, :, i * 3 + 1] = np.array(self.pGF[:, :, i * 3 + 1])
1613
- title.append('Peak ' + str(i + 1) + ' area')
1614
- self.parent.text2.insertPlainText('\n \t area \t {1:3.3f} eV \t {2:3.3f} \t {3:3.3f}'
1615
- .format(i, np.median(im[:, :, i * 3 + 1]), np.median(
1616
- abs(im[:, :, i * 3 + 1] - np.median(im[:, :, i * 3 + 1])) / 0.6745),
1617
- float(np.std(im[:, :, i * 3 + 1]))))
1618
- self.pGF[:, :, i * 3 + 2] = abs(self.pGF[:, :, i * 3 + 2])
1619
- im[:, :, i * 3 + 2] = np.array(self.pGF[:, :, i * 3 + 2])
1620
- title.append('Peak ' + str(i + 1) + ' width')
1621
- self.parent.text2.insertPlainText('\n \t width \t {1:3.3f} eV \t {2:3.3f} \t {3:3.3f}'
1622
- .format(i, np.median(im[:, :, i * 3 + 2]), np.median(
1623
- abs(im[:, :, i * 3 + 2] - np.median(im[:, :, i * 3 + 2])) / 0.6745),
1624
- float(np.std(im[:, :, i * 3 + 2]))))
1625
-
1626
- index = nGauss * 3
1627
- print(index, numOutImages)
1628
- if self.showSum:
1629
- showSa = 1
1630
- im[:, :, index] = np.sum(si['data'], axis=2)
1631
- title.append('sum')
1632
- index += 1
1633
- if self.showZ:
1634
- showZa = 1
1635
- im[:, :, index] = si['Zcontrast']
1636
- title.append('Z contrast')
1637
- index += 1
1638
- if self.showBF:
1639
- showBFa = 1
1640
- im[:, :, index] = si['BrightField']
1641
- title.append('bright field')
1642
- index += 1
1643
- if si['Qcheck']:
1644
- scale = np.ones((width, height))
1645
- if qf['plotmode'] == 0: # output in atom %
1646
- if self.debug > 0:
1647
- print('shape', self.pQF.shape)
1648
- print('sum pqf')
1649
- print(np.sum(self.pQF[:, :, 0:qf['numberOfEdges']], axis=2))
1650
- print('pqf')
1651
- print((self.pQF[:, :, 0:qf['numberOfEdges']]))
1652
- scale = 100.0 / (np.sum(self.pQF[:, :, 0:qf['numberOfEdges']], axis=2) + 0.00001)
1653
- unit = ' [atom %]'
1654
- if qf['plotmode'] == 1: # output in number of electrons
1655
- scale = scale * qf['norm']
1656
- unit = ' [# e-]'
1657
-
1658
- if qf['plotmode'] == 2: # output in areal density
1659
- multp = 1e10 # xsec is in barns = 10^28 m2 = 10^10 nm2
1660
- scale = scale * qf['norm'] * multp ## check this
1661
- unit = ' [# atoms/nm2]'
1662
- self.parent.text2.insertPlainText('\n')
1663
- self.parent.text2.insertPlainText(
1664
- '\n Edge \t Median value (' + unit + ') \t median absolute deviation \t Standard deviation')
1665
- for i in range(int(qf['numberOfEdges'])):
1666
- im[:, :, index] = self.pQF[:, :, i] * scale
1667
- # title.append('Edge '+str(i-oimages+1)) # Look up element - check scale
1668
- # print('Mean value of ZL Position: ',np.mean(im[:,:,1]),' with standard deviation: ',np.std(im[:,:,1]))
1669
- index += 1
1670
- titleStr = qf['edgeXtags'][str(i)]['element']
1671
- titleStr += '-'
1672
- titleStr += qf['edgeXtags'][str(i)]['subshell']
1673
- self.parent.text2.insertPlainText('\n' + titleStr + '\t {0:3.3f} \t {1:3.3f} \t {2:3.3f}'
1674
- .format(np.median(im[:, :, i]),
1675
- np.median(abs(im[:, :, i] - np.median(im[:, :, i])) / 0.6745),
1676
- float(np.std(im[:, :, i]))))
1677
-
1678
- titleStr += unit
1679
- title.append(titleStr)
1680
-
1681
- if si['LLcheck']:
1682
- titelsLL = ['rel. thick', 'ZL FWHM', 'ZL Max', 'Drude P Pos', 'Drude P Width', 'Drude P thick',
1683
- 'Drude P Assym', 'Drude P Probab', 'Drude P IMFP']
1684
- for i in range(9):
1685
- im[:, :, index] = self.pZL[:, :, i]
1686
- title.append(titelsLL[i])
1687
- self.parent.text2.insertPlainText('\n' + 'Mean value of' + titelsLL[i] + ': ' + str(
1688
- +np.mean(im[:, :, index])) + ' with standard deviation: ' + str(np.std(im[:, :, index])))
1689
- index += 1
1690
-
1691
- if si['Efix']:
1692
- im[:, :, index] = self.pELL[:, :, 1]
1693
- title.append('ZL Gauss position')
1694
- index += 1
1695
- im[:, :, index] = self.pELL[:, :, 0]
1696
- title.append('ZL Gauss width')
1697
- index += 1
1698
- # print('defined si', index)
1699
-
1700
- if 'Sliding Aver' not in si:
1701
- si['Sliding Aver'] = 0
1702
- if si['Sliding Aver'] == 0:
1703
- for ind in range(im.shape[2]):
1704
- for j in range(0, height, stepI):
1705
- for i in range(0, width, stepI):
1706
- for k in range(step):
1707
- for l in range(step):
1708
- if i + l < si['data'].shape[0]:
1709
- if j + k < si['data'].shape[1]:
1710
- im[i + l, j + k, ind] = im[i, j, ind]
1711
- Imdefined = index
1712
- if 'images' not in si:
1713
- si['images'] = {}
1714
- if 'outimage' in si['images']:
1715
- del si['images']['outimage']
1716
- # si['images'] = {}
1717
- si['images']['gridx'] = grid_x
1718
- si['images']['gridy'] = grid_y
1719
-
1720
- si['images']['xscale'] = float(si['Xscale'])
1721
- si['images']['pixel_size'] = float(si['Xscale'])
1722
- si['images']['width'] = width * si['images']['xscale']
1723
- si['numOutImages'] = numOutImages
1724
- index = 0
1725
- grid = np.zeros((4, 4))
1726
- si['images']['grid'] = grid
1727
-
1728
- if 'image_list' not in si['images']:
1729
- si['images']['image_list'] = []
1730
-
1731
- for index in range(numOutImages):
1732
- si['images'][title[index]] = {}
1733
-
1734
- if title[index] not in si['images']['image_list']:
1735
- si['images']['image_list'].append(title[index])
1736
-
1737
- imI = si['images'][title[index]]
1738
- imI['image'] = im[:, :, index]
1739
- # imI['name'] = title[index]
1740
- print(index, title[index])
1741
- imI['min'] = imI['image'].min()
1742
- imI['max'] = imI['image'].max()
1743
- imI['Z min'] = imI['image'].min()
1744
- imI['Z max'] = imI['image'].max()
1745
- xscale = float(si['Xscale'])
1746
- imI['xlim'] = (0, width * xscale)
1747
- imI['ylim'] = (height * xscale, 0)
1748
-
1749
- imI['extend'] = (0, width * xscale, height * xscale, 0)
1750
- imI['xlabel'] = 'Distance [' + si['Xunit'] + ']'
1751
-
1752
- print(si['images']['image_list'])
1753
- for index in range(numOutImages):
1754
- si['images'][str(index)] = {}
1755
- imI = si['images'][str(index)]
1756
-
1757
- imI['image'] = im[:, :, index]
1758
- imI['name'] = title[index]
1759
- imI['min'] = imI['image'].min()
1760
- imI['max'] = imI['image'].max()
1761
- # imI['Z min'] = imI['image'].min()
1762
- # imI['Z max'] = imI['image'].max()
1763
- xscale = float(si['Xscale'])
1764
- imI['xlim'] = (0, width * xscale)
1765
- imI['ylim'] = (height * xscale, 0)
1766
-
1767
- imI['extend'] = (0, width * xscale, height * xscale, 0)
1768
- imI['xlabel'] = 'Distance [' + si['Xunit'] + ']'
1769
-
1770
- index = 0
1771
- # print(grid_x,grid_y)
1772
-
1773
- for j in range(grid_y):
1774
- for i in range(grid_x):
1775
-
1776
- si['images']['grid'][j][i] = index + 1
1777
-
1778
- index += 1
1779
- if index == numOutImages:
1780
- break
1781
-
1782
- if index == numOutImages:
1783
- break
1784
-
1785
- if 'Sout' not in self.parent.tags:
1786
- self.parent.tags['Sout'] = False
1787
-
1788
- if self.parent.tags['Sout']:
1789
- import csv
1790
- with open(qf['filename'] + '-IM.csv', 'w', newline='') as csvfile:
1791
- xlwriter = csv.writer(csvfile, dialect='excel', delimiter=',', )
1792
- xlwriter.writerow(['File Name', qf['filename']])
1793
- xlwriter.writerow(['X-Scale', xscale])
1794
- xlwriter.writerow(['Y-units', res['unit']])
1795
- xlwriter.writerow(['Y-scale', res['scale']])
1796
- xlwriter.writerow(['Y-scaleP', res['scaleP']])
1797
-
1798
- for i in range(Imdefined):
1799
- imI = si['images'][str(i)]
1800
- xlwriter.writerow(imI['title'])
1801
- im = imI['image']
1802
- for j in im.shape[1]:
1803
- xlwriter.writerow(im[j, :])
1804
-
1805
- self.plotSIimages()
1806
- if len(self.parent.SIImageDialog.process) > 1:
1807
- self.parent.SIImageDialog.process = ['None']
1808
-
1809
- def plotSIimages(self):
1810
- ## Define dictionaries and important dimensions
1811
-
1812
- foreMem = self.parent.tags['QF']['Fore']
1813
- qf = self.parent.tags['QF'][str(foreMem)]
1814
- si = self.parent.tags['QF']['SI']
1815
-
1816
- # if self.parent.tab.tabText(2) == 'SI LS':
1817
-
1818
- self.parent.tab.removeTab(2)
1819
- self.parent.plotParamWindow3 = MySICanvas(self.parent.centralWidget, width=10, height=10, dpi=70)
1820
- plotLayout3 = QVBoxLayout()
1821
- plot3 = QWidget()
1822
- plotLayout3.addWidget(self.parent.plotParamWindow3)
1823
- plot3.setLayout(plotLayout3)
1824
-
1825
- self.parent.tab.setCurrentIndex(2)
1826
- self.parent.tab.insertTab(2, plot3, 'SI')
1827
-
1828
- plot = self.parent.plotParamWindow3
1829
-
1830
- plot.figure.clear()
1831
-
1832
- plot.figure.set_tight_layout(True)
1833
- axes = []
1834
- myImage = []
1835
-
1836
- self.parent.tab.setCurrentIndex(2)
1837
-
1838
- if 'images' not in si:
1839
- return
1840
- # si['images'].clear()
1841
- if 'outimage' in si['images']:
1842
- del si['images']['outimage']
1843
- grid_x = si['images']['gridx']
1844
- grid_y = si['images']['gridy']
1845
- numOutImages = si['numOutImages']
1846
- si['images']['imageList'] = []
1847
- # print(si['images']['imageList'])
1848
- if 'whichGrid' not in si['images']:
1849
- si['images']['whichGrid'] = [0, 0]
1850
-
1851
- index = 0
1852
- if 'grid' not in si['images']:
1853
- grid = np.zeros((4, 4))
1854
- index = 0
1855
- for i in range(4):
1856
- for j in range(4):
1857
- if j < grid_x:
1858
- if i < grid_y:
1859
- grid[i, j] = int(index + 1)
1860
- index += 1
1861
- if index == numOutImages:
1862
- break
1863
- if index == numOutImages:
1864
- break
1865
- si['images']['grid'] = grid
1866
- if 'whichGrid' not in si['images']:
1867
- si['images']['whichGrid'] = [0, 0]
1868
- import matplotlib.gridspec as gridspec
1869
- gs = gridspec.GridSpec(grid_y, grid_x) # columns, rows, )
1870
- index = 0
1871
- print('print grid\n', si['images']['grid'])
1872
- for i in range(grid_x):
1873
- for j in range(grid_y):
1874
- Imageindex = int(si['images']['grid'][j, i])
1875
- if Imageindex > 0:
1876
- Imageindex -= 1
1877
-
1878
- imI = si['images'][str(Imageindex)]
1879
- axes.append(plot.figure.add_subplot(gs[j, i]))
1880
- myImage.append(axes[index].imshow(np.transpose(imI['image']), origin='upper'))
1881
- # print(myImage[index], axes[index],index)
1882
-
1883
- """///*
1884
- # create an axes on the right side of ax. The width of cax will be 5%
1885
- # of ax and the padding between cax and ax will be fixed at 0.05 inch.
1886
- = mpl.pyplot.gca(plot.figure.add_subplot(gs[j,i]))
1887
- divider = make_axes_locatable(ax)
1888
- cax = divider.append_axes("right", size="5%", pad=0.05)
1889
-
1890
- cbar = plot.figure.colorbar(myImage[index], ax=axes[index], cax=cax)
1891
- """
1892
- # cbar = plot.figure.colorbar(myImage[index], ax=axes[index], orientation='vertical', shrink=.5, pad=.0, aspect=10)
1893
- axes[index].set_title(imI['name'])
1894
- myImage[index].set_extent(imI['extend'])
1895
-
1896
- # cbar = plot.figure.colorbar(myImage[index], ax=axes[index], orientation='vertical', shrink=.5, pad=.0, aspect=10)
1897
- if 'Z min' in imI:
1898
- norm = mpl.colors.Normalize(vmin=imI['Z min'], vmax=imI['Z max'])
1899
- myImage[index].set_norm(norm)
1900
-
1901
- cbar = plot.figure.colorbar(myImage[index], ax=axes[index], orientation='vertical', shrink=.5, pad=.05,
1902
- aspect=10)
1903
-
1904
- axes[index].set_xlim(imI['xlim'])
1905
- axes[index].set_ylim(imI['ylim'])
1906
- index += 1
1907
- if index == numOutImages:
1908
- break
1909
-
1910
- if index == numOutImages:
1911
- break
1912
-
1913
- for i in range(grid_x):
1914
- ind = len(axes) - grid_x + i
1915
- axes[ind].set_xlabel('Distance [' + si['Xunit'] + ']')
1916
- print(ind)
1917
- maxI = 0
1918
- for key in si['images']:
1919
- try:
1920
- if si['images'][key]['name'] not in si['images']['imageList']:
1921
- maxI += 1
1922
- except:
1923
- pass
1924
- for i in range(maxI - 1):
1925
- si['images']['imageList'].append(si['images'][str(i)]['name'])
1926
-
1927
- plot.draw()
1928
- plot.show()
1929
- self.parent.SIImageWidget.setVisible(True)
1930
- # self.parent.SIImageDialog.update()
1931
-
1932
- def onclick(self, event):
1933
- print('button=%d, x=%d, y=%d, xdata=%f, ydata=%f' % (
1934
- event.button, event.x, event.y, event.xdata, event.ydata))
1935
-
1936
- def onMouseReleaseClick(self, event):
1937
- print('onMouseReleaseClick')
1938
- if event.inaxes:
1939
- if event.button == 3:
1940
-
1941
- nix = 1
1942
- if int(event.xdata) == self.xsel:
1943
- nix = 0
1944
- if int(event.ydata) == self.ysel:
1945
- nix = 0
1946
- for i in range(self.xsel, int(event.xdata)):
1947
- for j in range(self.ysel, int(event.ydata)):
1948
- self.select[j, i] = 1
1949
- self.parent.text2.insertPlainText(
1950
- '\n Selected spectra from : (' + str(self.ysel + 1) + ',' + str(self.xsel + 1) + ') ')
1951
- self.parent.text2.insertPlainText(
1952
- ' to (' + str(int(event.ydata + 1)) + ',' + str(int(event.xdata + 1)) + ') \n')
1953
- else:
1954
- self.parent.text2.insertPlainText(
1955
- '\n Selected spectrum : (' + str(self.ysel + 1) + ',' + str(self.xsel + 1) + ') ')
1956
-
1957
- # print 'moved'
1958
- self.setSlider()
1959
-
1960
- def onMouseButtonClick(self, event):
1961
- print('onMouseButtonClick')
1962
-
1963
- if event is None:
1964
- return
1965
- x, y = event.xdata, event.ydata
1966
-
1967
- foreMem = self.parent.tags['QF']['Fore']
1968
- qf = self.parent.tags['QF'][str(foreMem)]
1969
- si = self.parent.tags['QF']['SI']
1970
-
1971
- if event.inaxes:
1972
- # print event.button
1973
-
1974
- if event.button == 1:
1975
- si['Xpos'] = int(x + 0.5)
1976
- si['Ypos'] = int(y + 0.5)
1977
-
1978
- s = 'Click, x: ' + str(si['Xpos']) + ', y: ' + str(si['Ypos'])
1979
- print(s)
1980
-
1981
- self.setSlider()
1982
-
1983
- return
1984
-
1985
- if event.button == 3:
1986
- s = 'Right Click '
1987
- if event.key == 'shift':
1988
- print('shift')
1989
- '''
1990
- self.xsel = int(x)
1991
- self.ysel = int(y)
1992
- #print int(event.xdata),int(event.ydata)
1993
- if self.select[int(x),int(y)] == 0:
1994
- self.select[int(x),int(y)] = 1
1995
- else:
1996
- self.select[int(event.ydata),int(event.xdata)] = 0
1997
- #print self.select[int(event.ydata),int(event.xdata)]
1998
- '''
1999
-
2000
- else:
2001
- if event.button == 3:
2002
- si['select'] = []
2003
- si['rectangles'] = {}
2004
- self.rect = 0
2005
- # del(self.select)
2006
- # self.select = np.zeros((height, width),'uint8')
2007
-
2008
- def XcheckClick(self, event):
2009
- if self.parent.tags['QF']['SI']['Xsum']:
2010
- self.parent.tags['QF']['SI']['Xsum'] = False
2011
- else:
2012
- self.parent.tags['QF']['SI']['Xsum'] = True
2013
-
2014
- self.setSlider()
2015
-
2016
- def YcheckClick(self, event):
2017
- if self.parent.tags['QF']['SI']['Ysum']:
2018
- self.parent.tags['QF']['SI']['Ysum'] = False
2019
- else:
2020
- self.parent.tags['QF']['SI']['Ysum'] = True
2021
- self.setSlider()
2022
-
2023
- def selectSumClick(self, event):
2024
- if self.Scheck.isChecked():
2025
- self.parent.tags['QF']['SI']['Ssum'] = 1
2026
- else:
2027
- self.parent.tags['QF']['SI']['Ssum'] = 0
2028
- self.setSlider()
2029
-
2030
- '''
2031
- def OnMotion(self,event):
2032
- s= "Mouse Motion"#t: (%.4f, %.4f)" % self.GetXY(event)
2033
- print(s)
2034
- #print event
2035
- event.Skip()
2036
- '''
2037
-
2038
- def sliderUpdate(self):
2039
-
2040
- si = self.parent.tags['QF']['SI']
2041
- if self.debug > 0:
2042
- print('slider Update')
2043
- xold = si['Xpos']
2044
- yold = si['Ypos']
2045
- if xold < 1:
2046
- xold = 1
2047
- if yold < 1:
2048
- yold = 1
2049
-
2050
- si['Ypos'] = int(self.slider2.value() + .2)
2051
- if si['Ypos'] < 1:
2052
- si['Ypos'] = 1
2053
-
2054
- si['Xpos'] = int(self.slider1.value() + .2)
2055
- if si['Xpos'] < 1:
2056
- si['Xpos'] = 1
2057
-
2058
- # str1 = "pos1 = %d pos2 = %d" % (si['Xpos'], si['Ypos'])
2059
- #
2060
- # display current slider positions in the self.parent's title
2061
- #
2062
- # print (str1)
2063
- if si['Xpos'] != xold or si['Ypos'] != yold:
2064
- if self.debug > 0:
2065
- print('set slider update')
2066
- self.setSlider()
2067
-
2068
-
2069
-
2070
-
2071
-
2072
-