mback_norm.py 5.68 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
# 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
34
from Orange.widgets.widget import OWWidget
35
36
from silx.gui import qt
from silx.gui.plot import LegendSelector
payno's avatar
payno committed
37
38
39
40
41
42
import est.core.process.larch.mback_norm
from orangecontrib.est.process import _ProcessForOrangeMixIn
from est.gui.XasObjectViewer import XasObjectViewer, ViewType
from est.gui.XasObjectViewer import _plot_norm, _plot_mback_mu
from est.gui.larch.mback import _MBackParameters
from orangecontrib.est.widgets.container import _ParameterWindowContainer
43
from ewokscore.hashing import MissingData
44
45
46
47
48
49
50
51
52

_logger = logging.getLogger(__file__)


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

        # xas object viewer
payno's avatar
payno committed
53
        mapKeys = ["mu", "mback_mu", "norm"]
54
        self.xasObjViewer = XasObjectViewer(mapKeys=mapKeys)
payno's avatar
payno committed
55
        self.xasObjViewer._spectrumViews[0]._plotWidget.getXAxis().setLabel(
payno's avatar
payno committed
56
57
            "Energy (eV)"
        )
58
        self.setCentralWidget(self.xasObjViewer)
payno's avatar
payno committed
59
60
61
        self._parametersWindow = _ParameterWindowContainer(
            parent=self, parametersWindow=_MBackParameters
        )
62
63
64
65
66
67
68
69
70
        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
71
        self.legendDockWidget = LegendSelector.LegendsDockWidget(
72
            parent=self, plot=self.xasObjViewer._spectrumViews[0]._plotWidget
payno's avatar
payno committed
73
74
75
76
        )
        self.legendDockWidget.setAllowedAreas(
            qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea
        )
77
78
79
80
        self.legendDockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
        self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget)

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

        # plot settings
86
        for ope in (_plot_mback_mu, _plot_norm):
87
88
89
90
91
92
93
94
95
96
97
98
99
            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
100
101
102
        self.xasObjViewer._mapView.keySelectionDocker.setVisible(
            viewType is ViewType.map
        )
103

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

107

108
109
class Mback_normOW(
    _ProcessForOrangeMixIn,
110
    OWWidget,
111
):
112
113
114
    """
    Widget used for signal extraction
    """
payno's avatar
payno committed
115

116
    name = "mback norm"
payno's avatar
payno committed
117
    id = "orange.widgets.est.larch.mback.Mback_normOW"
payno's avatar
payno committed
118
119
120
121
    description = (
        "simplified version of MBACK to Match mu(E) data for "
        "tabulated f''(E) for normalization"
    )
122
    icon = "icons/mbacknorm.svg"
123
124
125
126
127
128
    priority = 6
    category = "esrfWidgets"
    keywords = ["spectroscopy", "mback_norm"]

    want_main_area = True
    resizing_enabled = True
129
    ewokstaskclass = est.core.process.larch.mback_norm.Larch_mback_norm
130
131

    _larchSettings = Setting(dict())
132
133
    """Kept for compatiblity"""
    static_input = Setting({"mback_norm": None})
134
135
136
137
138
    """Store the configuration of the larch configuration"""

    def __init__(self):
        super().__init__()
        self._window = Mback_normWindow(parent=self)
payno's avatar
payno committed
139
        layout = gui.vBox(self.mainArea, "mback_norm").layout()
140
        layout.addWidget(self._window)
payno's avatar
payno committed
141
        self._window.xasObjViewer.setWindowTitle("spectra")
142
143

        # manage settings
144
145
        larch_settings = self.task_input_values.get("mback_norm", MissingData)
        if larch_settings is not MissingData:
146
            self._window._parametersWindow.setParameters(larch_settings)
147
148
149
150
151

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

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