Commit fa381a2a authored by payno's avatar payno
Browse files

[add-on] add plot for processing

parent 5f22ed9a
......@@ -28,6 +28,8 @@ __license__ = "MIT"
__date__ = "06/07/2019"
from silx.gui import qt
from silx.gui.plot import Plot2D, LegendSelector
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from xas.core.types import xas_process_io
......@@ -37,6 +39,27 @@ import logging
_logger = logging.getLogger(__file__)
class ExafsWindow(qt.QMainWindow):
def __init__(self, parent=None):
qt.QMainWindow.__init__(self, parent)
self.plot = Plot2D()
self.setCentralWidget(self.plot)
self._pymcaWindow = XASPostEdgeParameters(parent=self)
dockWidget = qt.QDockWidget(parent=self)
dockWidget.setWidget(self._pymcaWindow)
self.addDockWidget(qt.Qt.RightDockWidgetArea, dockWidget)
dockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
dockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
self.setWindowFlags(qt.Qt.Widget)
# legend
self.legendDockWidget = LegendSelector.LegendsDockWidget(parent=self,
plot=self.plot)
self.legendDockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
self.legendDockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget)
class ExafsOW(OWWidget):
"""
Widget used for signal extraction
......@@ -59,10 +82,46 @@ class ExafsOW(OWWidget):
def __init__(self):
super().__init__()
self._pymcaWindow = XASPostEdgeParameters(parent=self)
self._window = ExafsWindow()
layout = gui.vBox(self.mainArea, 'fourier transform').layout()
layout.addWidget(self._pymcaWindow)
layout.addWidget(self._window)
def process(self, process_io):
if process_io is None:
return
res = ExafsOW.process_function(process_io.configuration)
self._updatePlot(res)
# emit signal for the plot
self.send("spectrum", xas_process_io(spectrum=process_io.spectrum,
configuration=res))
def _updatePlot(self, ddict):
plot = self._window.plot
idx = (ddict["EXAFSKValues"] >= ddict["KMin"]) & \
(ddict["EXAFSKValues"] <= ddict["KMax"])
plot.addCurve(x=ddict["EXAFSKValues"][idx],
y=ddict["EXAFSSignal"][idx],
legend="EXAFSSignal",
xlabel="K",
ylabel="Normalized Units",
replace=True,
resetzoom=False)
plot.addCurve(ddict["EXAFSKValues"][idx],
ddict["PostEdgeB"][idx],
legend="PostEdge",
xlabel="K",
ylabel="Normalized Units",
color="blue",
resetzoom=False)
def process(self, spectrum_config):
self.process_function(spectrum_config)
print('process', self.name)
plot.addCurve(ddict["KnotsX"],
ddict["KnotsY"],
legend="Knots",
linestyle="",
symbol="o",
color="orange",
resetzoom=True)
......@@ -28,6 +28,8 @@ __license__ = "MIT"
__date__ = "06/07/2019"
from silx.gui import qt
from silx.gui.plot import Plot2D, LegendSelector
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from xas.core.types import xas_process_io
......@@ -37,6 +39,27 @@ import logging
_logger = logging.getLogger(__file__)
class FTWindow(qt.QMainWindow):
def __init__(self, parent=None):
qt.QMainWindow.__init__(self, parent)
self.plot = Plot2D()
self.setCentralWidget(self.plot)
self._pymcaWindow = XASFourierTransformParameters(parent=self)
dockWidget = qt.QDockWidget(parent=self)
dockWidget.setWidget(self._pymcaWindow)
self.addDockWidget(qt.Qt.RightDockWidgetArea, dockWidget)
dockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
dockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
self.setWindowFlags(qt.Qt.Widget)
# legend
self.legendDockWidget = LegendSelector.LegendsDockWidget(parent=self,
plot=self.plot)
self.legendDockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
self.legendDockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget)
class FTOW(OWWidget):
"""
Widget used for signal extraction
......@@ -59,9 +82,32 @@ class FTOW(OWWidget):
def __init__(self):
super().__init__()
self._pymcaWindow = XASFourierTransformParameters(parent=self)
self._window = FTWindow(parent=self)
layout = gui.vBox(self.mainArea, 'fourier transform').layout()
layout.addWidget(self._pymcaWindow)
layout.addWidget(self._window)
def process(self, process_io):
if process_io is None:
return
ddict = FTOW.process_function(process_io.configuration)
# emit signal for the plot
self.send("spectrum", xas_process_io(spectrum=process_io.spectrum,
configuration=ddict))
def _updatePlot(self, ddict):
self._window.plot.addCurve(x=ddict["FT"]["FTRadius"],
y=ddict["FT"]["FTIntensity"],
legend="FT Intensity",
xlabel="R (Angstrom)",
ylabel="Arbitrary Units",
replace=True)
def process(self, spectrum):
print('process', self.name)
self._window.plot.addCurve(x=ddict["FT"]["FTRadius"],
y=ddict["FT"]["FTImaginary"],
legend="FT Imaginary",
xlabel="R (Angstrom)",
ylabel="Arbitrary Units",
color="red",
replace=False)
self._window.plot.resetZoom()
......@@ -28,6 +28,8 @@ __license__ = "MIT"
__date__ = "06/07/2019"
from silx.gui import qt
from silx.gui.plot import Plot2D, LegendSelector
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from silx.gui import qt
......@@ -37,6 +39,34 @@ import logging
_logger = logging.getLogger(__file__)
class KWeightWindow(qt.QMainWindow):
def __init__(self, parent=None):
qt.QMainWindow.__init__(self, parent)
self.plot = Plot2D()
self.setCentralWidget(self.plot)
self._k_widget = qt.QWidget(parent=self)
self._k_widget.setLayout(qt.QFormLayout())
self._k_widget.layout().addWidget(qt.QLabel('k weight'))
self._k_spin_box = qt.QSpinBox(parent=self)
self._k_spin_box.setRange(0, 3)
self._k_widget.layout().addWidget(self._k_spin_box)
self._k_widget.layout().addItem(qt.QSpacerItem(0, 0, qt.QSizePolicy.Minimum, qt.QSizePolicy.Expanding))
dockWidget = qt.QDockWidget(parent=self)
dockWidget.setWidget(self._k_widget)
self.addDockWidget(qt.Qt.RightDockWidgetArea, dockWidget)
dockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
dockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
self.setWindowFlags(qt.Qt.Widget)
# legend
self.legendDockWidget = LegendSelector.LegendsDockWidget(parent=self,
plot=self.plot)
self.legendDockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
self.legendDockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget)
class KWeightOW(OWWidget):
"""
Widget used for signal extraction
......@@ -59,14 +89,51 @@ class KWeightOW(OWWidget):
def __init__(self):
super().__init__()
self._k_widget = qt.QWidget(parent=self)
self._k_widget.setLayout(qt.QFormLayout())
self._k_widget.layout().addWidget(qt.QLabel('k weight'))
self._k_spin_box = qt.QSpinBox(parent=self)
self._k_spin_box.setRange(0, 3)
self._k_widget.layout().addWidget(self._k_spin_box)
layout = gui.vBox(self.mainArea, 'fourier transform').layout()
layout.addWidget(self._k_widget)
self._window = KWeightWindow(parent=self)
layout.addWidget(self._window)
def process(self, process_io):
if process_io is None:
return
res = KWeightOW.process_function(process_io.configuration)
self._updatePlot(res)
# emit signal for the plot
self.send("spectrum", xas_process_io(spectrum=process_io.spectrum,
configuration=res))
def _updatePlot(self, ddict):
if ddict is None:
return
plot = self._window.plot
if ddict["KWeight"]:
if ddict["KWeight"] == 1:
ylabel = "EXAFS Signal * k"
else:
ylabel = "EXAFS Signal * k^%d" % ddict["KWeight"]
else:
ylabel = "EXAFS Signal"
idx = (ddict["EXAFSKValues"] >= ddict["KMin"]) & \
(ddict["EXAFSKValues"] <= ddict["KMax"])
plot.addCurve(x=ddict["EXAFSKValues"][idx],
y=ddict["EXAFSNormalized"][idx],
legend="Normalized EXAFS",
xlabel="K",
ylabel=ylabel,
replace=True,
replot=False)
def process(self, spectrum_config):
self.pymca_k_weight(spectrum_config)
plot.addCurve(x=ddict["FT"]["K"],
y=ddict["FT"]["WindowWeight"],
legend="FT Window",
xlabel="K",
ylabel="Weight",
yaxis="right",
color="red",
replace=False,
replot=False)
plot.resetZoom()
......@@ -28,6 +28,8 @@ __license__ = "MIT"
__date__ = "06/07/2019"
from silx.gui import qt
from silx.gui.plot import Plot2D, LegendSelector
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from PyMca5.PyMcaGui.physics.xas.XASNormalizationParameters import XASNormalizationParameters
......@@ -38,6 +40,30 @@ import xas.core.process.normalization
_logger = logging.getLogger(__file__)
class NormalizationWindow(qt.QMainWindow):
def __init__(self, parent=None):
qt.QMainWindow.__init__(self, parent)
self.plot = Plot2D()
self.setCentralWidget(self.plot)
self._pymcaWindow = XASNormalizationParameters(parent=self)
dockWidget = qt.QDockWidget(parent=self)
# pymca window
dockWidget.setWidget(self._pymcaWindow)
self.addDockWidget(qt.Qt.RightDockWidgetArea, dockWidget)
dockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
dockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
# legend
self.legendDockWidget = LegendSelector.LegendsDockWidget(parent=self,
plot=self.plot)
self.legendDockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
self.legendDockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget)
self.setWindowFlags(qt.Qt.Widget)
class NormalizationOW(OWWidget):
"""
Widget used for signal extraction
......@@ -57,29 +83,31 @@ class NormalizationOW(OWWidget):
outputs = [("spectrum", xas_process_io), ("curves", tuple)]
process_function = xas.core.process.ft.pymca_ft
process_function = xas.core.process.normalization.pymca_normalization
def __init__(self):
super().__init__()
self._pymcaWindow = XASNormalizationParameters(parent=self)
self._window = NormalizationWindow(parent=self)
layout = gui.vBox(self.mainArea, 'fourier transform').layout()
layout.addWidget(self._pymcaWindow)
layout.addWidget(self._window)
self._window.plot.setWindowTitle('spectrum')
self.pymca_xas = XASClass()
def process(self, spec_configuration):
def process(self, process_io):
if process_io is None:
return
ddict = NormalizationOW.process_function(process_io.configuration)
self._updatePlot(ddict)
ddict = self.process_function(spec_configuration)
return
# should spectrum be a XASClass instead of a numpy array ?
self.pymca_xas.setSpectrum(energy=xas_obj.spectrum.energy, mu=xas_obj.spectrum.mu)
# emit signal for the other xas process
ddict = self.pymca_xas.normalize()
print(ddict)
# emit signal for the plot
self.send("spectrum", xas_process_io(spectrum=xas_obj.spectrum,
configuration=None))
self.send("spectrum", xas_process_io(spectrum=process_io.spectrum,
configuration=ddict))
def _updatePlot(self, ddict):
self._window.plot.clear()
if ddict is None:
return
idx = (ddict["NormalizedEnergy"] >= ddict["NormalizedPlotMin"]) & \
(ddict["NormalizedEnergy"] <= ddict["NormalizedPlotMax"])
......@@ -87,53 +115,26 @@ class NormalizationOW(OWWidget):
# then create all the requested curve
e0 = ddict["Edge"]
if 'Energy'not in ddict:
ddict['Energy'] = xas_obj.spectrum.energy
if 'Mu'not in ddict:
ddict['Mu'] = xas_obj.spectrum.mu
curves = []
# plot spectrum
plot1 = {
'clear': True,
'x': ddict["Energy"] - e0,
'y': ddict["Mu"],
'legend': "Spectrum",
'xlabel': "Energy (eV)",
'ylabel': "Absorption (a.u.)",
'plot_name': 'Spectrum',
}
curves.append(plot1)
# plot normalized energy vs NormalizedMu
plot2 = {
'clear': False,
'x': ddict["NormalizedEnergy"][idx] - e0,
'y': ddict["NormalizedMu"][idx],
'legend': "Normalized",
'xlabel': "Energy (eV)",
'ylabel': "Absorption (a.u.)",
'yaxis': "right",
}
curves.append(plot2)
# plot normalized energy vs NormalizedSignal
plot3 = {
'clear': False,
'x': ddict["NormalizedEnergy"] - e0,
'y': ddict["NormalizedSignal"],
'legend': "Post",
'resetzoom': False,
}
curves.append(plot3)
# plot normalized energy vs NormalizedBackground
plot4 = {
'clear': False,
'x': ddict["NormalizedEnergy"] - e0,
'y': ddict["NormalizedBackground"],
'legend': "Pre",
'resetzoom': False,
}
curves.append(plot4)
self.send("curves", curves)
# curve 1
self._window.plot.addCurve(x=ddict["Energy"] - e0,
y=ddict["Mu"],
legend="Spectrum",
xlabel="Energy (eV)",
ylabel="Absorption (a.u.)")
self._window.plot.addCurve(x=ddict["NormalizedEnergy"][idx] - e0,
y=ddict["NormalizedMu"][idx],
legend="Normalized",
xlabel="Energy (eV)",
ylabel="Absorption (a.u.)",
yaxis='right')
self._window.plot.addCurve(x=ddict["NormalizedEnergy"] - e0,
y=ddict["NormalizedSignal"],
legend="Post",
resetzoom=False)
self._window.plot.addCurve(x=ddict["NormalizedEnergy"] - e0,
y=ddict["NormalizedBackground"],
legend='Pre',
resetzoom=False)
......@@ -109,7 +109,7 @@ class ExafsOW(OWWidget):
def _getFileSelected(self, file_path):
return self._inputLe.text()
def process(self):
def process(self, process_io):
if not os.path.isfile(self._getFileSelected()):
qt.QMessageBox.warning(self,
'No output file defined, please give a file path')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment