Commit 89f93c70 authored by Henri Payno's avatar Henri Payno
Browse files

[orangecontrib] normalization work

- orange signal 'spectra' is renamed xas_obj
- update to the new orange way to define Input and Output
- add a converter widget to convert from xas object to data table
parent 5a307d0c
Pipeline #13434 passed with stage
in 4 minutes and 51 seconds
......@@ -8,10 +8,10 @@
<node id="4" name="xftf" position="(643.0, 354.0)" project_name="xas" qualified_name="orangecontrib.xas.widgets.larch.xftf.XFTFOW" title="xftf" version="" />
</nodes>
<links>
<link enabled="true" id="0" sink_channel="spectra" sink_node_id="2" source_channel="spectra" source_node_id="0" />
<link enabled="true" id="1" sink_channel="spectra" sink_node_id="3" source_channel="spectra" source_node_id="2" />
<link enabled="true" id="2" sink_channel="spectra" sink_node_id="4" source_channel="spectra" source_node_id="3" />
<link enabled="true" id="3" sink_channel="spectra" sink_node_id="1" source_channel="spectra" source_node_id="4" />
<link enabled="true" id="0" sink_channel="xas_obj" sink_node_id="2" source_channel="xas_obj" source_node_id="0" />
<link enabled="true" id="1" sink_channel="xas_obj" sink_node_id="3" source_channel="xas_obj" source_node_id="2" />
<link enabled="true" id="2" sink_channel="xas_obj" sink_node_id="4" source_channel="xas_obj" source_node_id="3" />
<link enabled="true" id="3" sink_channel="xas_obj" sink_node_id="1" source_channel="xas_obj" source_node_id="4" />
</links>
<annotations>
<text font-family="Helvetica" font-size="14" id="0" rect="(-14.0, 228.0, 160.0, 73.0)" type="text/plain">A File widget. Double click to open it and select the dataset file.</text>
......
......@@ -9,11 +9,11 @@
<node id="5" name="fourier transform" position="(752.0, 466.0)" project_name="xas" qualified_name="orangecontrib.xas.widgets.pymca.ft.FTOW" title="fourier transform" version="" />
</nodes>
<links>
<link enabled="true" id="0" sink_channel="spectra" sink_node_id="2" source_channel="spectra" source_node_id="0" />
<link enabled="true" id="1" sink_channel="spectra" sink_node_id="3" source_channel="spectra" source_node_id="2" />
<link enabled="true" id="2" sink_channel="spectra" sink_node_id="4" source_channel="spectra" source_node_id="3" />
<link enabled="true" id="3" sink_channel="spectra" sink_node_id="5" source_channel="spectra" source_node_id="4" />
<link enabled="true" id="4" sink_channel="spectra" sink_node_id="1" source_channel="spectra" source_node_id="5" />
<link enabled="true" id="0" sink_channel="xas_obj" sink_node_id="2" source_channel="xas_obj" source_node_id="0" />
<link enabled="true" id="1" sink_channel="xas_obj" sink_node_id="3" source_channel="xas_obj" source_node_id="2" />
<link enabled="true" id="2" sink_channel="xas_obj" sink_node_id="4" source_channel="xas_obj" source_node_id="3" />
<link enabled="true" id="3" sink_channel="xas_obj" sink_node_id="5" source_channel="xas_obj" source_node_id="4" />
<link enabled="true" id="4" sink_channel="xas_obj" sink_node_id="1" source_channel="xas_obj" source_node_id="5" />
</links>
<annotations>
<text font-family="Helvetica" font-size="14" id="0" rect="(-16.0, 231.0, 160.0, 73.0)" type="text/plain">A File widget. Double click to open it and select the dataset file.</text>
......
......@@ -37,11 +37,13 @@ _logger = logging.getLogger(__file__)
class _ProcessForOrangeMixIn(object):
"""
Group processing and progress display in a common class for pymca process.
Group processing and progress display in a common class for xasObject
process.
If this process own a widget to display the xas object then this one should
be named '_window'
"""
def __init__(self):
# progress
self._progress = gui.ProgressBar(self, 100)
......@@ -73,7 +75,7 @@ class _ProcessForOrangeMixIn(object):
if hasattr(self, '_window') and hasattr(self._window, 'xasObjViewer'):
self._window.xasObjViewer.setXASObj(xas_obj=xas_obj)
# emit signal for the plot
self.send("spectra", xas_obj)
self.Outputs.res_xas_obj.send(xas_obj)
def _canProcess(self):
return self.__processingThread is None or not self.__processingThread.isRunning()
......
......@@ -88,11 +88,11 @@ class TestSimpleLarchWorkflow(OrangeWorflowTest):
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", xasMBackNormNode, "spectra")
cls.link(cls, xasMBackNormNode, "spectra", xasOutputNode, "spectra")
cls.link(cls, xasInputNode, "xas_obj", xasPreEdgeNode, "xas_obj")
cls.link(cls, xasPreEdgeNode, "xas_obj", xasAutobkNode, "xas_obj")
cls.link(cls, xasAutobkNode, "xas_obj", xasXFTFNode, "xas_obj")
cls.link(cls, xasXFTFNode, "xas_obj", xasMBackNormNode, "xas_obj")
cls.link(cls, xasMBackNormNode, "xas_obj", xasOutputNode, "xas_obj")
cls.processOrangeEvents(cls)
cls.xasInputWidget = cls.getWidgetForNode(cls, xasInputNode)
......
......@@ -86,11 +86,11 @@ class TestSimplePyMcaWorkflow(OrangeWorflowTest):
cls.processOrangeEvents(cls)
cls.link(cls, xasInputNode, "spectra", xasNormalizationNode, "spectra")
cls.link(cls, xasNormalizationNode, "spectra", xasEXAFSNode, "spectra")
cls.link(cls, xasEXAFSNode, "spectra", xasKWeightNode, "spectra")
cls.link(cls, xasKWeightNode, "spectra", xasFTNode, "spectra")
cls.link(cls, xasFTNode, "spectra", xasOutputNode, "spectra")
cls.link(cls, xasInputNode, "xas_obj", xasNormalizationNode, "xas_obj")
cls.link(cls, xasNormalizationNode, "xas_obj", xasEXAFSNode, "xas_obj")
cls.link(cls, xasEXAFSNode, "xas_obj", xasKWeightNode, "xas_obj")
cls.link(cls, xasKWeightNode, "xas_obj", xasFTNode, "xas_obj")
cls.link(cls, xasFTNode, "xas_obj", xasOutputNode, "xas_obj")
cls.processOrangeEvents(cls)
cls.xasInputWidget = cls.getWidgetForNode(cls, xasInputNode)
......
......@@ -51,6 +51,10 @@ class Converter(object):
@staticmethod
def toDataTable(xas_object):
_logger.warning('casting xas_object to Orange.data.Table might bring '
'lost of some information (process flow, '
'treatment result...). Only keep energy and absorbed '
'beam information')
spectra = XASObject._spectra_volume(xas_object.spectra,
key='mu',
dim_1=xas_object.dim1,
......
......@@ -33,6 +33,8 @@ import logging
from Orange.widgets import gui
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from Orange.widgets.widget import Input, Output
import Orange.data
from silx.gui import qt
from silx.gui.plot import LegendSelector
import xas.core.process.larch.autobk
......@@ -42,6 +44,7 @@ from xas.core.types import XASObject, Spectrum
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
from xas.gui.larch.autobk import _AutobkParameters
from orangecontrib.xas.progress import QProgress
from orangecontrib.xas.utils import Converter
_logger = logging.getLogger(__file__)
......@@ -139,15 +142,22 @@ class AutobkOW(_ProcessForOrangeMixIn, OWWidget):
want_main_area = True
resizing_enabled = True
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.larch.autobk.Larch_autobk
_settings = Setting(dict())
"""Store the configuration of the PyMca XASClass"""
class Inputs:
xas_obj = Input('xas_obj', XASObject, default=True)
# simple compatibility for some Orange widget and especialy the
# 'spectroscopy add-on'
data_table = Input('Data', Orange.data.Table)
class Outputs:
res_xas_obj = Output('xas_obj', XASObject)
# by default we want to avoid sending 'Orange.data.Table' to avoid
# loosing the XASObject flow process and results.
def __init__(self):
super().__init__()
self._latest_xas_obj = None
......@@ -172,6 +182,13 @@ class AutobkOW(_ProcessForOrangeMixIn, OWWidget):
def _update_settings(self):
self._settings = self._window._parametersWindow.getParameters()
@Inputs.data_table
def processFrmDataTable(self, data_table):
if data_table is None:
return
self.process(Converter.toXASObject(data_table=data_table))
@Inputs.xas_obj
def process(self, xas_obj):
if xas_obj is None:
return
......
......@@ -33,6 +33,8 @@ import logging
from Orange.widgets import gui
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from Orange.widgets.widget import Input, Output
import Orange.data
from silx.gui import qt
from silx.gui.plot import LegendSelector
import xas.core.process.larch.mback
......@@ -43,6 +45,7 @@ from xas.gui.XasObjectViewer import XasObjectViewer, ViewType
from xas.gui.larch.mback import _MBackParameters
from orangecontrib.xas.progress import QProgress
from xas.gui.XasObjectViewer import _plot_norm, _plot_raw, _plot_fpp, _plot_f2
from orangecontrib.xas.utils import Converter
_logger = logging.getLogger(__file__)
......@@ -115,15 +118,22 @@ class MbackOW(_ProcessForOrangeMixIn, OWWidget):
want_main_area = True
resizing_enabled = True
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.larch.mback.Larch_mback
_larchSettings = Setting(dict())
"""Store the configuration of the larch configuration"""
class Inputs:
xas_obj = Input('xas_obj', XASObject, default=True)
# simple compatibility for some Orange widget and especialy the
# 'spectroscopy add-on'
data_table = Input('Data', Orange.data.Table)
class Outputs:
res_xas_obj = Output('xas_obj', XASObject)
# by default we want to avoid sending 'Orange.data.Table' to avoid
# loosing the XASObject flow process and results.
def __init__(self):
super().__init__()
self._latest_xas_obj = None
......@@ -147,6 +157,13 @@ class MbackOW(_ProcessForOrangeMixIn, OWWidget):
def _update_settings(self):
self._larchSettings = self._window._parametersWindow.getParameters()
@Inputs.data_table
def processFrmDataTable(self, data_table):
if data_table is None:
return
self.process(Converter.toXASObject(data_table=data_table))
@Inputs.xas_obj
def process(self, xas_obj):
if xas_obj is None:
return
......
......@@ -33,6 +33,8 @@ import logging
from Orange.widgets import gui
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from Orange.widgets.widget import Input, Output
import Orange.data
from silx.gui import qt
from silx.gui.plot import LegendSelector
import xas.core.process.larch.mback_norm
......@@ -43,6 +45,7 @@ from xas.gui.XasObjectViewer import XasObjectViewer, ViewType
from xas.gui.XasObjectViewer import _plot_norm, _plot_mback_mu
from xas.gui.larch.mback import _MBackParameters
from orangecontrib.xas.progress import QProgress
from orangecontrib.xas.utils import Converter
_logger = logging.getLogger(__file__)
......@@ -115,15 +118,22 @@ class Mback_normOW(_ProcessForOrangeMixIn, OWWidget):
want_main_area = True
resizing_enabled = True
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.larch.mback_norm.Larch_mback_norm
_larchSettings = Setting(dict())
"""Store the configuration of the larch configuration"""
class Inputs:
xas_obj = Input('xas_obj', XASObject, default=True)
# simple compatibility for some Orange widget and especialy the
# 'spectroscopy add-on'
data_table = Input('Data', Orange.data.Table)
class Outputs:
res_xas_obj = Output('xas_obj', XASObject)
# by default we want to avoid sending 'Orange.data.Table' to avoid
# loosing the XASObject flow process and results.
def __init__(self):
super().__init__()
self._latest_xas_obj = None
......@@ -147,6 +157,13 @@ class Mback_normOW(_ProcessForOrangeMixIn, OWWidget):
def _update_settings(self):
self._larchSettings = self._window._parametersWindow.getParameters()
@Inputs.data_table
def processFrmDataTable(self, data_table):
if data_table is None:
return
self.process(Converter.toXASObject(data_table=data_table))
@Inputs.xas_obj
def process(self, xas_obj):
if xas_obj is None:
return
......
......@@ -33,6 +33,8 @@ import logging
from Orange.widgets import gui
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from Orange.widgets.widget import Input, Output
import Orange.data
from silx.gui import qt
from silx.gui.plot import LegendSelector
import xas.core.process.larch.pre_edge
......@@ -44,6 +46,7 @@ from xas.gui.XasObjectViewer import (_plot_edge, _plot_norm, _plot_norm_area,
_plot_post_edge, _plot_pre_edge)
from xas.gui.larch.pre_edge import _MPreEdgeParameters
from orangecontrib.xas.progress import QProgress
from orangecontrib.xas.utils import Converter
_logger = logging.getLogger(__file__)
......@@ -125,15 +128,22 @@ class PreEdgeOW(_ProcessForOrangeMixIn, OWWidget):
want_main_area = True
resizing_enabled = True
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.larch.pre_edge.Larch_pre_edge
_larchSettings = Setting(dict())
"""Store the configuration of the larch configuration"""
class Inputs:
xas_obj = Input('xas_obj', XASObject, default=True)
# simple compatibility for some Orange widget and especialy the
# 'spectroscopy add-on'
data_table = Input('Data', Orange.data.Table)
class Outputs:
res_xas_obj = Output('xas_obj', XASObject)
# by default we want to avoid sending 'Orange.data.Table' to avoid
# loosing the XASObject flow process and results.
def __init__(self):
super().__init__()
self._latest_xas_obj = None
......@@ -157,6 +167,13 @@ class PreEdgeOW(_ProcessForOrangeMixIn, OWWidget):
def _update_settings(self):
self._larchSettings = self._window._parametersWindow.getParameters()
@Inputs.data_table
def processFrmDataTable(self, data_table):
if data_table is None:
return
self.process(Converter.toXASObject(data_table=data_table))
@Inputs.xas_obj
def process(self, xas_obj):
if xas_obj is None:
return
......
......@@ -33,6 +33,8 @@ import logging
from Orange.widgets import gui
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from Orange.widgets.widget import Input, Output
import Orange.data
from silx.gui import qt
from silx.gui.plot import LegendSelector
import xas.core.process.larch.xftf
......@@ -42,6 +44,7 @@ from xas.core.types import XASObject, Spectrum
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
from xas.gui.larch.xftf import _MXFTFParameters
from orangecontrib.xas.progress import QProgress
from orangecontrib.xas.utils import Converter
_logger = logging.getLogger(__file__)
......@@ -163,15 +166,22 @@ class XFTFOW(_ProcessForOrangeMixIn, OWWidget):
want_main_area = True
resizing_enabled = True
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.larch.xftf.Larch_xftf
_larchSettings = Setting(dict())
"""Store the configuration of the larch configuration"""
class Inputs:
xas_obj = Input('xas_obj', XASObject, default=True)
# simple compatibility for some Orange widget and especialy the
# 'spectroscopy add-on'
data_table = Input('Data', Orange.data.Table)
class Outputs:
res_xas_obj = Output('xas_obj', XASObject)
# by default we want to avoid sending 'Orange.data.Table' to avoid
# loosing the XASObject flow process and results.
def __init__(self):
super().__init__()
self._latest_xas_obj = None
......@@ -195,6 +205,13 @@ class XFTFOW(_ProcessForOrangeMixIn, OWWidget):
def _update_settings(self):
self._larchSettings = self._window._parametersWindow.getParameters()
@Inputs.data_table
def processFrmDataTable(self, data_table):
if data_table is None:
return
self.process(Converter.toXASObject(data_table=data_table))
@Inputs.xas_obj
def process(self, xas_obj):
if xas_obj is None:
return
......
......@@ -34,6 +34,9 @@ import logging
from Orange.widgets import gui
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from Orange.widgets.widget import Input, Output
import Orange.data
from xas.core.types import XASObject
from PyMca5.PyMcaGui.physics.xas.XASPostEdgeParameters import \
XASPostEdgeParameters
from silx.gui import qt
......@@ -42,9 +45,11 @@ from silx.gui.plot import LegendSelector
import xas.core.process.pymca.exafs
from orangecontrib.xas.process import _ProcessForOrangeMixIn, \
ProcessRunnable
from xas.core.types import XASObject, Spectrum
from xas.core.types import Spectrum
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
from orangecontrib.xas.progress import QProgress
from orangecontrib.xas.utils import Converter
_logger = logging.getLogger(__file__)
......@@ -165,14 +170,22 @@ class ExafsOW(_ProcessForOrangeMixIn, OWWidget):
want_main_area = True
resizing_enabled = True
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.pymca.exafs.PyMca_exafs
_larchSettings = Setting(dict())
"""Store the configuration of the PyMca XASClass"""
class Inputs:
xas_obj = Input('xas_obj', XASObject, default=True)
# simple compatibility for some Orange widget and especialy the
# 'spectroscopy add-on'
data_table = Input('Data', Orange.data.Table)
class Outputs:
res_xas_obj = Output('xas_obj', XASObject)
# by default we want to avoid sending 'Orange.data.Table' to avoid
# loosing the XASObject flow process and results.
def __init__(self):
super().__init__()
self._latest_xas_obj = None
......@@ -199,6 +212,13 @@ class ExafsOW(_ProcessForOrangeMixIn, OWWidget):
def _update_settings(self):
self._larchSettings = self._window._pymcaWindow.getParameters()
@Inputs.data_table
def processFrmDataTable(self, data_table):
if data_table is None:
return
self.process(Converter.toXASObject(data_table=data_table))
@Inputs.xas_obj
def process(self, xas_obj):
if xas_obj is None:
return
......
......@@ -34,6 +34,8 @@ import logging
from Orange.widgets import gui
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from Orange.widgets.widget import Input, Output
import Orange.data
from PyMca5.PyMcaGui.physics.xas.XASFourierTransformParameters import \
XASFourierTransformParameters
from silx.gui import qt
......@@ -45,6 +47,7 @@ from orangecontrib.xas.process import _ProcessForOrangeMixIn, \
from xas.core.types import XASObject, Spectrum
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
from orangecontrib.xas.progress import QProgress
from orangecontrib.xas.utils import Converter
_logger = logging.getLogger(__file__)
......@@ -189,14 +192,22 @@ class FTOW(_ProcessForOrangeMixIn, OWWidget):
want_main_area = True
resizing_enabled = True
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.pymca.ft.PyMca_ft
_pymcaSettings = Setting(dict())
"""Store the configuration of the PyMca XASClass"""
class Inputs:
xas_obj = Input('xas_obj', XASObject, default=True)
# simple compatibility for some Orange widget and especialy the
# 'spectroscopy add-on'
data_table = Input('Data', Orange.data.Table)
class Outputs:
res_xas_obj = Output('xas_obj', XASObject)
# by default we want to avoid sending 'Orange.data.Table' to avoid
# loosing the XASObject flow process and results.
def __init__(self):
super().__init__()
self._latest_xas_obj = None
......@@ -219,6 +230,13 @@ class FTOW(_ProcessForOrangeMixIn, OWWidget):
if self._latest_xas_obj:
self.process(xas_obj=self._latest_xas_obj)
@Inputs.data_table
def processFrmDataTable(self, data_table):
if data_table is None:
return
self.process(Converter.toXASObject(data_table=data_table))
@Inputs.xas_obj
def process(self, xas_obj):
if xas_obj is None:
return
......
......@@ -33,6 +33,8 @@ import logging
from Orange.widgets import gui
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from Orange.widgets.widget import Input, Output
import Orange.data
from silx.gui import qt
import xas.core.process.pymca.k_weight
......@@ -40,6 +42,7 @@ from orangecontrib.xas.process import _ProcessForOrangeMixIn, \
ProcessRunnable
from xas.core.types import XASObject
from orangecontrib.xas.progress import QProgress
from orangecontrib.xas.utils import Converter
_logger = logging.getLogger(__file__)
......@@ -79,14 +82,22 @@ class KWeightOW(_ProcessForOrangeMixIn, OWWidget):
want_main_area = True
resizing_enabled = True
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.pymca.k_weight.PyMca_k_weight
_kWeightSetting = Setting(int(3))
"""Store the configuration of the PyMca XASClass"""
class Inputs:
xas_obj = Input('xas_obj', XASObject, default=True)
# simple compatibility for some Orange widget and especialy the
# 'spectroscopy add-on'
data_table = Input('Data', Orange.data.Table)
class Outputs:
res_xas_obj = Output('xas_obj', XASObject)
# by default we want to avoid sending 'Orange.data.Table' to avoid
# loosing the XASObject flow process and results.
def __init__(self):
super().__init__()
self._latest_xas_obj = None
......@@ -109,6 +120,13 @@ class KWeightOW(_ProcessForOrangeMixIn, OWWidget):
if self._latest_xas_obj:
self.process(self._latest_xas_obj)
@Inputs.data_table
def processFrmDataTable(self, data_table):
if data_table is None:
return
self.process(Converter.toXASObject(data_table=data_table))
@Inputs.xas_obj
def process(self, xas_obj):
if xas_obj is None:
return
......
......@@ -34,6 +34,8 @@ import logging
from Orange.widgets import gui
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from Orange.widgets.widget import Input, Output
import Orange.data
from PyMca5.PyMcaGui.physics.xas.XASNormalizationParameters import \
XASNormalizationParameters
from silx.gui import qt
......@@ -46,6 +48,7 @@ from orangecontrib.xas.process import ProcessRunnable
from xas.core.types import XASObject
from xas.gui.XasObjectViewer import XasObjectViewer, ViewType
from orangecontrib.xas.progress import QProgress
from orangecontrib.xas.utils import Converter
_logger = logging.getLogger(__file__)
......@@ -116,15 +119,22 @@ class NormalizationOW(_ProcessForOrangeMixIn, OWWidget):
want_main_area = True
resizing_enabled = True
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.pymca.normalization.PyMca_normalization
_pymcaSettings = Setting(dict())
"""Store the configuration of the PyMca XASClass"""