Commit 335339a0 authored by payno's avatar payno
Browse files

Merge branch 'ewoks_second_round' into 'master'

[ewoks integration] add static_input to OW

See merge request workflow/est!46
parents b78a4c35 b84008eb
Pipeline #55864 failed with stages
in 5 minutes and 56 seconds
...@@ -133,7 +133,11 @@ _USE_MULTIPROCESSING_POOL = False ...@@ -133,7 +133,11 @@ _USE_MULTIPROCESSING_POOL = False
class Larch_autobk( class Larch_autobk(
Process, name="autobk", input_names=["xas_obj"], output_names=["xas_obj"] Process,
name="autobk",
input_names=["xas_obj"],
output_names=["xas_obj"],
optional_input_names=["autobk"],
): ):
def set_properties(self, properties): def set_properties(self, properties):
if "_larchSettings" in properties: if "_larchSettings" in properties:
...@@ -144,8 +148,9 @@ class Larch_autobk( ...@@ -144,8 +148,9 @@ class Larch_autobk(
if xas_obj is None: if xas_obj is None:
raise ValueError("xas_obj should be provided") raise ValueError("xas_obj should be provided")
_xas_obj = self.getXasObject(xas_obj=xas_obj) _xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings: if self.inputs.autobk:
_xas_obj.configuration["autobk"] = self._settings self.setConfiguration(self.inputs.autobk)
_xas_obj.configuration["autobk"] = self.inputs.autobk
self._advancement.reset(max_=_xas_obj.n_spectrum) self._advancement.reset(max_=_xas_obj.n_spectrum)
self._advancement.startProcess() self._advancement.startProcess()
......
...@@ -124,7 +124,11 @@ _USE_MULTIPROCESSING_POOL = False ...@@ -124,7 +124,11 @@ _USE_MULTIPROCESSING_POOL = False
class Larch_mback( class Larch_mback(
Process, name="mback", input_names=["xas_obj"], output_names=["xas_obj"] Process,
name="mback",
input_names=["xas_obj"],
output_names=["xas_obj"],
optional_input_names=["mback"],
): ):
def set_properties(self, properties): def set_properties(self, properties):
if "_larchSettings" in properties: if "_larchSettings" in properties:
...@@ -135,8 +139,10 @@ class Larch_mback( ...@@ -135,8 +139,10 @@ class Larch_mback(
if xas_obj is None: if xas_obj is None:
raise ValueError("xas_obj should be provided") raise ValueError("xas_obj should be provided")
_xas_obj = self.getXasObject(xas_obj=xas_obj) _xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings:
_xas_obj.configuration["mback"] = self._settings if self.inputs.mback:
self.setConfiguration(self.inputs.mback)
_xas_obj.configuration["mback"] = self.inputs.mback
elif "mback" not in _xas_obj.configuration: elif "mback" not in _xas_obj.configuration:
_xas_obj.configuration["mback"] = {} _xas_obj.configuration["mback"] = {}
......
...@@ -133,7 +133,11 @@ _USE_MULTIPROCESSING_POOL = False ...@@ -133,7 +133,11 @@ _USE_MULTIPROCESSING_POOL = False
class Larch_mback_norm( class Larch_mback_norm(
Process, name="mback_norm", input_names=["xas_obj"], output_names=["xas_obj"] Process,
name="mback_norm",
input_names=["xas_obj"],
output_names=["xas_obj"],
optional_input_names=["mback_norm"],
): ):
def set_properties(self, properties): def set_properties(self, properties):
if "_larchSettings" in properties: if "_larchSettings" in properties:
...@@ -144,8 +148,9 @@ class Larch_mback_norm( ...@@ -144,8 +148,9 @@ class Larch_mback_norm(
if xas_obj is None: if xas_obj is None:
raise ValueError("xas_obj should be provided") raise ValueError("xas_obj should be provided")
_xas_obj = self.getXasObject(xas_obj=xas_obj) _xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings: if self.inputs.mback_norm:
_xas_obj.configuration["mback_norm"] = self._settings self.setConfiguration(self.inputs.mback_norm)
_xas_obj.configuration["mback_norm"] = self.inputs.mback_norm
self._advancement.reset(max_=_xas_obj.n_spectrum) self._advancement.reset(max_=_xas_obj.n_spectrum)
self._advancement.startProcess() self._advancement.startProcess()
......
...@@ -129,7 +129,11 @@ _USE_MULTIPROCESSING_POOL = False ...@@ -129,7 +129,11 @@ _USE_MULTIPROCESSING_POOL = False
class Larch_pre_edge( class Larch_pre_edge(
Process, name="pre_edge", input_names=["xas_obj"], output_names=["xas_obj"] Process,
name="pre_edge",
input_names=["xas_obj"],
output_names=["xas_obj"],
optional_input_names=["pre_edge"],
): ):
def set_properties(self, properties): def set_properties(self, properties):
if "_larchSettings" in properties: if "_larchSettings" in properties:
...@@ -141,8 +145,9 @@ class Larch_pre_edge( ...@@ -141,8 +145,9 @@ class Larch_pre_edge(
raise ValueError("xas_obj should be provided") raise ValueError("xas_obj should be provided")
self._xas_obj = self.getXasObject(xas_obj=xas_obj) self._xas_obj = self.getXasObject(xas_obj=xas_obj)
_xas_obj = self._xas_obj _xas_obj = self._xas_obj
if self._settings: if self.inputs.pre_edge:
_xas_obj.configuration["pre_edge"] = self._settings self.setConfiguration(self.inputs.pre_edge)
_xas_obj.configuration["pre_edge"] = self.inputs.pre_edge
self._advancement.reset(max_=_xas_obj.n_spectrum) self._advancement.reset(max_=_xas_obj.n_spectrum)
self._advancement.startProcess() self._advancement.startProcess()
......
...@@ -156,7 +156,11 @@ _USE_MULTIPROCESSING_POOL = False ...@@ -156,7 +156,11 @@ _USE_MULTIPROCESSING_POOL = False
class Larch_xftf( class Larch_xftf(
Process, name="xftf", input_names=["xas_obj"], output_names=["xas_obj"] Process,
name="xftf",
input_names=["xas_obj"],
output_names=["xas_obj"],
optional_input_names=["xftf"],
): ):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
...@@ -173,9 +177,11 @@ class Larch_xftf( ...@@ -173,9 +177,11 @@ class Larch_xftf(
if xas_obj is None: if xas_obj is None:
raise ValueError("xas_obj should be provided") raise ValueError("xas_obj should be provided")
_xas_obj = self.getXasObject(xas_obj=xas_obj) _xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings: if self.inputs.xftf:
_xas_obj.configuration["xftf"] = self._settings self.setConfiguration(self.inputs.xftf)
_xas_obj.configuration["xftf"] = self.inputs.xftf
elif "xftf" not in _xas_obj.configuration: elif "xftf" not in _xas_obj.configuration:
self.setConfiguration({})
_xas_obj.configuration["xftf"] = {} _xas_obj.configuration["xftf"] = {}
self._advancement.reset(max_=_xas_obj.n_spectrum) self._advancement.reset(max_=_xas_obj.n_spectrum)
......
...@@ -144,7 +144,11 @@ _USE_MULTIPROCESSING_POOL = False ...@@ -144,7 +144,11 @@ _USE_MULTIPROCESSING_POOL = False
class PyMca_exafs( class PyMca_exafs(
Process, name="exafs", input_names=["xas_obj"], output_names=["xas_obj"] Process,
name="exafs",
input_names=["xas_obj"],
output_names=["xas_obj"],
optional_input_names=["exafs"],
): ):
"""Process spectra for exafs and get information about the processing """Process spectra for exafs and get information about the processing
advancement""" advancement"""
...@@ -158,8 +162,9 @@ class PyMca_exafs( ...@@ -158,8 +162,9 @@ class PyMca_exafs(
if xas_obj is None: if xas_obj is None:
raise ValueError("xas_obj should be provided") raise ValueError("xas_obj should be provided")
_xas_obj = self.getXasObject(xas_obj=xas_obj) _xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings: if self.inputs.exafs:
_xas_obj.configuration["EXAFS"] = self._settings self.setConfiguration(self.inputs.exafs)
_xas_obj.configuration["EXAFS"] = self.inputs.exafs
self._advancement.reset(max_=_xas_obj.n_spectrum) self._advancement.reset(max_=_xas_obj.n_spectrum)
self._advancement.startProcess() self._advancement.startProcess()
......
...@@ -148,7 +148,13 @@ _USE_MULTIPROCESSING_POOL = False ...@@ -148,7 +148,13 @@ _USE_MULTIPROCESSING_POOL = False
# note: we cannot use multiprocessing pool with pypushflow for now. # note: we cannot use multiprocessing pool with pypushflow for now.
class PyMca_ft(Process, name="ft", input_names=["xas_obj"], output_names=["xas_obj"]): class PyMca_ft(
Process,
name="ft",
input_names=["xas_obj"],
output_names=["xas_obj"],
optional_input_names=["ft"],
):
def set_properties(self, properties): def set_properties(self, properties):
if "_pymcaSettings" in properties: if "_pymcaSettings" in properties:
self._settings = properties["_pymcaSettings"] self._settings = properties["_pymcaSettings"]
...@@ -165,8 +171,10 @@ class PyMca_ft(Process, name="ft", input_names=["xas_obj"], output_names=["xas_o ...@@ -165,8 +171,10 @@ class PyMca_ft(Process, name="ft", input_names=["xas_obj"], output_names=["xas_o
if xas_obj is None: if xas_obj is None:
raise ValueError("xas_obj should be provided") raise ValueError("xas_obj should be provided")
_xas_obj = self.getXasObject(xas_obj=xas_obj) _xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings:
_xas_obj.configuration["FT"] = self._settings if self.inputs.ft:
self.setConfiguration(self.inputs.ft)
_xas_obj.configuration["FT"] = self.inputs.ft
self._advancement.reset(max_=_xas_obj.n_spectrum) self._advancement.reset(max_=_xas_obj.n_spectrum)
self._advancement.startProcess() self._advancement.startProcess()
......
...@@ -137,7 +137,11 @@ _USE_MULTIPROCESSING_POOL = False ...@@ -137,7 +137,11 @@ _USE_MULTIPROCESSING_POOL = False
class PyMca_k_weight( class PyMca_k_weight(
Process, name="k weight", input_names=["xas_obj"], output_names=["xas_obj"] Process,
name="k weight",
input_names=["xas_obj"],
output_names=["xas_obj"],
optional_input_names=["k_weight"],
): ):
def set_properties(self, properties): def set_properties(self, properties):
if "_kWeightSetting" in properties: if "_kWeightSetting" in properties:
...@@ -146,11 +150,6 @@ class PyMca_k_weight( ...@@ -146,11 +150,6 @@ class PyMca_k_weight(
del _properties["_kWeightSetting"] del _properties["_kWeightSetting"]
self.setConfiguration(_properties) self.setConfiguration(_properties)
def _k_weight(self):
if "k_weight" in self._settings:
return self._settings["k_weight"]
return None
def run(self): def run(self):
""" """
...@@ -163,8 +162,10 @@ class PyMca_k_weight( ...@@ -163,8 +162,10 @@ class PyMca_k_weight(
if xas_obj is None: if xas_obj is None:
raise ValueError("xas_obj should be provided") raise ValueError("xas_obj should be provided")
_xas_obj = self.getXasObject(xas_obj=xas_obj) _xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._k_weight() is not None:
_xas_obj.configuration["SET_KWEIGHT"] = self._k_weight() if self.inputs.k_weight:
self.setConfiguration({"k_weight": self.inputs.k_weight})
_xas_obj.configuration["SET_KWEIGHT"] = self.inputs.k_weight
if "SET_KWEIGHT" not in _xas_obj.configuration: if "SET_KWEIGHT" not in _xas_obj.configuration:
_logger.warning( _logger.warning(
......
...@@ -123,7 +123,11 @@ _USE_MULTIPROCESSING_POOL = False ...@@ -123,7 +123,11 @@ _USE_MULTIPROCESSING_POOL = False
class PyMca_normalization( class PyMca_normalization(
Process, name="normalization", input_names=["xas_obj"], output_names=["xas_obj"] Process,
name="normalization",
input_names=["xas_obj"],
output_names=["xas_obj"],
optional_input_names=["normalization"],
): ):
def set_properties(self, properties): def set_properties(self, properties):
if "_pymcaSettings" in properties: if "_pymcaSettings" in properties:
...@@ -147,8 +151,9 @@ class PyMca_normalization( ...@@ -147,8 +151,9 @@ class PyMca_normalization(
_logger.error("Energy not specified, unable to normalize spectra") _logger.error("Energy not specified, unable to normalize spectra")
return return
if self._settings: if self.inputs.normalization:
_xas_obj.configuration["Normalization"] = self._settings self.setConfiguration(self.inputs.normalization)
_xas_obj.configuration["Normalization"] = self.inputs.normalization
self._advancement.reset(max_=_xas_obj.n_spectrum) self._advancement.reset(max_=_xas_obj.n_spectrum)
self._advancement.startProcess() self._advancement.startProcess()
self._pool_process(xas_obj=_xas_obj) self._pool_process(xas_obj=_xas_obj)
......
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2017-2019 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.
#
# ###########################################################################*/
"""some utils function for executing reprocessing"""
__authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "07/18/2019"
import importlib
import logging
from silx.io.utils import h5py_read_dataset
_logger = logging.getLogger(__name__)
def get_process_instance_frm_h5_desc(desc):
"""
:param dict desc: description of the process to instanciate
:return: instance of the process to execute, configured from the description
"""
assert "program" in desc
assert "class_instance" in desc
tmp = h5py_read_dataset(desc["class_instance"]).split(".")
module_name = ".".join(tmp[:-1])
class_name = tmp[-1]
try:
_module = importlib.import_module(module_name)
instance = getattr(_module, class_name)()
except Exception as e:
_logger.warning(
" ".join(("Fail to instanciate", module_name, class_name, "reason is", e))
)
instance = None
else:
if "configuration" in desc:
instance.setConfiguration(desc["configuration"])
return instance
...@@ -62,10 +62,6 @@ class _ParameterWindowContainer(qt.QWidget): ...@@ -62,10 +62,6 @@ class _ParameterWindowContainer(qt.QWidget):
# setup # setup
self._manualUpdatePB.setVisible(False) self._manualUpdatePB.setVisible(False)
# expose API
self.setParameters = self._mainwidget.setParameters
self.getParameters = self._mainwidget.getParameters
# connect signal / slot # connect signal / slot
self._autoCB.toggled.connect(self._manualUpdatePB.setVisible) self._autoCB.toggled.connect(self._manualUpdatePB.setVisible)
self._manualUpdatePB.pressed.connect(self._update) self._manualUpdatePB.pressed.connect(self._update)
...@@ -93,3 +89,9 @@ class _ParameterWindowContainer(qt.QWidget): ...@@ -93,3 +89,9 @@ class _ParameterWindowContainer(qt.QWidget):
def _update(self, *args, **kwargs): def _update(self, *args, **kwargs):
self.sigChanged.emit() self.sigChanged.emit()
def getParameters(self):
return self._mainwidget.getParameters()
def setParameters(self, params):
self._mainwidget.setParameters(params=params)
...@@ -158,7 +158,9 @@ class AutobkOW(_ProcessForOrangeMixIn, OWWidget): ...@@ -158,7 +158,9 @@ class AutobkOW(_ProcessForOrangeMixIn, OWWidget):
allows_cycle = False allows_cycle = False
_larchSettings = Setting(dict()) _larchSettings = Setting(dict())
"""Store the configuration of the PyMca XASClass""" # kept for compatibility
static_input = Setting({"xas_obj": None, "autobk": None})
"""Store the configuration of the larch configuration"""
ewokstaskclass = est.core.process.larch.autobk.Larch_autobk ewokstaskclass = est.core.process.larch.autobk.Larch_autobk
...@@ -182,8 +184,11 @@ class AutobkOW(_ProcessForOrangeMixIn, OWWidget): ...@@ -182,8 +184,11 @@ class AutobkOW(_ProcessForOrangeMixIn, OWWidget):
self._window.xasObjViewer.setWindowTitle("spectra") self._window.xasObjViewer.setWindowTitle("spectra")
# manage settings # manage settings
if self._larchSettings != dict(): larch_settings = self.static_input.get("autobk", None)
self._window._parametersWindow.setParameters(self._larchSettings) if larch_settings is None:
larch_settings = self._larchSettings
if larch_settings != dict():
self._window._parametersWindow.setParameters(larch_settings)
# connect signals / slots # connect signals / slots
self._window._parametersWindow.sigChanged.connect(self._updateProcess) self._window._parametersWindow.sigChanged.connect(self._updateProcess)
...@@ -206,6 +211,10 @@ class AutobkOW(_ProcessForOrangeMixIn, OWWidget): ...@@ -206,6 +211,10 @@ class AutobkOW(_ProcessForOrangeMixIn, OWWidget):
def _update_settings(self): def _update_settings(self):
self._larchSettings = self._window._parametersWindow.getParameters() self._larchSettings = self._window._parametersWindow.getParameters()
self.static_input = {
"autobk": self._window._parametersWindow.getParameters(),
"xas_obj": None,
}
@Inputs.data_table @Inputs.data_table
def processFrmDataTable(self, data_table): def processFrmDataTable(self, data_table):
......
...@@ -134,6 +134,8 @@ class MbackOW(_ProcessForOrangeMixIn, OWWidget): ...@@ -134,6 +134,8 @@ class MbackOW(_ProcessForOrangeMixIn, OWWidget):
allows_cycle = False allows_cycle = False
_larchSettings = Setting(dict()) _larchSettings = Setting(dict())
# kept for compatibility
static_input = Setting({"mback": None})
"""Store the configuration of the larch configuration""" """Store the configuration of the larch configuration"""
ewokstaskclass = est.core.process.larch.mback.Larch_mback ewokstaskclass = est.core.process.larch.mback.Larch_mback
...@@ -158,8 +160,11 @@ class MbackOW(_ProcessForOrangeMixIn, OWWidget): ...@@ -158,8 +160,11 @@ class MbackOW(_ProcessForOrangeMixIn, OWWidget):
self._window.xasObjViewer.setWindowTitle("spectra") self._window.xasObjViewer.setWindowTitle("spectra")
# manage settings # manage settings
if self._larchSettings != dict(): larch_settings = self.static_input.get("mback", None)
self._window._parametersWindow.setParameters(self._larchSettings) if larch_settings is None:
larch_settings = self._larchSettings
if larch_settings != dict():
self._window._parametersWindow.setParameters(larch_settings)
# connect signals / slots # connect signals / slots
self._window._parametersWindow.sigChanged.connect(self._updateProcess) self._window._parametersWindow.sigChanged.connect(self._updateProcess)
...@@ -180,6 +185,10 @@ class MbackOW(_ProcessForOrangeMixIn, OWWidget): ...@@ -180,6 +185,10 @@ class MbackOW(_ProcessForOrangeMixIn, OWWidget):
def _update_settings(self): def _update_settings(self):
self._larchSettings = self._window._parametersWindow.getParameters() self._larchSettings = self._window._parametersWindow.getParameters()
self.static_input = {
"mback": self._window._parametersWindow.getParameters(),
"xas_obj": None,
}
@Inputs.data_table @Inputs.data_table
def processFrmDataTable(self, data_table): def processFrmDataTable(self, data_table):
......
...@@ -138,6 +138,8 @@ class Mback_normOW( ...@@ -138,6 +138,8 @@ class Mback_normOW(
ewokstaskclass = est.core.process.larch.mback_norm.Larch_mback_norm ewokstaskclass = est.core.process.larch.mback_norm.Larch_mback_norm
_larchSettings = Setting(dict()) _larchSettings = Setting(dict())
"""Kept for compatiblity"""
static_input = Setting({"mback_norm": None})
"""Store the configuration of the larch configuration""" """Store the configuration of the larch configuration"""
class Inputs: class Inputs:
...@@ -160,8 +162,11 @@ class Mback_normOW( ...@@ -160,8 +162,11 @@ class Mback_normOW(
self._window.xasObjViewer.setWindowTitle("spectra") self._window.xasObjViewer.setWindowTitle("spectra")
# manage settings # manage settings
if self._larchSettings != dict(): larch_settings = self.static_input.get("mback_norm", None)
self._window._parametersWindow.setParameters(self._larchSettings) if larch_settings is None:
larch_settings = self._larchSettings
if larch_settings != dict():
self._window._parametersWindow.setParameters(larch_settings)
# connect signals / slots # connect signals / slots
self._window._parametersWindow.sigChanged.connect(self._updateProcess) self._window._parametersWindow.sigChanged.connect(self._updateProcess)
...@@ -182,6 +187,10 @@ class Mback_normOW( ...@@ -182,6 +187,10 @@ class Mback_normOW(
def _update_settings(self): def _update_settings(self):
self._larchSettings = self._window._parametersWindow.getParameters() self._larchSettings = self._window._parametersWindow.getParameters()
self.static_input = {
"mback_norm": self._window._parametersWindow.getParameters(),
"xas_obj": None,
}
@Inputs.data_table @Inputs.data_table
def processFrmDataTable(self, data_table): def processFrmDataTable(self, data_table):
......
...@@ -157,6 +157,8 @@ class PreEdgeOW( ...@@ -157,6 +157,8 @@ class PreEdgeOW(
ewokstaskclass = est.core.process.larch.pre_edge.Larch_pre_edge ewokstaskclass = est.core.process.larch.pre_edge.Larch_pre_edge
_larchSettings = Setting(dict()) _larchSettings = Setting(dict())
# kept for compatibility
static_input = Setting({"pre_edge": None})
"""Store the configuration of the larch configuration""" """Store the configuration of the larch configuration"""
class Inputs: class Inputs:
...@@ -179,8 +181,11 @@ class PreEdgeOW( ...@@ -179,8 +181,11 @@ class PreEdgeOW(
self._window.xasObjViewer.setWindowTitle("spectra") self._window.xasObjViewer.setWindowTitle("spectra")
# manage settings # manage settings
if self._larchSettings != dict(): larch_settings = self.static_input.get("pre_edge", None)