ft.py 6.14 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
payno's avatar
payno committed
32
from Orange.widgets import gui
payno's avatar
payno committed
33
34
35
from PyMca5.PyMcaGui.physics.xas.XASFourierTransformParameters import (
    XASFourierTransformParameters,
)
36
37
from silx.gui import qt
from silx.gui.plot import LegendSelector
payno's avatar
payno committed
38
import est.core.process.pymca.ft
39
from orangecontrib.est.process import _ProcessForOrangeMixIn
payno's avatar
payno committed
40
41
42
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
43
from ewokscore.hashing import MissingData
payno's avatar
payno committed
44

Henri Payno's avatar
Henri Payno committed
45

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

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


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

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

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

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

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

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

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

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

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

110
111
112
113
114
115
116
117
        self.setWindowFlags(qt.Qt.Widget)

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

        # set up
        self._updateLegendView()

118
119
120
    def getNCurves(self):
        return len(self.plot.getAllCurves())

121
    def _updateLegendView(self):
122
123
124
        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
125
126
127
        self.xasObjViewer._mapView.keySelectionDocker.setVisible(
            viewType is ViewType.map
        )
128

payno's avatar
payno committed
129

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

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

    want_main_area = True
    resizing_enabled = True

    def __init__(self):
        super().__init__()
148
        self._window = FTWindow(parent=self)
payno's avatar
payno committed
149
        layout = gui.vBox(self.mainArea, "fourier transform").layout()
payno's avatar
payno committed
150
151
        layout.addWidget(self._window)

152
153
154
        ft_params = self.task_input_values.get("ft", MissingData)
        if ft_params is not MissingData:
            self._window._pymcaWindow.setParameters(ft_params)
payno's avatar
payno committed
155

payno's avatar
payno committed
156
        # signal / slot connection
157
        self._window._pymcaWindow.sigChanged.connect(self._updateProcess)
payno's avatar
payno committed
158
159

    def _updateProcess(self, *arv, **kwargs):
160
        self.receiveDynamicInputs("ft", self._window._pymcaWindow.getParameters())
161
        self.handleNewSignals()