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 !46
parents b78a4c35 b84008eb
Pipeline #55864 failed with stages
in 5 minutes and 56 seconds
......@@ -133,7 +133,11 @@ _USE_MULTIPROCESSING_POOL = False
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):
if "_larchSettings" in properties:
......@@ -144,8 +148,9 @@ class Larch_autobk(
if xas_obj is None:
raise ValueError("xas_obj should be provided")
_xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings:
_xas_obj.configuration["autobk"] = self._settings
if self.inputs.autobk:
self.setConfiguration(self.inputs.autobk)
_xas_obj.configuration["autobk"] = self.inputs.autobk
self._advancement.reset(max_=_xas_obj.n_spectrum)
self._advancement.startProcess()
......
......@@ -124,7 +124,11 @@ _USE_MULTIPROCESSING_POOL = False
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):
if "_larchSettings" in properties:
......@@ -135,8 +139,10 @@ class Larch_mback(
if xas_obj is None:
raise ValueError("xas_obj should be provided")
_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:
_xas_obj.configuration["mback"] = {}
......
......@@ -133,7 +133,11 @@ _USE_MULTIPROCESSING_POOL = False
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):
if "_larchSettings" in properties:
......@@ -144,8 +148,9 @@ class Larch_mback_norm(
if xas_obj is None:
raise ValueError("xas_obj should be provided")
_xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings:
_xas_obj.configuration["mback_norm"] = self._settings
if self.inputs.mback_norm:
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.startProcess()
......
......@@ -129,7 +129,11 @@ _USE_MULTIPROCESSING_POOL = False
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):
if "_larchSettings" in properties:
......@@ -141,8 +145,9 @@ class Larch_pre_edge(
raise ValueError("xas_obj should be provided")
self._xas_obj = self.getXasObject(xas_obj=xas_obj)
_xas_obj = self._xas_obj
if self._settings:
_xas_obj.configuration["pre_edge"] = self._settings
if self.inputs.pre_edge:
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.startProcess()
......
......@@ -156,7 +156,11 @@ _USE_MULTIPROCESSING_POOL = False
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):
super().__init__(**kwargs)
......@@ -173,9 +177,11 @@ class Larch_xftf(
if xas_obj is None:
raise ValueError("xas_obj should be provided")
_xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings:
_xas_obj.configuration["xftf"] = self._settings
if self.inputs.xftf:
self.setConfiguration(self.inputs.xftf)
_xas_obj.configuration["xftf"] = self.inputs.xftf
elif "xftf" not in _xas_obj.configuration:
self.setConfiguration({})
_xas_obj.configuration["xftf"] = {}
self._advancement.reset(max_=_xas_obj.n_spectrum)
......
......@@ -144,7 +144,11 @@ _USE_MULTIPROCESSING_POOL = False
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
advancement"""
......@@ -158,8 +162,9 @@ class PyMca_exafs(
if xas_obj is None:
raise ValueError("xas_obj should be provided")
_xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings:
_xas_obj.configuration["EXAFS"] = self._settings
if self.inputs.exafs:
self.setConfiguration(self.inputs.exafs)
_xas_obj.configuration["EXAFS"] = self.inputs.exafs
self._advancement.reset(max_=_xas_obj.n_spectrum)
self._advancement.startProcess()
......
......@@ -148,7 +148,13 @@ _USE_MULTIPROCESSING_POOL = False
# 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):
if "_pymcaSettings" in properties:
self._settings = properties["_pymcaSettings"]
......@@ -165,8 +171,10 @@ class PyMca_ft(Process, name="ft", input_names=["xas_obj"], output_names=["xas_o
if xas_obj is None:
raise ValueError("xas_obj should be provided")
_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.startProcess()
......
......@@ -137,7 +137,11 @@ _USE_MULTIPROCESSING_POOL = False
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):
if "_kWeightSetting" in properties:
......@@ -146,11 +150,6 @@ class PyMca_k_weight(
del _properties["_kWeightSetting"]
self.setConfiguration(_properties)
def _k_weight(self):
if "k_weight" in self._settings:
return self._settings["k_weight"]
return None
def run(self):
"""
......@@ -163,8 +162,10 @@ class PyMca_k_weight(
if xas_obj is None:
raise ValueError("xas_obj should be provided")
_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:
_logger.warning(
......
......@@ -123,7 +123,11 @@ _USE_MULTIPROCESSING_POOL = False
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):
if "_pymcaSettings" in properties:
......@@ -147,8 +151,9 @@ class PyMca_normalization(
_logger.error("Energy not specified, unable to normalize spectra")
return
if self._settings:
_xas_obj.configuration["Normalization"] = self._settings
if self.inputs.normalization:
self.setConfiguration(self.inputs.normalization)
_xas_obj.configuration["Normalization"] = self.inputs.normalization
self._advancement.reset(max_=_xas_obj.n_spectrum)
self._advancement.startProcess()
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):
# setup
self._manualUpdatePB.setVisible(False)
# expose API
self.setParameters = self._mainwidget.setParameters
self.getParameters = self._mainwidget.getParameters
# connect signal / slot
self._autoCB.toggled.connect(self._manualUpdatePB.setVisible)
self._manualUpdatePB.pressed.connect(self._update)
......@@ -93,3 +89,9 @@ class _ParameterWindowContainer(qt.QWidget):
def _update(self, *args, **kwargs):
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):
allows_cycle = False
_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
......@@ -182,8 +184,11 @@ class AutobkOW(_ProcessForOrangeMixIn, OWWidget):
self._window.xasObjViewer.setWindowTitle("spectra")
# manage settings
if self._larchSettings != dict():
self._window._parametersWindow.setParameters(self._larchSettings)
larch_settings = self.static_input.get("autobk", None)
if larch_settings is None:
larch_settings = self._larchSettings
if larch_settings != dict():
self._window._parametersWindow.setParameters(larch_settings)
# connect signals / slots
self._window._parametersWindow.sigChanged.connect(self._updateProcess)
......@@ -206,6 +211,10 @@ class AutobkOW(_ProcessForOrangeMixIn, OWWidget):
def _update_settings(self):
self._larchSettings = self._window._parametersWindow.getParameters()
self.static_input = {
"autobk": self._window._parametersWindow.getParameters(),
"xas_obj": None,
}
@Inputs.data_table
def processFrmDataTable(self, data_table):
......
......@@ -134,6 +134,8 @@ class MbackOW(_ProcessForOrangeMixIn, OWWidget):
allows_cycle = False
_larchSettings = Setting(dict())
# kept for compatibility
static_input = Setting({"mback": None})
"""Store the configuration of the larch configuration"""
ewokstaskclass = est.core.process.larch.mback.Larch_mback
......@@ -158,8 +160,11 @@ class MbackOW(_ProcessForOrangeMixIn, OWWidget):
self._window.xasObjViewer.setWindowTitle("spectra")
# manage settings
if self._larchSettings != dict():
self._window._parametersWindow.setParameters(self._larchSettings)
larch_settings = self.static_input.get("mback", None)
if larch_settings is None:
larch_settings = self._larchSettings
if larch_settings != dict():
self._window._parametersWindow.setParameters(larch_settings)
# connect signals / slots
self._window._parametersWindow.sigChanged.connect(self._updateProcess)
......@@ -180,6 +185,10 @@ class MbackOW(_ProcessForOrangeMixIn, OWWidget):
def _update_settings(self):
self._larchSettings = self._window._parametersWindow.getParameters()
self.static_input = {
"mback": self._window._parametersWindow.getParameters(),
"xas_obj": None,
}
@Inputs.data_table
def processFrmDataTable(self, data_table):
......
......@@ -138,6 +138,8 @@ class Mback_normOW(
ewokstaskclass = est.core.process.larch.mback_norm.Larch_mback_norm
_larchSettings = Setting(dict())
"""Kept for compatiblity"""
static_input = Setting({"mback_norm": None})
"""Store the configuration of the larch configuration"""
class Inputs:
......@@ -160,8 +162,11 @@ class Mback_normOW(
self._window.xasObjViewer.setWindowTitle("spectra")
# manage settings
if self._larchSettings != dict():
self._window._parametersWindow.setParameters(self._larchSettings)
larch_settings = self.static_input.get("mback_norm", None)
if larch_settings is None:
larch_settings = self._larchSettings
if larch_settings != dict():
self._window._parametersWindow.setParameters(larch_settings)
# connect signals / slots
self._window._parametersWindow.sigChanged.connect(self._updateProcess)
......@@ -182,6 +187,10 @@ class Mback_normOW(
def _update_settings(self):
self._larchSettings = self._window._parametersWindow.getParameters()
self.static_input = {
"mback_norm": self._window._parametersWindow.getParameters(),
"xas_obj": None,
}
@Inputs.data_table
def processFrmDataTable(self, data_table):
......
......@@ -157,6 +157,8 @@ class PreEdgeOW(
ewokstaskclass = est.core.process.larch.pre_edge.Larch_pre_edge
_larchSettings = Setting(dict())
# kept for compatibility
static_input = Setting({"pre_edge": None})
"""Store the configuration of the larch configuration"""
class Inputs:
......@@ -179,8 +181,11 @@ class PreEdgeOW(
self._window.xasObjViewer.setWindowTitle("spectra")
# manage settings
if self._larchSettings != dict():
self._window._parametersWindow.setParameters(self._larchSettings)
larch_settings = self.static_input.get("pre_edge", None)
if larch_settings is None:
larch_settings = self._larchSettings
if larch_settings != dict():
self._window._parametersWindow.setParameters(larch_settings)
# connect signals / slots
self._window._parametersWindow.sigChanged.connect(self._updateProcess)
......@@ -201,6 +206,10 @@ class PreEdgeOW(
def _update_settings(self):
self._larchSettings = self._window._parametersWindow.getParameters()
self.static_input = {
"pre_edge": self._window._parametersWindow.getParameters(),
"xas_obj": None,
}
@Inputs.data_table
def processFrmDataTable(self, data_table):
......
......@@ -174,6 +174,8 @@ class XFTFOW(
ewokstaskclass = est.core.process.larch.xftf.Larch_xftf
_larchSettings = Setting(dict())
# kept for compatibility
static_input = Setting({"xftf": None, "xas_obj": None})
"""Store the configuration of the larch configuration"""
class Inputs:
......@@ -196,8 +198,11 @@ class XFTFOW(
self._window.xasObjViewer.setWindowTitle("spectra")
# manage settings
if self._larchSettings != dict():
self._window._parametersWindow.setParameters(self._larchSettings)
larch_settings = self.static_input.get("xftf", None)
if larch_settings is None:
larch_settings = self._larchSettings
if larch_settings != dict():
self._window._parametersWindow.setParameters(larch_settings)
# connect signals / slots
self._window._parametersWindow.sigChanged.connect(self._updateProcess)
......@@ -219,6 +224,10 @@ class XFTFOW(
def _update_settings(self):
self._larchSettings = self._window._parametersWindow.getParameters()
self.static_input = {
"xftf": self._window._parametersWindow.getParameters(),
"xas_obj": None,
}
@Inputs.data_table
def processFrmDataTable(self, data_table):
......
......@@ -138,6 +138,8 @@ class ExafsOW(
ewokstaskclass = est.core.process.pymca.exafs.PyMca_exafs
_larchSettings = Setting(dict())
# kept for compatibility
static_input = Setting({"xas_obj": None, "exafs": None})
"""Store the configuration of the PyMca XASClass"""
class Inputs:
......@@ -164,8 +166,11 @@ class ExafsOW(
)
# manage settings
if self._larchSettings != dict():
self._window._pymcaWindow.setParameters(self._larchSettings)
pymca_settings = self.static_input.get("exafs", None)
if pymca_settings is None:
pymca_settings = self._larchSettings
if pymca_settings != dict():
self._window._pymcaWindow.setParameters(pymca_settings)
# signal / slot connection
self._window._pymcaWindow.sigChanged.connect(self._updateProcess)
......@@ -179,6 +184,10 @@ class ExafsOW(
def _update_settings(self):
self._larchSettings = self._window._pymcaWindow.getParameters()
self.static_input = {
"xas_obj": None,
"exafs": self._window._pymcaWindow.getParameters(),
}
@Inputs.data_table
def processFrmDataTable(self, data_table):
......
......@@ -157,6 +157,8 @@ class FTOW(
ewokstaskclass = est.core.process.pymca.ft.PyMca_ft
_pymcaSettings = Setting(dict())
# kept for compatibility
static_input = dict({"ft": None, "xas_obj": None})
"""Store the configuration of the PyMca XASClass"""
class Inputs:
......@@ -181,8 +183,11 @@ class FTOW(
self._progress = gui.ProgressBar(self, 100)
# manage settings
if self._pymcaSettings != dict():
self._window._pymcaWindow.setParameters(self._pymcaSettings)
pymca_settings = self.static_input.get("ft", None)
if pymca_settings is None:
pymca_settings = self._pymcaSettings
if pymca_settings != dict():
self._window._pymcaWindow.setParameters(pymca_settings)
# signal / slot connection
# connect signals / slots
......@@ -235,6 +240,10 @@ class FTOW(
def _update_settings(self):
self._pymcaSettings = self._window._pymcaWindow.getParameters()
self.static_input = {
"xas_obj": None,
"ft": self._window._pymcaWindow.getParameters(),
}
def _setProgressValue(self, value):
self._progress.widget.progressBarSet(value)
......
......@@ -87,6 +87,8 @@ class KWeightOW(
ewokstaskclass = est.core.process.pymca.k_weight.PyMca_k_weight
_kWeightSetting = Setting(int(3))
# kept for compatibility
static_input = Setting({"xas_obj": None, "k_weight": 3})
"""Store the configuration of the PyMca XASClass"""
class Inputs:
......@@ -111,8 +113,11 @@ class KWeightOW(
self._progress = gui.ProgressBar(self, 100)
# manage settings
if self._kWeightSetting != 3:
self._window._k_spin_box.setValue(self._kWeightSetting)
k_weight = self.static_input.get("k_weight")
if k_weight == 3:
k_weight = self._kWeightSetting
if k_weight != 3:
self._window._k_spin_box.setValue(k_weight)
# signal / slot connection
self._window._k_spin_box.valueChanged.connect(self._updateProcess)
......@@ -163,6 +168,10 @@ class KWeightOW(
def _update_settings(self):
self._kWeightSetting = self._window._k_spin_box.value()
self.static_input = {
"xas_obj": None,
"k_weight": self._window._k_spin_box.value(),
}
def _setProgressValue(self, value):