Commit 89029fe6 authored by payno's avatar payno

[gui][XasObjViewer] add the possibility to display a specific map view from a key

parent 9cf53972
Pipeline #12338 passed with stage
in 4 minutes and 26 seconds
......@@ -95,7 +95,9 @@ def _exafs_knots_plot(spectrum):
class ExafsWindow(qt.QMainWindow):
def __init__(self, parent=None):
qt.QMainWindow.__init__(self, parent)
self.xasObjViewer = XasObjectViewer()
mapKeys = ['Mu', 'EXAFS/EXAFSKValues', 'EXAFS/EXAFSSignal',
'EXAFS/PostEdgeB']
self.xasObjViewer = XasObjectViewer(mapKeys=mapKeys)
self.xasObjViewer._spectrumView._plot.getXAxis().setLabel("K")
self.xasObjViewer._spectrumView._plot.getYAxis().setLabel("Normalized Units")
self.setCentralWidget(self.xasObjViewer)
......@@ -116,17 +118,28 @@ class ExafsWindow(qt.QMainWindow):
self.legendDockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget)
self.setWindowFlags(qt.Qt.Widget)
# volume key selection
self.addDockWidget(qt.Qt.RightDockWidgetArea,
self.xasObjViewer._mapView.keySelectionDocker)
# plot settings
for ope in (_exafs_signal_plot, _exafs_postedge_plot, _exafs_knots_plot,):
self.xasObjViewer._spectrumView.addCurveOperation(ope)
self.setWindowFlags(qt.Qt.Widget)
# connect signal / slot
self.xasObjViewer.viewTypeChanged.connect(self._updateLegendView)
# set up
self._updateLegendView()
def getNCurves(self):
return len(self.xasObjViewer.getAllCurves())
def _updateLegendView(self):
self.legendDockWidget.setVisible(self.xasObjViewer.getViewType() is ViewType.spectrum)
self.xasObjViewer._mapView.keySelectionDocker.setVisible(self.xasObjViewer.getViewType() is ViewType.map)
class ExafsOW(OWWidget):
......
......@@ -70,7 +70,7 @@ class FTWindow(qt.QMainWindow):
qt.QMainWindow.__init__(self, parent)
# xas object viewer
self.xasObjViewer = XasObjectViewer()
self.xasObjViewer = XasObjectViewer(mapKeys=['Mu'])
self.xasObjViewer._spectrumView._plot.getXAxis().setLabel("R (Angstrom)")
self.xasObjViewer._spectrumView._plot.getYAxis().setLabel("Arbitrary Units")
self.setCentralWidget(self.xasObjViewer)
......@@ -82,7 +82,6 @@ class FTWindow(qt.QMainWindow):
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 selector
self.legendDockWidget = LegendSelector.LegendsDockWidget(parent=self,
......@@ -91,15 +90,29 @@ class FTWindow(qt.QMainWindow):
self.legendDockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget)
# volume key selection
self.addDockWidget(qt.Qt.RightDockWidgetArea,
self.xasObjViewer._mapView.keySelectionDocker)
# plot settings
for ope in (_ft_intensity_plot, _ft_imaginary_plot):
self.xasObjViewer._spectrumView.addCurveOperation(ope)
self.setWindowFlags(qt.Qt.Widget)
# connect signal / slot
self.xasObjViewer.viewTypeChanged.connect(self._updateLegendView)
# set up
self._updateLegendView()
def getNCurves(self):
return len(self.plot.getAllCurves())
def _updateLegendView(self):
self.legendDockWidget.setVisible(self.xasObjViewer.getViewType() is ViewType.spectrum)
self.xasObjViewer._mapView.keySelectionDocker.setVisible(self.xasObjViewer.getViewType() is ViewType.map)
class FTOW(OWWidget):
"""
......
......@@ -35,7 +35,7 @@ from Orange.widgets.settings import Setting
from silx.gui import qt
from xas.core.types import XASObject, Spectrum
import xas.core.process.k_weight
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
import logging
_logger = logging.getLogger(__file__)
......@@ -85,7 +85,7 @@ class KWeightWindow(qt.QMainWindow):
def __init__(self, parent=None):
qt.QMainWindow.__init__(self, parent)
# xas object viewer
self.xasObjViewer = XasObjectViewer()
self.xasObjViewer = XasObjectViewer(mapKeys=['Mu'])
self.xasObjViewer._spectrumView._plot.getXAxis().setLabel("K")
self.setCentralWidget(self.xasObjViewer)
......@@ -109,15 +109,29 @@ class KWeightWindow(qt.QMainWindow):
self.legendDockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget)
self.setWindowFlags(qt.Qt.Widget)
# volume key selection
self.addDockWidget(qt.Qt.RightDockWidgetArea,
self.xasObjViewer._mapView.keySelectionDocker)
# plot settings
for ope in (_normalized_exafs, _ft_window_plot):
self.xasObjViewer._spectrumView.addCurveOperation(ope)
self.setWindowFlags(qt.Qt.Widget)
# connect signal / slot
self.xasObjViewer.viewTypeChanged.connect(self._updateLegendView)
# set up
self._updateLegendView()
def getNCurves(self):
return len(self.plot.getAllCurves())
def _updateLegendView(self, *args, **kwargs):
self.legendDockWidget.setVisible(self.xasObjViewer.getViewType() is ViewType.spectrum)
self.xasObjViewer._mapView.keySelectionDocker.setVisible(self.xasObjViewer.getViewType() is ViewType.map)
class KWeightOW(OWWidget):
"""
......
......@@ -105,7 +105,8 @@ class NormalizationWindow(qt.QMainWindow):
qt.QMainWindow.__init__(self, parent)
# xas object viewer
self.xasObjViewer = XasObjectViewer()
mapKeys = ['Mu', 'NormalizedMu', 'NormalizedSignal', 'NormalizedBackground']
self.xasObjViewer = XasObjectViewer(mapKeys=mapKeys)
self.xasObjViewer._spectrumView._plot.getXAxis().setLabel("Energy (eV)")
self.xasObjViewer._spectrumView._plot.getYAxis().setLabel("Absorption (a.u.)")
self.setCentralWidget(self.xasObjViewer)
......@@ -125,18 +126,29 @@ class NormalizationWindow(qt.QMainWindow):
self.legendDockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget)
self.setWindowFlags(qt.Qt.Widget)
# volume key selection
self.addDockWidget(qt.Qt.RightDockWidgetArea,
self.xasObjViewer._mapView.keySelectionDocker)
# plot settings
for ope in (_spectrum_plot, _normalized_spectrum_plot, _post_plot,
_pre_plot):
self.xasObjViewer._spectrumView.addCurveOperation(ope)
self.setWindowFlags(qt.Qt.Widget)
# connect signal / slot
self.xasObjViewer.viewTypeChanged.connect(self._updateLegendView)
# set up
self._updateLegendView()
def getNCurves(self):
return len(self.xasObjViewer._spectrumView._plot.getAllCurves())
def _updateLegendView(self):
self.legendDockWidget.setVisible(self.xasObjViewer.getViewType() is ViewType.spectrum)
self.xasObjViewer._mapView.keySelectionDocker.setVisible(self.xasObjViewer.getViewType() is ViewType.map)
class NormalizationOW(OWWidget):
......
......@@ -127,14 +127,14 @@ class XASObject(object):
"""convert the XAS object to a dict"""
return {
'configuration': self.configuration,
'spectra': self._spectra_volume(self.spectra, self.dim1, self.dim2),
'spectra': self._spectra_volume(self.spectra, 'Mu', self.dim1, self.dim2),
'energy': self.energy,
'dim1': self.dim1,
'dim2': self.dim2,
}
@staticmethod
def _spectra_volume(spectra, dim_1, dim_2):
def _spectra_volume(spectra, key, dim_1, dim_2):
"""Convert a list of spectra (mu) to a numpy array.
..note: only convert raw data for now"""
if len(spectra) is 0:
......@@ -142,7 +142,12 @@ class XASObject(object):
else:
array = numpy.zeros((len(spectra[0].energy), dim_1 * dim_2))
for i_spectrum, spectrum in enumerate(spectra):
array[:, i_spectrum] = spectrum.mu
subkeys = key.split('/')
value = spectrum[subkeys[0]]
for subkey in subkeys[1:]:
value = value[subkey]
array[:, i_spectrum] = value
return array.reshape((len(spectra[0].energy), dim_1, dim_2))
......
......@@ -65,7 +65,11 @@ class _MapViewAction(qt.QAction):
class XasObjectViewer(qt.QMainWindow):
"""Viewer dedicated to view a XAS object"""
def __init__(self, parent=None):
viewTypeChanged = qt.Signal()
"""emitted when the view type change"""
def __init__(self, parent=None, mapKeys=None):
qt.QMainWindow.__init__(self, parent)
self.setWindowFlags(qt.Qt.Widget)
......@@ -74,7 +78,7 @@ class XasObjectViewer(qt.QMainWindow):
self._mainWidget.setLayout(qt.QVBoxLayout())
self.setCentralWidget(self._mainWidget)
# map view
self._mapView = MapViewer(parent=self)
self._mapView = MapViewer(parent=self, keys=mapKeys)
self._mainWidget.layout().addWidget(self._mapView)
# spectrum view
......@@ -107,6 +111,7 @@ class XasObjectViewer(qt.QMainWindow):
def _updateView(self, *arg, **kwargs):
self._mapView.setVisible(self.getViewType() is ViewType.map)
self._spectrumView.setVisible(self.getViewType() is ViewType.spectrum)
self.viewTypeChanged.emit()
def getViewType(self):
if self._mapViewAction.isChecked():
......@@ -118,21 +123,70 @@ class XasObjectViewer(qt.QMainWindow):
self._mapView.clear()
self._spectrumView.clear()
# set the map view
spectra_volume = XASObject._spectra_volume(xas_obj.spectra,
xas_obj.dim1,
xas_obj.dim2)
self._mapView.setStack(spectra_volume)
# set spectrum view
self._mapView.setXasObject(xas_obj)
self._spectrumView.setXasObject(xas_obj)
class MapViewer(StackViewMainWindow):
def __init__(self, parent=None):
StackViewMainWindow.__init__(self, parent=parent)
self.setKeepDataAspectRatio(True)
self.setColormap(Colormap(name='temperature'))
class MapViewer(qt.QWidget):
def __init__(self, parent=None, keys=None):
"""
:param parent:
:param keys: volume keys to display for the xasObject (Mu,
NormalizedMu...)
"""
assert keys is not None
self._xasObj = None
qt.QWidget.__init__(self, parent=parent)
self.setLayout(qt.QVBoxLayout())
self._mainWindow = StackViewMainWindow(parent=parent)
self.layout().addWidget(self._mainWindow)
self.layout().setContentsMargins(0, 0, 0, 0)
self.layout().setSpacing(0.0)
self._mainWindow.setKeepDataAspectRatio(True)
self._mainWindow.setColormap(Colormap(name='temperature'))
# define the keys combobox
self._keyWidget = qt.QWidget(parent=self)
self._keyWidget.setLayout(qt.QHBoxLayout())
self._keyComboBox = qt.QComboBox(parent=self._keyWidget)
for key in keys:
self._keyComboBox.addItem(key)
self._keyWidget.layout().addWidget(qt.QLabel('view: '))
self._keyWidget.layout().addWidget(self._keyComboBox)
self.keySelectionDocker = qt.QDockWidget(parent=self)
self.keySelectionDocker.setContentsMargins(0, 0, 0, 0)
self._keyWidget.layout().setContentsMargins(0, 0, 0, 0)
self._keyWidget.layout().setSpacing(0.0)
self.keySelectionDocker.setWidget(self._keyWidget)
# self._mainWindow.addDockWidget(qt.Qt.TopDockWidgetArea, dockWidget)
self.keySelectionDocker.setAllowedAreas(qt.Qt.TopDockWidgetArea)
self.keySelectionDocker.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
# connect signal / slot
self._keyComboBox.currentTextChanged.connect(self._updateView)
def clear(self):
self._mainWindow.clear()
def getActiveKey(self):
return self._keyComboBox.currentText()
def setXasObject(self, xas_obj):
self._xasObj = xas_obj
self._updateView()
def _updateView(self, *args, **kwargs):
if self._xasObj is None:
return
# set the map view
spectra_volume = XASObject._spectra_volume(spectra=self._xasObj.spectra,
dim_1=self._xasObj.dim1,
dim_2=self._xasObj.dim2,
key=self.getActiveKey())
self._mainWindow.setStack(spectra_volume)
class _ExtendedSliderWithBrowser(HorizontalSliderWithBrowser):
......
Markdown is supported
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