ft.py 6.69 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
32
import logging

payno's avatar
payno committed
33
from Orange.widgets import gui
payno's avatar
payno committed
34
from Orange.widgets.settings import Setting
payno's avatar
payno committed
35
36
37
from PyMca5.PyMcaGui.physics.xas.XASFourierTransformParameters import (
    XASFourierTransformParameters,
)
38
39
40
from silx.gui import qt
from silx.gui.plot import LegendSelector

payno's avatar
payno committed
41
import est.core.process.pymca.ft
42
from orangecontrib.est.process import _ProcessForOrangeMixIn
payno's avatar
payno committed
43
44
45
from est.gui.XasObjectViewer import XasObjectViewer, ViewType
from est.gui.XasObjectViewer import _normalized_exafs, _ft_window_plot
from est.gui.XasObjectViewer import _ft_intensity_plot, _ft_imaginary_plot
payno's avatar
payno committed
46

Henri Payno's avatar
Henri Payno committed
47

payno's avatar
payno committed
48
from orangecontrib.est.widgets.container import _ParameterWindowContainer
payno's avatar
payno committed
49

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


payno's avatar
payno committed
53
54
55
class FTWindow(qt.QMainWindow):
    def __init__(self, parent=None):
        qt.QMainWindow.__init__(self, parent)
56
57

        # xas object viewer
payno's avatar
payno committed
58
59
60
        self.xasObjViewer = XasObjectViewer(
            mapKeys=["Mu"], spectrumPlots=("FTWindow", "FTIntensity")
        )
61
        self.xasObjViewer._spectrumViews[0]._plotWidget.getXAxis().setLabel("K")
62

payno's avatar
payno committed
63
64
65
66
67
68
        self.xasObjViewer._spectrumViews[1]._plotWidget.getXAxis().setLabel(
            "R (Angstrom)"
        )
        self.xasObjViewer._spectrumViews[1]._plotWidget.getYAxis().setLabel(
            "Arbitrary Units"
        )
69
        self.setCentralWidget(self.xasObjViewer)
payno's avatar
payno committed
70
71
72
        self._pymcaWindow = _ParameterWindowContainer(
            parent=self, parametersWindow=XASFourierTransformParameters
        )
payno's avatar
payno committed
73
74
        dockWidget = qt.QDockWidget(parent=self)

75
        # pymca window
payno's avatar
payno committed
76
77
78
79
        dockWidget.setWidget(self._pymcaWindow)
        self.addDockWidget(qt.Qt.RightDockWidgetArea, dockWidget)
        dockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
        dockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
80

81
        # legend selectors
payno's avatar
payno committed
82
        self.legendDockWidget1 = LegendSelector.LegendsDockWidget(
83
            parent=self, plot=self.xasObjViewer._spectrumViews[0]._plotWidget
payno's avatar
payno committed
84
85
86
87
        )
        self.legendDockWidget1.setAllowedAreas(
            qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea
        )
88
89
90
        self.legendDockWidget1.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
        self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget1)

payno's avatar
payno committed
91
        self.legendDockWidget2 = LegendSelector.LegendsDockWidget(
92
            parent=self, plot=self.xasObjViewer._spectrumViews[1]._plotWidget
payno's avatar
payno committed
93
94
95
96
        )
        self.legendDockWidget2.setAllowedAreas(
            qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea
        )
97
98
        self.legendDockWidget2.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
        self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget2)
payno's avatar
payno committed
99

100
        # volume key selection
payno's avatar
payno committed
101
102
103
        self.addDockWidget(
            qt.Qt.RightDockWidgetArea, self.xasObjViewer._mapView.keySelectionDocker
        )
104

105
        # plot settings
106
107
108
        for ope in (_normalized_exafs, _ft_window_plot):
            self.xasObjViewer._spectrumViews[0].addCurveOperation(ope)

109
        for ope in (_ft_intensity_plot, _ft_imaginary_plot):
110
            self.xasObjViewer._spectrumViews[1].addCurveOperation(ope)
111

112
113
114
115
116
117
118
119
        self.setWindowFlags(qt.Qt.Widget)

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

        # set up
        self._updateLegendView()

120
121
122
    def getNCurves(self):
        return len(self.plot.getAllCurves())

123
    def _updateLegendView(self):
124
125
126
        index, viewType = self.xasObjViewer.getViewType()
        self.legendDockWidget1.setVisible(viewType is ViewType.spectrum and index == 0)
        self.legendDockWidget2.setVisible(viewType is ViewType.spectrum and index == 1)
payno's avatar
payno committed
127
128
129
        self.xasObjViewer._mapView.keySelectionDocker.setVisible(
            viewType is ViewType.map
        )
130

payno's avatar
payno committed
131

132
class FTOW(_ProcessForOrangeMixIn, ewokstaskclass=est.core.process.pymca.ft.PyMca_ft):
payno's avatar
payno committed
133
134
135
    """
    Widget used for signal extraction
    """
payno's avatar
payno committed
136

payno's avatar
payno committed
137
    name = "fourier transform"
payno's avatar
payno committed
138
    id = "orange.widgets.est.pymca.ft"
139
    description = "Progress fourier transform"
payno's avatar
payno committed
140
    icon = "icons/ft.png"
141
    priority = 4
payno's avatar
payno committed
142
143
144
145
146
147
    category = "esrfWidgets"
    keywords = ["spectroscopy", "signal", "fourier", "transform", "fourier transform"]

    want_main_area = True
    resizing_enabled = True

payno's avatar
payno committed
148
    _pymcaSettings = Setting(dict())
149
150
    # kept for compatibility
    static_input = dict({"ft": None, "xas_obj": None})
payno's avatar
payno committed
151
    """Store the configuration of the PyMca XASClass"""
152

payno's avatar
payno committed
153
154
    def __init__(self):
        super().__init__()
155
        self._latest_xas_obj = None
156
        self._window = FTWindow(parent=self)
payno's avatar
payno committed
157
        layout = gui.vBox(self.mainArea, "fourier transform").layout()
payno's avatar
payno committed
158
159
        layout.addWidget(self._window)

payno's avatar
payno committed
160
        # manage settings
161
162
163
164
165
        pymca_settings = self.static_input.get("ft", None)
        if pymca_settings is None:
            pymca_settings = self._pymcaSettings
        if pymca_settings != dict():
            self._window._pymcaWindow.setParameters(pymca_settings)
payno's avatar
payno committed
166

payno's avatar
payno committed
167
        # signal / slot connection
168
        self._window._pymcaWindow.sigChanged.connect(self._updateProcess)
payno's avatar
payno committed
169
170

    def _updateProcess(self, *arv, **kwargs):
payno's avatar
payno committed
171
        self._update_settings()
172
173
        if self._latest_xas_obj:
            self.process(xas_obj=self._latest_xas_obj)
payno's avatar
payno committed
174

payno's avatar
payno committed
175
176
    def _update_settings(self):
        self._pymcaSettings = self._window._pymcaWindow.getParameters()
177
178
179
180
        self.static_input = {
            "xas_obj": None,
            "ft": self._window._pymcaWindow.getParameters(),
        }