Skip to content
ft.py 4.91 KiB
Newer Older
payno's avatar
payno committed
# 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"


payno's avatar
payno committed
from silx.gui import qt
from silx.gui.plot import Plot2D, LegendSelector
payno's avatar
payno committed
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from xas.core.types import XASBase
from PyMca5.PyMcaGui.physics.xas.XASFourierTransformParameters import XASFourierTransformParameters
payno's avatar
payno committed
import logging
payno's avatar
payno committed
_logger = logging.getLogger(__file__)


payno's avatar
payno committed
class FTWindow(qt.QMainWindow):
    def __init__(self, parent=None):
        qt.QMainWindow.__init__(self, parent)
        self.plot = Plot2D()
        self.setCentralWidget(self.plot)
        self._pymcaWindow = XASFourierTransformParameters(parent=self)
        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)
        # legend
        self.legendDockWidget = LegendSelector.LegendsDockWidget(parent=self,
                                                                 plot=self.plot)
        self.legendDockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
        self.legendDockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
        self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget)


payno's avatar
payno committed
class FTOW(OWWidget):
    """
    Widget used for signal extraction
    """
    name = "fourier transform"
    id = "orange.widgets.xas.ft"
    description = "Process fourier transform"
    icon = "icons/ft.png"
payno's avatar
payno committed
    category = "esrfWidgets"
    keywords = ["spectroscopy", "signal", "fourier", "transform", "fourier transform"]

    want_main_area = True
    resizing_enabled = True

    inputs = [("spectrum", XASBase, "process")]
    outputs = [("spectrum", XASBase), ("curves", tuple)]
    process_function = xas.core.process.ft.pymca_ft
payno's avatar
payno committed

    def __init__(self):
        super().__init__()
payno's avatar
payno committed
        self._window = FTWindow(parent=self)
        self._latest_xas_obj = None
        layout = gui.vBox(self.mainArea, 'fourier transform').layout()
payno's avatar
payno committed
        layout.addWidget(self._window)

        # signal / slot connection
        self._window._pymcaWindow.sigFTParametersSignal.connect(self._updateProcess)

    def _updateProcess(self, *arv, **kwargs):
        if self._latest_xas_obj:
            self.process(xas_obj=self._latest_xas_obj)
    def process(self, xas_obj):
        if xas_obj is None:
payno's avatar
payno committed
            return
        self._latest_xas_obj = copy.copy(xas_obj)
        xas_obj.configuration['FT'] = self._window._pymcaWindow.getParameters()
        spectrum = FTOW.process_function(xas_obj)
        self._updatePlot(ddict=spectrum)
        xas_obj.spectrum.update(spectrum)
payno's avatar
payno committed

        # emit signal for the plot
        self.send("spectrum", xas_obj)
payno's avatar
payno committed

    def _updatePlot(self, ddict):
        self._window.plot.clear()
        self._window.plot.addCurve(x=ddict["FTRadius"],
                                   y=ddict["FTIntensity"],
payno's avatar
payno committed
                                   legend="FT Intensity",
                                   xlabel="R (Angstrom)",
                                   ylabel="Arbitrary Units")
        self._window.plot.addCurve(x=ddict["FTRadius"],
                                   y=ddict["FTImaginary"],
payno's avatar
payno committed
                                   legend="FT Imaginary",
                                   xlabel="R (Angstrom)",
                                   ylabel="Arbitrary Units",
                                   color="red")
payno's avatar
payno committed
        self._window.plot.resetZoom()