Commit c66dbfa4 authored by Henri Payno's avatar Henri Payno
Browse files

[larch] fix display and processing relative to mback

parent 6f3e552e
Pipeline #13318 failed with stage
in 4 minutes and 26 seconds
# 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__ = "24/01/2017"
import logging
import os
import shutil
import tempfile
import unittest
from silx.gui import qt
import time
from orangecontrib.xas.test.OrangeWorkflowTest import OrangeWorflowTest
try:
import PyMca5
except ImportError:
has_pymca = False
else:
has_pymca = True
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.gui.qtapplicationmanager import QApplicationManager
logging.disable(logging.INFO)
_logger = logging.getLogger(__file__)
app = QApplicationManager()
@unittest.skipIf(has_pymca is False, 'PyMca5 is not installed')
class TestSimplePyMcaWorkflow(OrangeWorflowTest):
"""Test the following workflow:
- XASInputOW
- NormalizationOW
- XASOutputOW
"""
def setUp(self):
OrangeWorflowTest.setUp(self)
# set input file
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
self.xasInputWidget.setFileSelected(data_file)
# set output file
self.outputdir = tempfile.mkdtemp()
self.output_file = os.path.join(self.outputdir, 'output.h5')
self.xasOutputWidget.setFileSelected(self.output_file)
def tearDow(self):
if os.path.isdir(self.outputdir):
shutil.rmtree(self.outputdir)
OrangeWorflowTest.tearDown(self)
@classmethod
def setUpClass(cls):
OrangeWorflowTest.setUpClass()
# create widgets
xasInputNode = cls.addWidget(cls, 'orangecontrib.xas.widgets.utils.xas_input.XASInputOW')
xasPreEdgeNode = cls.addWidget(cls, 'orangecontrib.xas.widgets.larch.pre_edge.PreEdgeOW')
xasAutobkNode = cls.addWidget(cls, 'orangecontrib.xas.widgets.larch.autobk.AutobkOW')
xasXFTFNode = cls.addWidget(cls, 'orangecontrib.xas.widgets.larch.xftf.XFTFOW')
xasMBackNode = cls.addWidget(cls, 'orangecontrib.xas.widgets.larch.mback.MbackOW')
xasOutputNode = cls.addWidget(cls, 'orangecontrib.xas.widgets.utils.xas_output.XASOutputOW')
cls.processOrangeEvents(cls)
cls.link(cls, xasInputNode, "spectra", xasPreEdgeNode, "spectra")
cls.link(cls, xasPreEdgeNode, "spectra", xasAutobkNode, "spectra")
cls.link(cls, xasAutobkNode, "spectra", xasXFTFNode, "spectra")
cls.link(cls, xasXFTFNode, "spectra", xasMBackNode, "spectra")
cls.link(cls, xasMBackNode, "spectra", xasOutputNode, "spectra")
cls.processOrangeEvents(cls)
cls.xasInputWidget = cls.getWidgetForNode(cls, xasInputNode)
cls.xasPreEdgeWidget = cls.getWidgetForNode(cls, xasPreEdgeNode)
cls.xasAutobkWidget = cls.getWidgetForNode(cls, xasAutobkNode)
cls.xasXFTFWidget = cls.getWidgetForNode(cls, xasXFTFNode)
cls.xasMbackWidget = cls.getWidgetForNode(cls, xasMBackNode)
cls.xasOutputWidget = cls.getWidgetForNode(cls, xasOutputNode)
@classmethod
def tearDownClass(cls):
cls.xasInputWidget = None
cls.xasPreEdgeWidget = None
cls.xasAutobkWidget = None
cls.xasXFTFWidget = None
cls.xasMbackWidget = None
cls.xasOutputWidget = None
OrangeWorflowTest.tearDownClass()
def test(self):
"""Make sure the workflow is valid and end on the data transfert"""
# start processing
self.xasInputWidget.restart()
# wait until end
app = qt.QApplication.instance()
while (app.hasPendingEvents()):
app.processEvents()
# wait for calculation finished
time.sleep(0.1)
self.processOrangeEventsStack()
self.assertEqual(self.xasPreEdgeWidget._window.getNCurves(), 4)
# check plot have been updated
self.assertEqual(self.xasAutobkWidget._window.getNCurves(), 3)
self.assertEqual(self.xasXFTFWidget._window.getNCurves(), 3)
self.assertEqual(self.xasMbackWidget._window.getNCurves(), 4)
self.assertTrue(os.path.exists(self.output_file))
......@@ -46,13 +46,31 @@ from orangecontrib.xas.progress import QProgress
_logger = logging.getLogger(__file__)
def _plot_raw(spectrum):
assert isinstance(spectrum, Spectrum)
if spectrum.mu is None:
_logger.error('mu not existing')
return
return _CurveOperation(x=spectrum.energy, y=spectrum.mu,
legend='raw spectrum', color='grey')
def _plot_norm(spectrum):
assert isinstance(spectrum, Spectrum)
if spectrum.norm is None:
_logger.error('norm not computed')
return
return _CurveOperation(x=spectrum.energy, y=spectrum.norm,
legend='norm spectrum', color='blue')
def _plot_fpp(spectrum):
assert isinstance(spectrum, Spectrum)
if not hasattr(spectrum, 'fpp'):
_logger.error('fpp has not been computed yet')
return
return _CurveOperation(x=spectrum.energy, y=spectrum.fpp, legend='fpp')
return _CurveOperation(x=spectrum.energy, y=spectrum.fpp, legend='fpp',
color='red')
def _plot_f2(spectrum):
......@@ -60,7 +78,8 @@ def _plot_f2(spectrum):
if not hasattr(spectrum, 'f2'):
_logger.error('f2 has not been computed yet')
return
return _CurveOperation(x=spectrum.energy, y=spectrum.f2, legend='f2')
return _CurveOperation(x=spectrum.energy, y=spectrum.f2, legend='f2',
color='orange')
class MbackWindow(qt.QMainWindow):
......@@ -93,7 +112,7 @@ class MbackWindow(qt.QMainWindow):
self.xasObjViewer._mapView.keySelectionDocker)
# plot settings
for ope in (_plot_fpp, _plot_f2):
for ope in (_plot_fpp, _plot_f2, _plot_raw, _plot_norm):
self.xasObjViewer._spectrumViews[0].addCurveOperation(ope)
self.setWindowFlags(qt.Qt.Widget)
......@@ -109,6 +128,9 @@ class MbackWindow(qt.QMainWindow):
self.legendDockWidget.setVisible(viewType is ViewType.spectrum)
self.xasObjViewer._mapView.keySelectionDocker.setVisible(viewType is ViewType.map)
def getNCurves(self):
return len(self.xasObjViewer._spectrumViews[0]._plot.getAllCurves())
class MbackOW(_ProcessForOrangeMixIn, OWWidget):
"""
......
......@@ -141,6 +141,9 @@ class MbackWindow(qt.QMainWindow):
self.legendDockWidget.setVisible(viewType is ViewType.spectrum)
self.xasObjViewer._mapView.keySelectionDocker.setVisible(viewType is ViewType.map)
def getNCurves(self):
return len(self.xasObjViewer._spectrumViews[0]._plot.getAllCurves())
class XFTFOW(_ProcessForOrangeMixIn, OWWidget):
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment