-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyImageGui.py
146 lines (112 loc) · 5.67 KB
/
pyImageGui.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
# ################################################################
# 1######## pyTEMgui Main program
# #
# # by Gerd Duscher
# # Started February 2025:
# # Also used as an example for pycrosGUI
# #
# BaseWIdget with
# InfoWidget which changes with imae or spectrum file.
# Image, CoreLoss, and PeakFit dialogs work on spectra and spectral images
#
#################################################################
from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import PyQt5
import os as os
import numpy as np
import scipy as scipy
import pyqtgraph as pg
# =============================================================
# Include Quantifit Libraries #
# =============================================================
# global frame
import sidpy
from BaseWidget import BaseWidget
from InfoDialog import InfoDialog
from ImageDialog import ImageDialog
# =======================================================================================================
# Main Window Module #
# =======================================================================================================
class MainWidget(BaseWidget):
def __init__(self, filename=None):
super().__init__(filename=filename)
# add dialogs with additional capabilities
self.InfoWidget = PyQt5.QtWidgets.QDockWidget("Info ", self)
self.InfoDialog = InfoDialog(self)
self.InfoWidget.setFeatures(PyQt5.QtWidgets.QDockWidget.DockWidgetMovable |
PyQt5.QtWidgets.QDockWidget.DockWidgetFloatable)
self.InfoWidget.setWidget(self.InfoDialog)# Add the dock to the main window
self.addDockWidget (QtCore.Qt.LeftDockWidgetArea, self.InfoWidget)
self.tabifyDockWidget(self.DataWidget, self.InfoWidget)
self.InfoWidget.visibilityChanged.connect(self.InfoDialog.updateInfo)
self.ImageWidget = PyQt5.QtWidgets.QDockWidget("Image", self)
self.ImageDialog = ImageDialog(self)
self.ImageWidget.setFeatures(PyQt5.QtWidgets.QDockWidget.DockWidgetMovable |
PyQt5.QtWidgets.QDockWidget.DockWidgetFloatable)
self.ImageWidget.setWidget(self.ImageDialog)# Add the dock to the main window
self.tabifyDockWidget(self.InfoWidget, self.ImageWidget)
#self.tabifyDockWidget(self.ImageWidget, self.CoreLossWidget)
self.ImageWidget.visibilityChanged.connect(self.image_update)
self.DataWidget.raise_()
def updateRoiPlot(self):
self.get_image
global img, roi, data, p2
selected = roi.getArrayRegion(data, img)
p2.plot(selected.mean(axis=0), clear=True)
def plot_additional_features(self, plt):
"""
Adds additional features to the plot, as defined in the dialogs.
The current dialog is determined by the metadata of the dataset.
"""
super().plot_additional_features(plt)
additional_features = {}
if 'plot' not in self.dataset.metadata:
return
if 'additional_features' in self.dataset.metadata['plot']:
if 'Image' in self.dataset.metadata['plot']['additional_features']:
additional_features = self.ImageDialog.get_additional_features()
elif 'CoreLoss' in self.dataset.metadata['plot']['additional_features']:
additional_features = self.CoreLossDialog.get_additional_features()
self.plot_features = additional_features
elif 'PeakFit' in self.dataset.metadata['plot']['additional_features']:
additional_features = self.PeakFitDialog.get_additional_features()
additional_spectra = {}
if 'additional_spectra' in self.dataset.metadata['plot']:
if 'LowLoss' in self.dataset.metadata['plot']['additional_spectra']:
additional_spectra = self.ImageDialog.get_additional_spectra()
elif 'CoreLoss' in self.dataset.metadata['plot']['additional_spectra']:
additional_spectra = self.CoreLossDialog.get_additional_spectra()
elif 'PeakFit' in self.dataset.metadata['plot']['additional_spectra']:
print('peak add')
additional_spectra = self.PeakFitDialog.get_additional_spectra()
ene = np.array(self.dataset.get_spectral_dims(return_axis=True)[0])
energy_scale = np.append(ene, ene[-1])
colors = ('red', 'green', 'orange', 'purple', 'cyan', 'magenta', 'grey', 'lightgrey', 'black','black')
for i, key in enumerate(additional_spectra.keys()):
spectrum = additional_spectra[key]*self.intensity_scale
curve = pg.PlotCurveItem(np.array(energy_scale), spectrum,
pen = colors[i%10], stepMode=True,
padding = 0, name=key) #, name=memtags['name'])
plt.addItem(curve)
curve.setPen(pg.mkPen(colors[i%10], width=2))
for key, item in additional_features.items():
plt.addItem(item)
def image_update(self, visible):
if visible:
self.ImageDialog.update_sidebar()
def main(args=[]):
global app
app = QtWidgets.QApplication(args)
f = MainWidget()
f.show()
app.setStyle(QtWidgets.QStyleFactory.create("Cleanlooks"))
app.setPalette(QtWidgets.QApplication.style().standardPalette())
app.exec()
if __name__ == "__main__":
# import sys
main() # sys.argv)