Commit f6e592fe authored by payno's avatar payno
Browse files

[core][process] adapt processes to ewoks API:

- rename `process` to `run` and
- replace output.var_namevar.value by outputs.var_name and input.var_namevar.value by inputs.var_name
- _INPUT_NAMES and _OUTPUT_NAMES where missing (larch processes...)
parent 24bbd2be
......@@ -58,13 +58,9 @@ class ROI1D:
class EnergyROIProcess(Process):
inputs = [
_input_desc(name="xas_obj", type=XASObject, handler="process", doc=""),
]
_INPUT_NAMES = set(["xas_obj"])
outputs = [
_output_desc(name="xas_obj", type=XASObject, doc=""),
]
_OUTPUT_NAMES = set(["xas_obj"])
def __init__(self, varinfo=None, **inputs):
Process.__init__(self, name="energy roi", varinfo=varinfo, **inputs)
......@@ -104,7 +100,7 @@ class EnergyROIProcess(Process):
# print(xas_obj.__dict__)
return xas_obj
def process(self, xas_obj: Union[dict, XASObject]):
def run(self, xas_obj: Union[dict, XASObject] = None):
"""
:param xas_obj: object containing the configuration and spectra to process
......@@ -112,7 +108,8 @@ class EnergyROIProcess(Process):
:return: spectra dict
:rtype: :class:`.XASObject`
"""
assert xas_obj is not None
if xas_obj is None:
xas_obj = self.inputs.xas_obj
_xas_obj = self.getXasObject(xas_obj=xas_obj)
# existing roi is priority. This is the case if called from pushworkflow
......@@ -121,6 +118,7 @@ class EnergyROIProcess(Process):
xas_obj = self._apply_roi(xas_obj=_xas_obj, roi=self._roi)
self.register_process(_xas_obj, data_keys=("Mu", "energy"))
self.outputs.xas_obj = _xas_obj.to_dict()
return xas_obj
def definition(self):
......@@ -135,4 +133,4 @@ class EnergyROIProcess(Process):
def program_name():
return "energy-roi"
__call__ = process
__call__ = run
......@@ -44,7 +44,7 @@ class DumpXasObject(Process):
def __init__(self, varinfo=None, **inputs):
super().__init__(name="dump xas object", varinfo=varinfo, **inputs)
self._output_file = inputs.get("output_file", None)
self._output_file = varinfo.get("output_file", None)
@property
def output_file(self):
......@@ -66,9 +66,9 @@ class DumpXasObject(Process):
"""definition of the process"""
return "write xas object to a file"
def process(self, xas_object=None):
def run(self, xas_object=None):
if xas_object is None:
xas_object = self.input.xas_obj.value
xas_object = self.inputs.xas_obj
if isinstance(xas_object, dict):
xas_object = XASObject.from_dict(xas_object)
if not isinstance(xas_object, XASObject):
......@@ -80,7 +80,7 @@ class DumpXasObject(Process):
raise ValueError("output file not provided")
else:
xas_object.dump(self.output_file)
self.output.result.value = self.output_file
self.outputs.result = self.output_file
def set_properties(self, properties):
self.setConfiguration(properties)
......@@ -99,7 +99,7 @@ class DumpXasObject(Process):
elif "_output_file_setting" in self._settings:
self.output_file = self._settings["_output_file_setting"]
__call__ = process
__call__ = run
class ReadXasObject(Process):
......@@ -108,13 +108,15 @@ class ReadXasObject(Process):
def __init__(self, varinfo=None, **inputs):
super().__init__(name="read xas", varinfo=varinfo, **inputs)
self.setConfiguration(inputs)
if "input_information" not in varinfo:
raise ValueError("Input information should be provided")
self.setConfiguration(varinfo["input_information"])
def process(self):
def run(self):
from est.core.io import XASReader
config = self.getConfiguration()
input_information = InputInformation.from_dict(config)
xas_obj = XASReader.read_frm_url(input_information)
self.output.xas_obj.value = xas_obj.to_dict()
self.outputs.xas_obj = xas_obj.to_dict()
return xas_obj
......@@ -147,9 +147,9 @@ class Larch_autobk(Process):
if "_larchSettings" in properties:
self._settings = properties["_larchSettings"]
def process(self, xas_obj=None):
def run(self, xas_obj=None):
if xas_obj is None:
xas_obj = self.input.xas_obj.value
xas_obj = self.inputs.xas_obj
_xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings:
_xas_obj.configuration["autobk"] = self._settings
......@@ -159,7 +159,7 @@ class Larch_autobk(Process):
self._pool_process(xas_obj=_xas_obj)
self._advancement.endProcess()
self.register_process(_xas_obj, data_keys=(_NexusDatasetDef("bkg"),))
self.output.xas_obj.value = _xas_obj.to_dict()
self.outputs.xas_obj = _xas_obj.to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
......@@ -209,4 +209,4 @@ class Larch_autobk(Process):
def program_name():
return "larch_autobk"
__call__ = process
__call__ = run
......@@ -138,9 +138,9 @@ class Larch_mback(Process):
if "_larchSettings" in properties:
self._settings = properties["_larchSettings"]
def process(self, xas_obj=None):
def run(self, xas_obj=None):
if xas_obj is None:
xas_obj = self.input.xas_obj.value
xas_obj = self.inputs.xas_obj
_xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings:
_xas_obj.configuration["mback"] = self._settings
......@@ -158,6 +158,7 @@ class Larch_mback(Process):
_NexusDatasetDef("f2"),
),
)
self.outputs.xas_obj = _xas_obj.to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
......@@ -207,4 +208,4 @@ class Larch_mback(Process):
def program_name():
return "larch_mback"
__call__ = process
__call__ = run
......@@ -136,13 +136,9 @@ _USE_MULTIPROCESSING_POOL = False
class Larch_mback_norm(Process):
inputs = [
_input_desc(name="xas_obj", type=XASObject, handler="process", doc=""),
]
_INPUT_NAMES = set(["xas_obj"])
outputs = [
_output_desc(name="xas_obj", type=XASObject, doc=""),
]
_OUTPUT_NAMES = set(["xas_obj"])
def __init__(self, varinfo=None, **inputs):
Process.__init__(self, name="mback_norm", varinfo=varinfo, **inputs)
......@@ -151,7 +147,9 @@ class Larch_mback_norm(Process):
if "_larchSettings" in properties:
self._settings = properties["_larchSettings"]
def process(self, xas_obj):
def runprocess(self, xas_obj):
if xas_obj is None:
xas_obj = self.inputs.xas_obj
_xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings:
_xas_obj.configuration["mback_norm"] = self._settings
......@@ -167,6 +165,7 @@ class Larch_mback_norm(Process):
if _xas_obj.n_spectrum > 0 and hasattr(_xas_obj.spectra[0], "edge_step"):
data_keys += ["norm"]
self.register_process(_xas_obj, data_keys=data_keys)
self.outputs.xas_obj = _xas_obj.to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
......@@ -216,4 +215,4 @@ class Larch_mback_norm(Process):
def program_name():
return "larch_mback_norm"
__call__ = process
__call__ = run
......@@ -143,11 +143,10 @@ class Larch_pre_edge(Process):
if "_larchSettings" in properties:
self._settings = properties["_larchSettings"]
def process(self, xas_obj=None):
def run(self, xas_obj=None):
if xas_obj is None:
xas_obj = self.input.xas_obj.value
xas_obj = self.inputs.xas_obj
self._xas_obj = self.getXasObject(xas_obj=xas_obj)
assert isinstance(self._xas_obj, XASObject)
_xas_obj = self._xas_obj
if self._settings:
_xas_obj.configuration["pre_edge"] = self._settings
......@@ -216,7 +215,7 @@ class Larch_pre_edge(Process):
),
),
)
self.output.xas_obj.value = _xas_obj.to_dict()
self.outputs.xas_obj = _xas_obj.to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
......@@ -266,4 +265,4 @@ class Larch_pre_edge(Process):
def program_name():
return "larch_pre_edge"
__call__ = process
__call__ = run
......@@ -173,7 +173,7 @@ class Larch_xftf(Process):
if "plot_settings" in properties:
self._plot_settings = properties["plot_settings"]
def process(self, xas_obj=None):
def run(self, xas_obj=None):
if xas_obj is None:
xas_obj = self.input.xas_obj.value
_xas_obj = self.getXasObject(xas_obj=xas_obj)
......@@ -297,4 +297,4 @@ class Larch_xftf(Process):
def program_name():
return "larch_xftf"
__call__ = process
__call__ = run
......@@ -151,13 +151,9 @@ def xas_noise(xas_obj):
class NoiseProcess(Process):
inputs = [
_input_desc(name="xas_obj", type=XASObject, handler="process", doc=""),
]
_INPUT_NAMES = set(["xas_obj"])
outputs = [
_output_desc(name="xas_obj", type=XASObject, doc=""),
]
_OUTPUT_NAMES = set(["xas_obj"])
def __init__(self, varinfo=None, **inputs):
Process.__init__(self, name="noise", varinfo=varinfo, **inputs)
......@@ -173,7 +169,7 @@ class NoiseProcess(Process):
if "polynomial_order" in properties:
self._polynomial_order = properties["polynomial_order"]
def process(self, xas_obj: Union[dict, XASObject]):
def run(self, xas_obj: Union[dict, XASObject] = None):
"""
:param xas_obj: object containing the configuration and spectra to process
......@@ -181,7 +177,8 @@ class NoiseProcess(Process):
:return: spectra dict
:rtype: :class:`.XASObject`
"""
assert xas_obj is not None
if xas_obj is None:
xas_obj = self.inputs.xas_obj
_xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings:
......@@ -209,6 +206,7 @@ class NoiseProcess(Process):
),
),
)
self.outputs.xas_obj = _xas_obj.to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
......@@ -256,4 +254,4 @@ class NoiseProcess(Process):
def program_name():
return "noise_savgol"
__call__ = process
__call__ = run
......@@ -138,7 +138,7 @@ def pymca_exafs(xas_obj):
:rtype: XASObject
"""
exafs_obj = PyMca_exafs()
return exafs_obj.process(xas_obj=xas_obj)
return exafs_obj.run(xas_obj=xas_obj)
_USE_MULTIPROCESSING_POOL = False
......@@ -160,9 +160,9 @@ class PyMca_exafs(Process):
if "_pymcaSettings" in properties:
self.setConfiguration(properties["_pymcaSettings"])
def process(self, xas_obj=None):
def run(self, xas_obj=None):
if xas_obj is None:
xas_obj = self.input.xas_obj.value
xas_obj = self.inputs.xas_obj
_xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings:
_xas_obj.configuration["EXAFS"] = self._settings
......@@ -178,7 +178,7 @@ class PyMca_exafs(Process):
_NexusDatasetDef("EXAFSSignal"),
),
)
self.output.xas_obj.value = _xas_obj.to_dict()
self.outputs.xas_obj = _xas_obj.to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
......@@ -230,7 +230,7 @@ class PyMca_exafs(Process):
def program_name():
return "pymca_exafs"
__call__ = process
__call__ = run
if __name__ == "__main__":
......
......@@ -163,7 +163,7 @@ class PyMca_ft(Process):
if "_pymcaSettings" in properties:
self._settings = properties["_pymcaSettings"]
def process(self, xas_obj=None):
def run(self, xas_obj=None):
"""
:param xas_obj: object containing the configuration and spectra to process
......@@ -172,7 +172,7 @@ class PyMca_ft(Process):
:rtype: dict
"""
if xas_obj is None:
xas_obj = self.input.xas_obj.value
xas_obj = self.inputs.xas_obj
_xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings:
_xas_obj.configuration["FT"] = self._settings
......@@ -192,7 +192,7 @@ class PyMca_ft(Process):
_NexusDatasetDef("ft.imaginary"),
),
)
self.output.xas_obj.value = _xas_obj.to_dict()
self.outputs.xas_obj = _xas_obj.to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
......@@ -242,7 +242,7 @@ class PyMca_ft(Process):
def program_name():
return "pymca_ft"
__call__ = process
__call__ = run
if __name__ == "__main__":
......
......@@ -32,8 +32,6 @@ import logging
import multiprocessing
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass, e2k
from est.core.process.process import _input_desc
from est.core.process.process import _output_desc
from est.core.process.process import Process
from est.core.process.pymca.exafs import process_spectr_exafs
from est.core.types import XASObject, Spectrum
......@@ -132,7 +130,7 @@ def pymca_k_weight(xas_obj):
:rtype: :class:`.XASObject`
"""
k_weight_obj = PyMca_k_weight()
return k_weight_obj.process(xas_obj=xas_obj)
return k_weight_obj.run(xas_obj=xas_obj)
_USE_MULTIPROCESSING_POOL = False
......@@ -160,7 +158,7 @@ class PyMca_k_weight(Process):
return self._settings["k_weight"]
return None
def process(self, xas_obj=None):
def run(self, xas_obj=None):
"""
:param xas_obj: object containing the configuration and spectra to process
......@@ -169,7 +167,7 @@ class PyMca_k_weight(Process):
:rtype: :class:`.XASObject`
"""
if xas_obj is None:
xas_obj = self.input.xas_obj.value
xas_obj = self.inputs.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()
......@@ -199,7 +197,7 @@ class PyMca_k_weight(Process):
self._pool_process(xas_obj=_xas_obj)
self._advancement.endProcess()
self.register_process(xas_obj=_xas_obj, data_keys=tuple())
self.output.xas_obj.value = _xas_obj.to_dict()
self.outputs.xas_obj = _xas_obj.to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
......@@ -237,7 +235,7 @@ class PyMca_k_weight(Process):
def program_name():
return "pymca_k_weight"
__call__ = process
__call__ = run
if __name__ == "__main__":
......
......@@ -117,7 +117,7 @@ def pymca_normalization(xas_obj):
:rtype: dict
"""
normalization_obj = PyMca_normalization()
return normalization_obj.process(xas_obj=xas_obj)
return normalization_obj.run(xas_obj=xas_obj)
_USE_MULTIPROCESSING_POOL = False
......@@ -138,7 +138,7 @@ class PyMca_normalization(Process):
if "_pymcaSettings" in properties:
self._settings = properties["_pymcaSettings"]
def process(self, xas_obj=None):
def run(self, xas_obj=None):
"""
:param xas_obj: object containing the configuration and spectra to process
......@@ -148,7 +148,7 @@ class PyMca_normalization(Process):
:rtype: :class:`.XASObject`
"""
if xas_obj is None:
xas_obj = self.input.xas_obj.value
xas_obj = self.inputs.xas_obj
_xas_obj = self.getXasObject(xas_obj)
if _xas_obj.energy is None:
......@@ -170,7 +170,7 @@ class PyMca_normalization(Process):
_NexusDatasetDef("NormalizedSignal"),
),
)
self.output.xas_obj.value = _xas_obj.to_dict()
self.outputs.xas_obj = _xas_obj.to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
......@@ -221,28 +221,4 @@ class PyMca_normalization(Process):
def program_name():
return "pymca_normalization"
__call__ = process
if __name__ == "__main__":
import sys
import yaml
import os
xas_object_yaml_file = sys.argv[1]
working_dir = sys.argv[2]
_logger.debug("Load xas object from {}".format(xas_object_yaml_file))
with open(xas_object_yaml_file, "r") as file:
ddict = yaml.load(file)["input_data"]
xas_object = XASObject.from_dict(ddict)
res_xas_object = pymca_normalization(xas_obj=xas_object)
res_xas_object._create_saving_pt()
# dump resulting object in input file
with open(xas_object_yaml_file, "w") as file:
yaml.dump({"input_data": res_xas_object.to_dict()}, file)
output_dest = os.path.join(os.getcwd(), "output_normalization.yaml")
# dump resulting object into output_normalization file
with open(output_dest, "w") as file:
yaml.dump({"input_data": res_xas_object.to_dict()}, file)
__call__ = run
......@@ -91,13 +91,9 @@ class _ROI(object):
class ROIProcess(Process):
inputs = [
_input_desc(name="xas_obj", type=XASObject, handler="process", doc=""),
]
_INPUT_NAMES = set(["xas_obj"])
outputs = [
_output_desc(name="xas_obj", type=XASObject, doc=""),
]
_OUTPUT_NAMES = set(["xas_obj"])
def __init__(self, varinfo=None, **inputs):
Process.__init__(self, name="roi", varinfo=varinfo, **inputs)
......@@ -178,7 +174,7 @@ class ROIProcess(Process):
xas_obj.spectra.reshape((roi.size[1], roi.size[0]))
return xas_obj
def process(self, xas_obj: Union[dict, XASObject]):
def run(self, xas_obj: Union[dict, XASObject] = None):
"""
:param xas_obj: object containing the configuration and spectra to process
......@@ -186,22 +182,23 @@ class ROIProcess(Process):
:return: spectra dict
:rtype: :class:`.XASObject`
"""
assert xas_obj is not None
if xas_obj is None:
xas_obj = self.inputs.xas_obj
_xas_obj = self.getXasObject(xas_obj=xas_obj)
# existing roi is priority. This is the case if called from pushworkflow
# for example.
if self._roi is not None:
return self._apply_roi(xas_obj=_xas_obj, roi=self._roi)
_xas_obj = self._apply_roi(xas_obj=_xas_obj, roi=self._roi)
elif "roi" in _xas_obj.configuration:
roi_dict = _xas_obj.configuration["roi"]
origin, size = roi_dict["origin"], roi_dict["size"]
return self._apply_roi(xas_obj=_xas_obj, roi=_ROI(origin, size))
else:
return _xas_obj
_xas_obj = self._apply_roi(xas_obj=_xas_obj, roi=_ROI(origin, size))
self.outputs.xas_obj = _xas_obj.to_dict()
return _xas_obj
@staticmethod
def program_name():
return "roi"
__call__ = process
__call__ = run
......@@ -147,4 +147,4 @@ class ProcessQThread(qt.QThread):
self._process_obj = process_obj
def run(self):
self._xas_obj = self._process_obj.process(self._xas_obj)
self._xas_obj = self._process_obj.run(self._xas_obj)
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