mback.py 5.67 KB
Newer Older
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
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2016-2017 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/

__authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "06/07/2019"


import logging
from Orange.widgets import gui
from Orange.widgets.settings import Setting
from silx.gui import qt
from silx.gui.plot import LegendSelector
payno's avatar
payno committed
36
37
38
39
40
41
import est.core.process.larch.mback
from orangecontrib.est.process import _ProcessForOrangeMixIn
from est.gui.XasObjectViewer import XasObjectViewer, ViewType
from est.gui.larch.mback import _MBackParameters
from est.gui.XasObjectViewer import _plot_norm, _plot_raw, _plot_fpp, _plot_f2
from orangecontrib.est.widgets.container import _ParameterWindowContainer
42
from ewokscore.hashing import MissingData
43
44
45
46
47
48
49
50
51

_logger = logging.getLogger(__file__)


class MbackWindow(qt.QMainWindow):
    def __init__(self, parent=None):
        qt.QMainWindow.__init__(self, parent)

        # xas object viewer
payno's avatar
payno committed
52
        mapKeys = ["mu", "fpp", "f2"]
53
        self.xasObjViewer = XasObjectViewer(mapKeys=mapKeys)
payno's avatar
payno committed
54
55
56
        self.xasObjViewer._spectrumViews[0]._plotWidget.getXAxis().setLabel(
            "Energy (eV)"
        )
57
        self.setCentralWidget(self.xasObjViewer)
payno's avatar
payno committed
58
59
60
        self._parametersWindow = _ParameterWindowContainer(
            parent=self, parametersWindow=_MBackParameters
        )
61
62
63
64
65
66
67
68
69
        dockWidget = qt.QDockWidget(parent=self)

        # parameters window
        dockWidget.setWidget(self._parametersWindow)
        self.addDockWidget(qt.Qt.RightDockWidgetArea, dockWidget)
        dockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
        dockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)

        # legend selector
payno's avatar
payno committed
70
        self.legendDockWidget = LegendSelector.LegendsDockWidget(
71
            parent=self, plot=self.xasObjViewer._spectrumViews[0]._plotWidget
payno's avatar
payno committed
72
73
74
75
        )
        self.legendDockWidget.setAllowedAreas(
            qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea
        )
76
77
78
79
        self.legendDockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
        self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget)

        # volume key selection
payno's avatar
payno committed
80
81
82
        self.addDockWidget(
            qt.Qt.RightDockWidgetArea, self.xasObjViewer._mapView.keySelectionDocker
        )
83
84

        # plot settings
85
        for ope in (_plot_fpp, _plot_f2, _plot_raw, _plot_norm):
86
87
88
89
90
91
92
93
94
95
96
97
98
            self.xasObjViewer._spectrumViews[0].addCurveOperation(ope)

        self.setWindowFlags(qt.Qt.Widget)

        # connect signal / slot
        self.xasObjViewer.viewTypeChanged.connect(self._updateLegendView)

        # set up
        self._updateLegendView()

    def _updateLegendView(self):
        index, viewType = self.xasObjViewer.getViewType()
        self.legendDockWidget.setVisible(viewType is ViewType.spectrum)
payno's avatar
payno committed
99
100
101
        self.xasObjViewer._mapView.keySelectionDocker.setVisible(
            viewType is ViewType.map
        )
102

103
    def getNCurves(self):
104
        return len(self.xasObjViewer._spectrumViews[0]._plotWidget.getAllCurves())
105

106

107
108
109
class MbackOW(
    _ProcessForOrangeMixIn, ewokstaskclass=est.core.process.larch.mback.Larch_mback
):
110
111
112
    """
    Widget used for signal extraction
    """
payno's avatar
payno committed
113

114
    name = "mback"
payno's avatar
payno committed
115
    id = "orange.widgets.est.larch.mback.MbackOW"
payno's avatar
payno committed
116
117
118
119
    description = (
        "Match mu(E) data for tabulated f''(E) using the MBACK "
        "algorithm and, optionally, the Lee & Xiang extension"
    )
120
    icon = "icons/mback.svg"
121
122
    priority = 5
    category = "esrfWidgets"
123
    keywords = ["spectroscopy", "mback"]
124
125
126
127
128

    want_main_area = True
    resizing_enabled = True

    _larchSettings = Setting(dict())
129
130
    # kept for compatibility
    static_input = Setting({"mback": None})
131
132
133
134
135
    """Store the configuration of the larch configuration"""

    def __init__(self):
        super().__init__()
        self._window = MbackWindow(parent=self)
payno's avatar
payno committed
136
        layout = gui.vBox(self.mainArea, "mback").layout()
137
        layout.addWidget(self._window)
payno's avatar
payno committed
138
        self._window.xasObjViewer.setWindowTitle("spectra")
139
140

        # manage settings
141
142
        larch_settings = self.task_input_values.get("mback", MissingData)
        if larch_settings is not MissingData:
143
            self._window._parametersWindow.setParameters(larch_settings)
144
145
146
147

        # connect signals / slots
        self._window._parametersWindow.sigChanged.connect(self._updateProcess)

148
        # set up (insure settings will be store
149
        self._update_settings()
150

151
    def _updateProcess(self):
152
153
154
        self.receiveDynamicInputs(
            "mback", self._window._parametersWindow.getParameters()
        )
155
        self.handleNewSignals()