Commit 9cf53972 authored by payno's avatar payno

[orange-add on] integrate the XasObjectViewer in the pymca orange add-on

parent d5e8f28c
Pipeline #12331 passed with stage
in 5 minutes and 39 seconds
......@@ -29,40 +29,104 @@ __date__ = "06/07/2019"
from silx.gui import qt
from silx.gui.plot import Plot1D, LegendSelector
from silx.gui.plot import LegendSelector
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from xas.core.types import XASObject
from PyMca5.PyMcaGui.physics.xas.XASPostEdgeParameters import XASPostEdgeParameters
from Orange.widgets.settings import Setting
from xas.core.types import XASObject, Spectrum
import xas.core.process.exafs
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
from PyMca5.PyMcaGui.physics.xas.XASPostEdgeParameters import XASPostEdgeParameters
import logging
_logger = logging.getLogger(__file__)
def _exafs_signal_plot(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.get_missing_keys(('EXAFSKValues', 'EXAFSSignal'))
if missing_keys:
_logger.error('missing keys:', missing_keys, 'unable to compute exafs signal plot')
return
k = spectrum["EXAFSKValues"]
if "KMin" not in spectrum:
spectrum["KMin"] = k.min()
if "KMax" not in spectrum:
spectrum["KMax"] = k.max()
idx = (spectrum["EXAFSKValues"] >= spectrum["KMin"]) & \
(spectrum["EXAFSKValues"] <= spectrum["KMax"])
x = spectrum["EXAFSKValues"][idx]
y = spectrum["EXAFSSignal"][idx]
return _CurveOperation(x=x, y=y, legend="EXAFSSignal")
def _exafs_postedge_plot(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.get_missing_keys(('EXAFSKValues', 'PostEdgeB'))
if missing_keys:
_logger.error('missing keys:', missing_keys, 'unable to compute exafs postedge plot')
return
k = spectrum["EXAFSKValues"]
if "KMin" not in spectrum:
spectrum["KMin"] = k.min()
if "KMax" not in spectrum:
spectrum["KMax"] = k.max()
idx = (spectrum["EXAFSKValues"] >= spectrum["KMin"]) & \
(spectrum["EXAFSKValues"] <= spectrum["KMax"])
x = spectrum["EXAFSKValues"][idx]
y = spectrum["PostEdgeB"][idx]
return _CurveOperation(x=x, y=y, legend="PostEdge")
def _exafs_knots_plot(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.get_missing_keys(('KnotsX', 'KnotsY'))
if missing_keys:
_logger.error('missing keys:', missing_keys, 'unable to compute exafs knot plot')
return
x = spectrum["KnotsX"]
y = spectrum["KnotsY"]
return _CurveOperation(x=x, y=y, legend="Knots", linestyle="", symbol="o")
class ExafsWindow(qt.QMainWindow):
def __init__(self, parent=None):
qt.QMainWindow.__init__(self, parent)
self.plot = Plot1D()
self.setCentralWidget(self.plot)
self.xasObjViewer = XasObjectViewer()
self.xasObjViewer._spectrumView._plot.getXAxis().setLabel("K")
self.xasObjViewer._spectrumView._plot.getYAxis().setLabel("Normalized Units")
self.setCentralWidget(self.xasObjViewer)
# pymca window
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
# legend selector
self.legendDockWidget = LegendSelector.LegendsDockWidget(parent=self,
plot=self.plot)
plot=self.xasObjViewer._spectrumView._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)
# plot settings
for ope in (_exafs_signal_plot, _exafs_postedge_plot, _exafs_knots_plot,):
self.xasObjViewer._spectrumView.addCurveOperation(ope)
def getNCurves(self):
return len(self.plot.getAllCurves())
return len(self.xasObjViewer.getAllCurves())
def _updateLegendView(self):
self.legendDockWidget.setVisible(self.xasObjViewer.getViewType() is ViewType.spectrum)
class ExafsOW(OWWidget):
......@@ -95,8 +159,8 @@ class ExafsOW(OWWidget):
layout.addWidget(self._window)
self._latest_xas_obj = None
self._window.plot.getXAxis().setLabel("K")
self._window.plot.getYAxis().setLabel("Normalized Units")
self._window.xasObjViewer._spectrumView._plot.getXAxis().setLabel("K")
self._window.xasObjViewer._spectrumView._plot.getYAxis().setLabel("Normalized Units")
# manage settings
if self._pymcaSettings != dict():
......@@ -119,40 +183,10 @@ class ExafsOW(OWWidget):
process_obj = ExafsOW.process_function()
process_obj.setProperties({'_pymcaSettings': self._window._pymcaWindow.getParameters()})
xas_obj = process_obj.process(xas_obj)
self._updatePlot(xas_obj.spectra)
self._window.xasObjViewer.setXASObj(xas_obj)
# emit signal for the plot
self.send("spectra", xas_obj)
def _updatePlot(self, ddict):
plot = self._window.plot
plot.clear()
k = ddict["EXAFSKValues"]
if "KMin" not in ddict:
ddict["KMin"] = k.min()
if "KMax" not in ddict:
ddict["KMax"] = k.max()
idx = (ddict["EXAFSKValues"] >= ddict["KMin"]) & \
(ddict["EXAFSKValues"] <= ddict["KMax"])
plot.addCurve(x=ddict["EXAFSKValues"][idx],
y=ddict["EXAFSSignal"][idx],
legend="EXAFSSignal",
resetzoom=False)
plot.addCurve(ddict["EXAFSKValues"][idx],
ddict["PostEdgeB"][idx],
legend="PostEdge",
resetzoom=False)
plot.addCurve(ddict["KnotsX"],
ddict["KnotsY"],
legend="Knots",
linestyle="",
symbol="o",
resetzoom=True)
def _update_settings(self):
self._pymcaSettings = self._window._pymcaWindow.getParameters()
......@@ -29,41 +29,77 @@ __date__ = "06/07/2019"
from silx.gui import qt
from silx.gui.plot import Plot1D, LegendSelector
from silx.gui.plot import LegendSelector
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.widgets.settings import Setting
from xas.core.types import XASObject
from xas.core.types import XASObject, Spectrum
import xas.core.process.ft
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
from PyMca5.PyMcaGui.physics.xas.XASFourierTransformParameters import XASFourierTransformParameters
import logging
_logger = logging.getLogger(__file__)
def _ft_intensity_plot(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.ft.get_missing_keys(('FTRadius', 'FTIntensity'))
if missing_keys:
_logger.error('missing keys:', missing_keys, 'unable to compute spectrum plot')
return
return _CurveOperation(x=spectrum.ft['FTRadius'],
y=spectrum.ft['FTIntensity'],
legend="FT Intensity")
def _ft_imaginary_plot(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.ft.get_missing_keys(('FTRadius', 'FTImaginary'))
if missing_keys:
_logger.error('missing keys:', missing_keys, 'unable to compute spectrum plot')
return
return _CurveOperation(x=spectrum.ft['FTRadius'],
y=spectrum.ft['FTImaginary'],
legend="FT Imaginary",
color="red")
class FTWindow(qt.QMainWindow):
def __init__(self, parent=None):
qt.QMainWindow.__init__(self, parent)
self.plot = Plot1D()
self.setCentralWidget(self.plot)
# xas object viewer
self.xasObjViewer = XasObjectViewer()
self.xasObjViewer._spectrumView._plot.getXAxis().setLabel("R (Angstrom)")
self.xasObjViewer._spectrumView._plot.getYAxis().setLabel("Arbitrary Units")
self.setCentralWidget(self.xasObjViewer)
self._pymcaWindow = XASFourierTransformParameters(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)
self.setWindowFlags(qt.Qt.Widget)
# legend
# legend selector
self.legendDockWidget = LegendSelector.LegendsDockWidget(parent=self,
plot=self.plot)
plot=self.xasObjViewer._spectrumView._plot)
self.legendDockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
self.legendDockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget)
# plot settings
for ope in (_ft_intensity_plot, _ft_imaginary_plot):
self.xasObjViewer._spectrumView.addCurveOperation(ope)
def getNCurves(self):
return len(self.plot.getAllCurves())
def _updateLegendView(self):
self.legendDockWidget.setVisible(self.xasObjViewer.getViewType() is ViewType.spectrum)
class FTOW(OWWidget):
"""
......@@ -95,9 +131,6 @@ class FTOW(OWWidget):
layout = gui.vBox(self.mainArea, 'fourier transform').layout()
layout.addWidget(self._window)
self._window.plot.getXAxis().setLabel("R (Angstrom)")
self._window.plot.getYAxis().setLabel("Arbitrary Units")
# manage settings
if self._pymcaSettings != dict():
self._window._pymcaWindow.setParameters(self._pymcaSettings)
......@@ -119,22 +152,10 @@ class FTOW(OWWidget):
process_obj.setProperties({'_pymcaSettings': self._window._pymcaWindow.getParameters()})
xas_obj = process_obj.process(xas_obj)
self._updatePlot(ddict=xas_obj.spectrum['FT'])
self._window.xasObjViewer.setXASObj(xas_obj)
# emit signal for the plot
self.send("spectra", xas_obj)
def _updatePlot(self, ddict):
self._window.plot.clear()
self._window.plot.addCurve(x=ddict["FTRadius"],
y=ddict["FTIntensity"],
legend="FT Intensity",)
self._window.plot.addCurve(x=ddict["FTRadius"],
y=ddict["FTImaginary"],
legend="FT Imaginary",
color="red")
self._window.plot.resetZoom()
def _update_settings(self):
self._pymcaSettings = self._window._pymcaWindow.getParameters()
......@@ -28,44 +28,93 @@ __license__ = "MIT"
__date__ = "06/07/2019"
from silx.gui.plot import Plot1D, LegendSelector
from silx.gui.plot import LegendSelector
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.widgets.settings import Setting
from silx.gui import qt
from xas.core.types import XASObject
from xas.core.types import XASObject, Spectrum
import xas.core.process.k_weight
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation
import logging
_logger = logging.getLogger(__file__)
def _normalized_exafs(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.get_missing_keys(('EXAFSKValues', 'EXAFSNormalized'))
if missing_keys:
_logger.error('missing keys:', missing_keys,
'unable to compute normalized EXAFS')
return None
if spectrum["KWeight"]:
if spectrum["KWeight"] == 1:
ylabel = "EXAFS Signal * k"
else:
ylabel = "EXAFS Signal * k^%d" % spectrum["KWeight"]
else:
ylabel = "EXAFS Signal"
idx = (spectrum["EXAFSKValues"] >= spectrum["KMin"]) & \
(spectrum["EXAFSKValues"] <= spectrum["KMax"])
return _CurveOperation(x=spectrum["EXAFSKValues"][idx],
y=spectrum["EXAFSNormalized"][idx],
legend="Normalized EXAFS",
ylabel=ylabel)
def _ft_window_plot(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.ft.get_missing_keys(('K', 'WindowWeight'))
if missing_keys:
_logger.error('missing keys:', missing_keys,
'unable to compute normalized EXAFS')
return None
return _CurveOperation(x=spectrum.ft['K'],
y=spectrum.ft["WindowWeight"],
legend="FT Window",
yaxis="right",
color="red")
class KWeightWindow(qt.QMainWindow):
def __init__(self, parent=None):
qt.QMainWindow.__init__(self, parent)
self.plot = Plot1D()
self.setCentralWidget(self.plot)
# xas object viewer
self.xasObjViewer = XasObjectViewer()
self.xasObjViewer._spectrumView._plot.getXAxis().setLabel("K")
self.setCentralWidget(self.xasObjViewer)
# k wright widget
self._k_widget = qt.QWidget(parent=self)
self._k_widget.setLayout(qt.QHBoxLayout())
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)
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
# legend selector
self.legendDockWidget = LegendSelector.LegendsDockWidget(parent=self,
plot=self.plot)
plot=self.xasObjViewer._spectrumView._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)
# plot settings
for ope in (_normalized_exafs, _ft_window_plot):
self.xasObjViewer._spectrumView.addCurveOperation(ope)
def getNCurves(self):
return len(self.plot.getAllCurves())
......@@ -100,8 +149,6 @@ class KWeightOW(OWWidget):
layout.addWidget(self._window)
self._latest_xas_obj = None
self._window.plot.getXAxis().setLabel("K")
# manage settings
if self._kWeightSetting != 3:
self._window._k_spin_box.setValue(self._kWeightSetting)
......@@ -122,40 +169,10 @@ class KWeightOW(OWWidget):
process_obj = KWeightOW.process_function()
process_obj.setProperties({'_kWeightSetting': self._window._k_spin_box.value()})
xas_obj = process_obj.process(xas_obj)
self._updatePlot(xas_obj.spectrum)
self._window.xasObjViewer.setXASObj(xas_obj)
# emit signal for the plot
self.send("spectra", xas_obj)
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"
self._window.plot.getYAxis().setLabel(ylabel)
idx = (ddict["EXAFSKValues"] >= ddict["KMin"]) & \
(ddict["EXAFSKValues"] <= ddict["KMax"])
plot.addCurve(x=ddict["EXAFSKValues"][idx],
y=ddict["EXAFSNormalized"][idx],
legend="Normalized EXAFS",
ylabel=ylabel,
replace=True)
plot.addCurve(x=ddict["FT"]["K"],
y=ddict["FT"]["WindowWeight"],
legend="FT Window",
yaxis="right",
color="red",
replace=False)
plot.resetZoom()
def _update_settings(self):
self._kWeightSetting = self._window._k_spin_box.value()
......@@ -29,24 +29,86 @@ __date__ = "06/07/2019"
from silx.gui import qt
from silx.gui.plot import Plot1D, LegendSelector
from silx.gui.plot import LegendSelector
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.widgets.settings import Setting
from PyMca5.PyMcaGui.physics.xas.XASNormalizationParameters import XASNormalizationParameters
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
from xas.core.types import XASObject
from xas.core.types import XASObject, Spectrum
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
import xas.core.process.normalization
import logging
_logger = logging.getLogger(__file__)
def _spectrum_plot(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.get_missing_keys(('Edge',))
if missing_keys:
_logger.error('missing keys:', missing_keys, 'unable to compute spectrum plot')
return
e0 = spectrum['Edge']
x = spectrum.energy - e0
y = spectrum.mu
return _CurveOperation(x=x, y=y, legend='Spectrum', yaxis=None)
def _normalized_spectrum_plot(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.get_missing_keys(('Edge', 'NormalizedEnergy',
'NormalizedPlotMin', 'NormalizedPlotMax',
'NormalizedMu'))
if missing_keys:
_logger.error('missing keys:', missing_keys, 'unable to compute normalized spectrum plot')
return None
idx = (spectrum["NormalizedEnergy"] >= spectrum["NormalizedPlotMin"]) & \
(spectrum["NormalizedEnergy"] <= spectrum["NormalizedPlotMax"])
e0 = spectrum['Edge']
x = spectrum["NormalizedEnergy"][idx] - e0
y = spectrum["NormalizedMu"][idx]
return _CurveOperation(x=x, y=y, legend='Normalized', yaxis='right')
def _post_plot(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.get_missing_keys(('Edge', 'NormalizedEnergy',
'NormalizedSignal'))
if missing_keys:
_logger.error('missing keys:', missing_keys, 'unable to compute post plot')
return None
e0 = spectrum['Edge']
x = spectrum['NormalizedEnergy'] - e0
y = spectrum["NormalizedSignal"]
return _CurveOperation(x=x, y=y, legend='Post', yaxis=None)
def _pre_plot(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.get_missing_keys(('Edge', 'NormalizedEnergy',
'NormalizedBackground'))
if missing_keys:
_logger.error('missing keys:', missing_keys, 'unable to compute pre plot')
return None
e0 = spectrum['Edge']
x = spectrum['NormalizedEnergy'] - e0
y = spectrum["NormalizedBackground"]
return _CurveOperation(x=x, y=y, legend='Pre', yaxis=None)
class NormalizationWindow(qt.QMainWindow):
def __init__(self, parent=None):
qt.QMainWindow.__init__(self, parent)
self.plot = Plot1D()
self.setCentralWidget(self.plot)
# xas object viewer
self.xasObjViewer = XasObjectViewer()
self.xasObjViewer._spectrumView._plot.getXAxis().setLabel("Energy (eV)")
self.xasObjViewer._spectrumView._plot.getYAxis().setLabel("Absorption (a.u.)")
self.setCentralWidget(self.xasObjViewer)
self._pymcaWindow = XASNormalizationParameters(parent=self)
dockWidget = qt.QDockWidget(parent=self)
......@@ -56,17 +118,25 @@ class NormalizationWindow(qt.QMainWindow):
dockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
dockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
# legend
# legend selector
self.legendDockWidget = LegendSelector.LegendsDockWidget(parent=self,
plot=self.plot)
plot=self.xasObjViewer._spectrumView._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)
# plot settings
for ope in (_spectrum_plot, _normalized_spectrum_plot, _post_plot,
_pre_plot):
self.xasObjViewer._spectrumView.addCurveOperation(ope)
def getNCurves(self):
return len(self.plot.getAllCurves())
return len(self.xasObjViewer._spectrumView._plot.getAllCurves())
def _updateLegendView(self):
self.legendDockWidget.setVisible(self.xasObjViewer.getViewType() is ViewType.spectrum)
class NormalizationOW(OWWidget):
......@@ -99,9 +169,7 @@ class NormalizationOW(OWWidget):
self._window = NormalizationWindow(parent=self)
layout = gui.vBox(self.mainArea, 'fourier transform').layout()
layout.addWidget(self._window)
self._window.plot.setWindowTitle('spectra')
self._window.plot.getXAxis().setLabel("Energy (eV)")
self._window.plot.getYAxis().setLabel("Absorption (a.u.)")
self._window.xasObjViewer.setWindowTitle('spectra')
self.pymca_xas = XASClass()
......@@ -120,11 +188,13 @@ class NormalizationOW(OWWidget):
if xas_obj is None:
return
# TODO: move process to multiprocessing + add advancement progress
self._latest_xas_obj = xas_obj.copy()
process_class = NormalizationOW.process_function()
process_class.setProperties({'_pymcaSettings': self._window._pymcaWindow.getParameters()})
xas_obj = process_class(xas_obj)
self._updatePlot(xas_obj.spectrum)
self._window.xasObjViewer.setXASObj(xas_obj=xas_obj)
# emit signal for the plot
self.send("spectra", xas_obj)
......@@ -133,37 +203,5 @@ class NormalizationOW(OWWidget):
if self._latest_xas_obj:
self.process(self._latest_xas_obj)
def _updatePlot(self, ddict):
self._window.plot.clear()
if ddict is None:
return
assert isinstance(ddict, dict)
idx = (ddict["NormalizedEnergy"] >= ddict["NormalizedPlotMin"]) & \
(ddict["NormalizedEnergy"] <= ddict["NormalizedPlotMax"])
# first clear connected plot
# then create all the requested curve
e0 = ddict["Edge"]
self._window.plot.addCurve(x=ddict["Energy"] - e0,
y=ddict["Mu"],
legend="Spectrum")
self._window.plot.addCurve(x=ddict["NormalizedEnergy"][idx] - e0,
y=ddict["NormalizedMu"][idx],
legend="Normalized",
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)
self._window.plot.resetZoom()
def _update_settings(self):
self._pymcaSettings = self._window._pymcaWindow.getParameters()
......@@ -88,6 +88,8 @@ class XASObject(object):
assert dim1_idx < self.dim1
assert dim2_idx < self.dim2
global_idx = dim1_idx * self.dim2 + dim2_idx
assert global_idx < len(self.spectra)
assert global_idx >= 0
return self.spectra[global_idx]
def addSpectrum(self, spectrum):
......@@ -221,6 +223,7 @@ class XASObject(object):
class Spectra(object):
pass
class Spectrum(object):
_MU_KEY = 'Mu'
......@@ -387,6 +390,17 @@ class Spectrum(object):
for key, value in obj.items():
self[key] = value
def get_missing_keys(self, keys):
"""Return missing keys on the spectrum"""
missing = []
for key in keys:
if key not in self:
missing.append(key)
if len(missing) is 0:
return None
else:
return missing
class _FT(object):
......@@ -460,3 +474,15 @@ class _FT(object):
}
res.update(self.__other_parameters)
return res
def get_missing_keys(self, keys):
"""Return missing keys on the spectrum"""
missing = []
for key in keys:
if key not in self:
missing.append(key)
if len(missing) is 0:
return None
else:
return missing
......@@ -39,6 +39,7 @@ from silx.utils.enum import Enum
from silx.gui.widgets.FrameBrowser import HorizontalSliderWithBrowser
from silx.gui import icons as silx_icons
from silx.gui.colors import Colormap
from collections import namedtuple
class ViewType(Enum):
......@@ -140,13 +141,30 @@ class _ExtendedSliderWithBrowser(HorizontalSliderWithBrowser):
self.layout().insertWidget(0, qt.QLabel(str(name + ':')))
class _CurveOperation(object):
def __init__(self, x, y, legend, yaxis=None, linestyle=None, symbol=None,
color=None, ylabel=None):
self.x = x
self.y = y
self.legend = legend
self.yaxis = yaxis
self.linestyle = linestyle
self.symbol = symbol
self.color = color
self.ylabel = ylabel
class SpectrumViewer(qt.QMainWindow):
def __init__(self, parent=None):
self._curveOperations = []
"""List of callaback to produce plot regarding the XASObject.
Callback function should return a _curve_operation"""
qt.QMainWindow.__init__(self, parent)
self.xas_obj = None
self._plot = Plot1D(parent=self)
self.setCentralWidget(self._plot)
# frame browsers
dockWidget = qt.QDockWidget(parent=