exafs.py 5.53 KB
Newer Older
payno's avatar
payno committed
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
# 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"


31
import logging
32
from ewokscore.hashing import MissingData
payno's avatar
payno committed
33
from Orange.widgets import gui
payno's avatar
payno committed
34
from PyMca5.PyMcaGui.physics.xas.XASPostEdgeParameters import XASPostEdgeParameters
35
36
from silx.gui import qt
from silx.gui.plot import LegendSelector
payno's avatar
payno committed
37
import est.core.process.pymca.exafs
38
from orangecontrib.est.process import _ProcessForOrangeMixIn
payno's avatar
payno committed
39
from est.gui.XasObjectViewer import XasObjectViewer, ViewType
payno's avatar
payno committed
40
41
42
43
44
from est.gui.XasObjectViewer import (
    _exafs_signal_plot,
    _exafs_postedge_plot,
    _exafs_knots_plot,
)
Henri Payno's avatar
Henri Payno committed
45

payno's avatar
payno committed
46
from orangecontrib.est.widgets.container import _ParameterWindowContainer
47

payno's avatar
payno committed
48

payno's avatar
payno committed
49
50
51
_logger = logging.getLogger(__file__)


payno's avatar
payno committed
52
53
54
class ExafsWindow(qt.QMainWindow):
    def __init__(self, parent=None):
        qt.QMainWindow.__init__(self, parent)
payno's avatar
payno committed
55
        mapKeys = ["mu", "EXAFS.EXAFSKValues", "EXAFS.EXAFSSignal", "EXAFS.PostEdgeB"]
56
        self.xasObjViewer = XasObjectViewer(mapKeys=mapKeys)
57
58
        self.xasObjViewer._spectrumViews[0]._plotWidget.getXAxis().setLabel("K")
        self.xasObjViewer._spectrumViews[0]._plotWidget.getYAxis().setLabel(
payno's avatar
payno committed
59
60
            "Normalized Units"
        )
61
62
63
        self.setCentralWidget(self.xasObjViewer)

        # pymca window
payno's avatar
payno committed
64
65
66
        self._pymcaWindow = _ParameterWindowContainer(
            parent=self, parametersWindow=XASPostEdgeParameters
        )
payno's avatar
payno committed
67
68
69
70
71
72
        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)
73
74

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

84
        # volume key selection
payno's avatar
payno committed
85
86
87
        self.addDockWidget(
            qt.Qt.RightDockWidgetArea, self.xasObjViewer._mapView.keySelectionDocker
        )
88
89

        # plot settings
payno's avatar
payno committed
90
        for ope in (_exafs_signal_plot, _exafs_postedge_plot, _exafs_knots_plot):
91
            self.xasObjViewer._spectrumViews[0].addCurveOperation(ope)
92

93
94
95
96
97
98
99
100
        self.setWindowFlags(qt.Qt.Widget)

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

        # set up
        self._updateLegendView()

101
    def getNCurves(self):
102
103
104
        return len(self.xasObjViewer.getAllCurves())

    def _updateLegendView(self):
105
106
        index, viewType = self.xasObjViewer.getViewType()
        self.legendDockWidget.setVisible(viewType is ViewType.spectrum)
payno's avatar
payno committed
107
108
109
        self.xasObjViewer._mapView.keySelectionDocker.setVisible(
            viewType is ViewType.map
        )
110

payno's avatar
payno committed
111

112
class ExafsOW(
113
    _ProcessForOrangeMixIn, ewokstaskclass=est.core.process.pymca.exafs.PyMca_exafs
114
):
payno's avatar
payno committed
115
116
117
    """
    Widget used for signal extraction
    """
payno's avatar
payno committed
118

payno's avatar
payno committed
119
    name = "exafs"
payno's avatar
payno committed
120
    id = "orange.widgets.est.pymca.exafs"
121
    description = "Progress signal extraction"
payno's avatar
payno committed
122
    icon = "icons/exafs.png"
123
    priority = 3
payno's avatar
payno committed
124
125
126
127
128
129
130
131
    category = "esrfWidgets"
    keywords = ["spectroscopy", "signal"]

    want_main_area = True
    resizing_enabled = True

    def __init__(self):
        super().__init__()
payno's avatar
payno committed
132
        self._window = ExafsWindow()
payno's avatar
payno committed
133
        layout = gui.vBox(self.mainArea, "exafs").layout()
payno's avatar
payno committed
134
        layout.addWidget(self._window)
payno's avatar
payno committed
135

136
137
        self._window.xasObjViewer._spectrumViews[0]._plotWidget.getXAxis().setLabel("K")
        self._window.xasObjViewer._spectrumViews[0]._plotWidget.getYAxis().setLabel(
payno's avatar
payno committed
138
139
            "Normalized Units"
        )
payno's avatar
payno committed
140

141
142
143
        exafs_params = self.task_input_values.get("exafs", MissingData)
        if exafs_params is not MissingData:
            self._window._pymcaWindow.setParameters(exafs_params)
payno's avatar
payno committed
144

payno's avatar
payno committed
145
        # signal / slot connection
146
        self._window._pymcaWindow.sigChanged.connect(self._updateProcess)
payno's avatar
payno committed
147
148

    def _updateProcess(self):
149
        self.receiveDynamicInputs("exafs", self._window._pymcaWindow.getParameters())
150
        self.handleNewSignals()