Commit b428b506 authored by Wout De Nolf's avatar Wout De Nolf
Browse files

the task class `run` method should not return anything

parent 0fc99f62
......@@ -13,8 +13,9 @@ def xas_energy_roi(xas_obj):
:return: spectra dict
:rtype: :class:`.XASObject`
"""
xas_roi_process = EnergyROIProcess(inputs={"xas_obj": xas_obj})
return xas_roi_process.run()
process = EnergyROIProcess(inputs={"xas_obj": xas_obj})
process.run()
return process.get_output_value("xas_obj", None)
class EnergyROIProcess(
......@@ -51,7 +52,6 @@ class EnergyROIProcess(
self.register_process(_xas_obj, data_keys=("Mu", "energy"))
self.outputs.xas_obj = _xas_obj # .to_dict()
return _xas_obj
def _apply_roi(self, xas_obj, emin, emax):
if emin is None and emax is None:
......
......@@ -51,4 +51,3 @@ class ReadXasObject(
input_information = InputInformation.from_dict(self.inputs.input_information)
xas_obj = XASReader.read_frm_url(input_information)
self.outputs.xas_obj = xas_obj
return xas_obj
......@@ -90,7 +90,7 @@ def process_spectr_autobk(
return configuration, _spectrum
def larch_autobk(xas_obj, config: dict):
def larch_autobk(xas_obj, **optional_inputs):
"""
:param xas_obj: object containing the configuration and spectra to process
......@@ -98,8 +98,9 @@ def larch_autobk(xas_obj, config: dict):
:return: spectra dict
:rtype: XASObject
"""
mback_obj = Larch_autobk(inputs={"xas_obj": xas_obj, "autobk_config": config})
return mback_obj.run()
process = Larch_autobk(inputs={"xas_obj": xas_obj, **optional_inputs})
process.run()
return process.get_output_value("xas_obj", None)
class Larch_autobk(
......@@ -118,7 +119,6 @@ class Larch_autobk(
self.progress = 100
self.register_process(_xas_obj, data_keys=(_NexusDatasetDef("bkg"),))
self.outputs.xas_obj = _xas_obj # .to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
assert isinstance(xas_obj, XASObject)
......@@ -144,5 +144,3 @@ class Larch_autobk(
@staticmethod
def program_name():
return "larch_autobk"
__call__ = run
......@@ -81,7 +81,7 @@ def process_spectr_mback(
return configuration, _spectrum
def larch_mback(xas_obj, config: dict):
def larch_mback(xas_obj, **optional_inputs):
"""
:param xas_obj: object containing the configuration and spectra to process
......@@ -89,8 +89,9 @@ def larch_mback(xas_obj, config: dict):
:return: spectra dict
:rtype: XASObject
"""
mback_obj = Larch_mback(inputs={"xas_obj": xas_obj, "mback_config": config})
return mback_obj.run()
process = Larch_mback(inputs={"xas_obj": xas_obj, **optional_inputs})
process.run()
return process.get_output_value("xas_obj", None)
class Larch_mback(
......@@ -115,7 +116,6 @@ class Larch_mback(
),
)
self.outputs.xas_obj = _xas_obj # .to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
assert isinstance(xas_obj, XASObject)
......@@ -141,5 +141,3 @@ class Larch_mback(
@staticmethod
def program_name():
return "larch_mback"
__call__ = run
......@@ -87,7 +87,7 @@ def process_spectr_mback_norm(
return configuration, _spectrum
def larch_mback_norm(xas_obj, config: dict):
def larch_mback_norm(xas_obj, **optional_inputs):
"""
:param xas_obj: object containing the configuration and spectra to process
......@@ -95,10 +95,9 @@ def larch_mback_norm(xas_obj, config: dict):
:return: spectra dict
:rtype: XASObject
"""
mback_obj = Larch_mback_norm(
inputs={"xas_obj": xas_obj, "mback_norm_config": config}
)
return mback_obj.run()
process = Larch_mback_norm(inputs={"xas_obj": xas_obj, **optional_inputs})
process.run()
return process.get_output_value("xas_obj", None)
class Larch_mback_norm(
......@@ -123,7 +122,6 @@ class Larch_mback_norm(
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):
assert isinstance(xas_obj, XASObject)
......@@ -149,5 +147,3 @@ class Larch_mback_norm(
@staticmethod
def program_name():
return "larch_mback_norm"
__call__ = run
......@@ -87,7 +87,7 @@ def process_spectr_pre_edge(
return configuration, _spectrum
def larch_pre_edge(xas_obj, config: dict):
def larch_pre_edge(xas_obj, **optional_inputs):
"""
:param xas_obj: object containing the configuration and spectra to process
......@@ -95,8 +95,9 @@ def larch_pre_edge(xas_obj, config: dict):
:return: spectra dict
:rtype: XASObject
"""
mback_obj = Larch_pre_edge(inputs={"xas_obj": xas_obj, "pre_edge_config": config})
return mback_obj.run()
process = Larch_pre_edge(inputs={"xas_obj": xas_obj, **optional_inputs})
process.run()
return process.get_output_value("xas_obj", None)
class Larch_pre_edge(
......@@ -177,7 +178,6 @@ class Larch_pre_edge(
),
)
self.outputs.xas_obj = _xas_obj # .to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
assert isinstance(xas_obj, XASObject)
......@@ -203,5 +203,3 @@ class Larch_pre_edge(
@staticmethod
def program_name():
return "larch_pre_edge"
__call__ = run
......@@ -114,7 +114,7 @@ def process_spectr_xftf(
return configuration, _spectrum
def larch_xftf(xas_obj, config: dict):
def larch_xftf(xas_obj, **optional_inputs):
"""
:param xas_obj: object containing the configuration and spectra to process
......@@ -122,8 +122,9 @@ def larch_xftf(xas_obj, config: dict):
:return: spectra dict
:rtype: XASObject
"""
mback_obj = Larch_xftf(inputs={"xas_obj": xas_obj, "xftf_config": config})
return mback_obj.run()
process = Larch_xftf(inputs={"xas_obj": xas_obj, **optional_inputs})
process.run()
return process.get_output_value("xas_obj", None)
class Larch_xftf(
......@@ -203,7 +204,6 @@ class Larch_xftf(
),
)
self.outputs.xas_obj = _xas_obj # .to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
assert isinstance(xas_obj, XASObject)
......@@ -229,5 +229,3 @@ class Larch_xftf(
@staticmethod
def program_name():
return "larch_xftf"
__call__ = run
......@@ -156,5 +156,3 @@ class NoiseProcess(
@staticmethod
def program_name():
return "noise_savgol"
__call__ = run
......@@ -97,7 +97,7 @@ def process_spectr_exafs(
return configuration, get_output(spectrum, res_spectrum)
def pymca_exafs(xas_obj):
def pymca_exafs(xas_obj, **optional_inputs):
"""
:param xas_obj: object containing the configuration and spectra to process
......@@ -105,8 +105,9 @@ def pymca_exafs(xas_obj):
:return: spectra dict
:rtype: XASObject
"""
exafs_obj = PyMca_exafs(inputs={"xas_obj": xas_obj})
return exafs_obj.run()
process = PyMca_exafs(inputs={"xas_obj": xas_obj, **optional_inputs})
process.run()
return process.get_output_value("xas_obj", None)
class PyMca_exafs(
......@@ -144,7 +145,6 @@ class PyMca_exafs(
),
)
self.outputs.xas_obj = _xas_obj # .to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
assert isinstance(xas_obj, XASObject)
......@@ -171,5 +171,3 @@ class PyMca_exafs(
@staticmethod
def program_name():
return "pymca_exafs"
__call__ = run
......@@ -101,7 +101,7 @@ def process_spectr_ft(
return configuration, spectrum_
def pymca_ft(xas_obj):
def pymca_ft(xas_obj, **optional_inputs):
"""
:param xas_obj: object containing the configuration and spectra to process
......@@ -109,9 +109,9 @@ def pymca_ft(xas_obj):
:return: spectra dict
:rtype: dict
"""
assert xas_obj is not None
ft_obj = PyMca_ft(inputs={"xas_obj": xas_obj})
return ft_obj.run()
process = PyMca_ft(inputs={"xas_obj": xas_obj, **optional_inputs})
process.run()
return process.get_output_value("xas_obj", None)
class PyMca_ft(
......@@ -158,7 +158,6 @@ class PyMca_ft(
),
)
self.outputs.xas_obj = _xas_obj # .to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
assert isinstance(xas_obj, XASObject)
......@@ -183,5 +182,3 @@ class PyMca_ft(
@staticmethod
def program_name():
return "pymca_ft"
__call__ = run
......@@ -90,7 +90,7 @@ def process_spectr_k(
return configuration_, spectrum_
def pymca_k_weight(xas_obj):
def pymca_k_weight(xas_obj, **optional_inputs):
"""
Set weight for exafs values
......@@ -99,8 +99,9 @@ def pymca_k_weight(xas_obj):
:return: spectra dict
:rtype: :class:`.XASObject`
"""
k_weight_obj = PyMca_k_weight(inputs={"xas_obj": xas_obj})
return k_weight_obj.run()
process = PyMca_k_weight(inputs={"xas_obj": xas_obj, **optional_inputs})
process.run()
return process.get_output_value("xas_obj", None)
class PyMca_k_weight(
......@@ -160,7 +161,6 @@ class PyMca_k_weight(
self.progress = 100.0
self.register_process(xas_obj=_xas_obj, data_keys=tuple())
self.outputs.xas_obj = _xas_obj # .to_dict()
return _xas_obj
def _pool_process(self, xas_obj):
"""process normalization from a pool"""
......@@ -188,5 +188,3 @@ class PyMca_k_weight(
@staticmethod
def program_name():
return "pymca_k_weight"
__call__ = run
......@@ -75,7 +75,7 @@ def process_spectr_norm(
return configuration, get_output(spectrum, spectrum_)
def pymca_normalization(xas_obj):
def pymca_normalization(xas_obj, **optional_inputs):
"""
:param xas_obj: object containing the configuration and spectra to process
......@@ -84,8 +84,9 @@ def pymca_normalization(xas_obj):
:return: spectra dict
:rtype: dict
"""
normalization_obj = PyMca_normalization(inputs={"xas_obj": xas_obj})
return normalization_obj.run()
process = PyMca_normalization(inputs={"xas_obj": xas_obj, **optional_inputs})
process.run()
return process.get_output_value("xas_obj", None)
class PyMca_normalization(
......@@ -133,9 +134,7 @@ class PyMca_normalization(
_NexusDatasetDef("NormalizedSignal"),
),
)
xas_obj_as_dict = _xas_obj.to_dict()
self.outputs.xas_obj = xas_obj_as_dict
return _xas_obj
self.outputs.xas_obj = _xas_obj # .to_dict()
def _pool_process(self, xas_obj):
"""process normalization from a pool"""
......@@ -161,5 +160,3 @@ class PyMca_normalization(
@staticmethod
def program_name():
return "pymca_normalization"
__call__ = run
......@@ -19,8 +19,9 @@ def xas_roi(xas_obj):
:return: spectra dict
:rtype: :class:`.XASObject`
"""
xas_roi_process = ROIProcess(inputs={"xas_obj": xas_obj})
return xas_roi_process.run()
process = ROIProcess(inputs={"xas_obj": xas_obj})
process.run()
return process.get_output_value("xas_obj", None)
class _ROI:
......@@ -162,10 +163,7 @@ class ROIProcess(
origin, size = roi_dict["origin"], roi_dict["size"]
_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__ = run
......@@ -34,7 +34,7 @@ def xas_object(spectrum_cu_from_larch):
@pytest.mark.skipif(larch is None, reason="xraylarch not installed")
def test_multiple_spectra(xas_object):
"""Make sure computation on spectra is valid (n spectrum)"""
res = larch_autobk(xas_object, {})
res = larch_autobk(xas_object)
assert isinstance(res, XASObject)
spectrum0 = res.spectra.data.flat[0]
assert hasattr(spectrum0, "k")
......@@ -44,7 +44,7 @@ def test_multiple_spectra(xas_object):
@pytest.mark.skipif(larch is None, reason="xraylarch not installed")
def test_multiple_spectra_as_dict(xas_object):
"""Make sure computation on spectra is valid (n spectrum)"""
res = larch_autobk(xas_object.to_dict(), {})
res = larch_autobk(xas_object.to_dict())
assert isinstance(res, XASObject)
spectrum0 = res.spectra.data.flat[0]
assert hasattr(spectrum0, "k")
......
......@@ -35,7 +35,7 @@ def xas_object(spectrum_cu_from_larch):
@pytest.mark.skipif(larch is None, reason="xraylarch not installed")
def test_multiple_spectra(xas_object):
"""Make sure computation on spectra is valid (n spectrum)"""
res = larch_mback(xas_object, {"z": 29})
res = larch_mback(xas_object, mback_config={"z": 29})
assert isinstance(res, XASObject)
spectrum0 = res.spectra.data.flat[0]
assert hasattr(spectrum0, "fpp")
......@@ -45,7 +45,7 @@ def test_multiple_spectra(xas_object):
@pytest.mark.skipif(larch is None, reason="xraylarch not installed")
def test_multiple_spectra_asdict(xas_object):
"""Make sure computation on spectra is valid (n spectrum)"""
res = larch_mback(xas_object.to_dict(), {"z": 29})
res = larch_mback(xas_object.to_dict(), mback_config={"z": 29})
assert isinstance(res, XASObject)
spectrum0 = res.spectra.data.flat[0]
assert hasattr(spectrum0, "fpp")
......
......@@ -48,7 +48,7 @@ def xas_object(spectrum_cu_from_larch):
@pytest.mark.skipif(larch is None, reason="xraylarch not installed")
def test_multiple_spectra(xas_object):
"""Make sure computation on spectra is valid (n spectrum)"""
res = larch_mback_norm(xas_object, {})
res = larch_mback_norm(xas_object)
assert isinstance(res, XASObject)
spectrum0 = res.spectra.data.flat[0]
assert hasattr(spectrum0, "mback_mu")
......@@ -58,7 +58,7 @@ def test_multiple_spectra(xas_object):
@pytest.mark.skipif(larch is None, reason="xraylarch not installed")
def test_multiple_spectra_asdict(xas_object):
"""Make sure computation on spectra is valid (n spectrum)"""
res = larch_mback_norm(xas_object.to_dict(), {})
res = larch_mback_norm(xas_object.to_dict())
assert isinstance(res, XASObject)
spectrum0 = res.spectra.data.flat[0]
assert hasattr(spectrum0, "mback_mu")
......
......@@ -35,7 +35,7 @@ def xas_object(spectrum_cu_from_larch):
@pytest.mark.skipif(larch is None, reason="xraylarch not installed")
def test_multiple_spectra(xas_object):
"""Make sure computation on spectra is valid (n spectrum)"""
res = larch_pre_edge(xas_object, {})
res = larch_pre_edge(xas_object)
assert isinstance(res, XASObject)
spectrum0 = res.spectra.data.flat[0]
assert hasattr(spectrum0, "pre_edge")
......@@ -45,7 +45,7 @@ def test_multiple_spectra(xas_object):
@pytest.mark.skipif(larch is None, reason="xraylarch not installed")
def test_multiple_spectra_asdict(xas_object):
"""Make sure computation on spectra is valid (n spectrum)"""
res = larch_pre_edge(xas_object.to_dict(), {})
res = larch_pre_edge(xas_object.to_dict())
assert isinstance(res, XASObject)
spectrum0 = res.spectra.data.flat[0]
assert hasattr(spectrum0, "pre_edge")
......
......@@ -53,7 +53,7 @@ def xas_object(spectrum_cu_from_larch):
@pytest.mark.skipif(larch is None, reason="xraylarch not installed")
def test_multiple_spectra(xas_object):
"""Make sure computation on spectra is valid (n spectrum)"""
res = larch_xftf(xas_object, {})
res = larch_xftf(xas_object)
assert isinstance(res, XASObject)
spectrum = res.spectra.data.flat[0]
assert hasattr(spectrum, "chir_re")
......@@ -65,7 +65,7 @@ def test_multiple_spectra(xas_object):
@pytest.mark.skipif(larch is None, reason="xraylarch not installed")
def test_multiple_spectra_asdict(xas_object):
"""Make sure computation on spectra is valid (n spectrum)"""
res = larch_xftf(xas_object.to_dict(), {})
res = larch_xftf(xas_object.to_dict())
assert isinstance(res, XASObject)
spectrum = res.spectra.data.flat[0]
assert hasattr(spectrum, "chir_re")
......
......@@ -19,11 +19,10 @@ try:
except ImportError:
PyMca5 = None
else:
from est.core.process.pymca.exafs import pymca_exafs, PyMca_exafs
from est.core.process.pymca.ft import pymca_ft, PyMca_ft
from est.core.process.pymca.k_weight import pymca_k_weight, PyMca_k_weight
from est.core.process.pymca.exafs import pymca_exafs
from est.core.process.pymca.ft import pymca_ft
from est.core.process.pymca.k_weight import pymca_k_weight
from est.core.process.pymca.normalization import pymca_normalization
from est.core.process.pymca.normalization import PyMca_normalization
@pytest.mark.skipif(PyMca5 is None, reason="PyMca5 is not installed")
......@@ -50,10 +49,10 @@ def test_pymca_process(filename_cu_from_pymca):
),
)
out.configuration = {"EXAFS": exafs_configuration, "SET_KWEIGHT": 0}
out = pymca_normalization(xas_obj=out)
out = pymca_exafs(xas_obj=out)
out = pymca_k_weight(xas_obj=out)
out = pymca_ft(xas_obj=out)
out = pymca_normalization(out)
out = pymca_exafs(out)
out = pymca_k_weight(out)
out = pymca_ft(out)
assert isinstance(out, XASObject)
......@@ -81,40 +80,10 @@ def test_pymca_process_with_dict(filename_cu_from_pymca):
),
)
out.configuration = {"EXAFS": exafs_configuration, "SET_KWEIGHT": 0}
out = pymca_normalization(xas_obj=out.to_dict())
out = pymca_exafs(xas_obj=out.to_dict())
out = pymca_k_weight(xas_obj=out.to_dict())
out = pymca_ft(xas_obj=out.to_dict())
assert isinstance(out, XASObject)
@pytest.mark.skipif(PyMca5 is None, reason="PyMca5 is not installed")
def test_pymca_process_with_cls(filename_cu_from_pymca):
"""Make sure the process have valid io"""
exafs_configuration = {
"Knots": {"Values": (1, 2, 5), "Number": 3, "Orders": [3, 3, 3]},
"KMin": 0,
"KMax": 2.3,
}
out = read_xas(
spectra_url=url_utils.build_spec_data_url(
file_path=filename_cu_from_pymca,
col_name="Column 2",
),
channel_url=url_utils.build_spec_data_url(
file_path=filename_cu_from_pymca,
col_name="Column 1",
),
)
out = PyMca_normalization(inputs={"xas_obj": out})()
exafs_process = PyMca_exafs(inputs={"xas_obj": out})
exafs_process.setConfiguration(configuration=exafs_configuration)
out = exafs_process()
kweight_process = PyMca_k_weight(inputs={"xas_obj": out})
kweight_process.setConfiguration({"k_weight": 0})
out = kweight_process()
out = PyMca_ft(inputs={"xas_obj": out})()
out = pymca_normalization(out.to_dict())
out = pymca_exafs(out.to_dict())
out = pymca_k_weight(out.to_dict())
out = pymca_ft(out.to_dict())
assert isinstance(out, XASObject)
assert out.spectra.data.flat[0].ft is not None
assert len(out.spectra.data.flat[0].ft.intensity) > 0
......@@ -136,16 +105,17 @@ def test_pymca_with_roi():
dict_xas_obj = xas_obj.to_dict()
assert "spectra" in dict_xas_obj.keys()
assert "energy" in dict_xas_obj.keys()
tmp_obj = XASObject.from_dict(dict_xas_obj)
numpy.testing.assert_array_equal(
tmp_obj.energy, tmp_obj.spectra.data.flat[0].energy
)
out = xas_roi(dict_xas_obj)
out.configuration = {"EXAFS": exafs_configuration, "SET_KWEIGHT": 0}
out = pymca_normalization(xas_obj=out)
out = pymca_exafs(xas_obj=out)
out = pymca_k_weight(xas_obj=out)
out = pymca_ft(xas_obj=out)
out = pymca_normalization(out)
out = pymca_exafs(out)
out = pymca_k_weight(out)
out = pymca_ft(out)
assert isinstance(out, XASObject)
assert out.spectra.shape[0] == 1
assert out.spectra.shape[1] == 5
......@@ -165,27 +135,23 @@ def test_h5_link_xas_object(tmpdir):
xas_obj.link_to_h5(h5_file)
assert xas_obj.linked_h5_file is not None
out = PyMca_normalization(inputs={"xas_obj": xas_obj})()
exafs_process = PyMca_exafs(inputs={"xas_obj": out})
out = pymca_normalization(xas_obj)
configuration = {
"Knots": {"Values": (1, 2, 5), "Number": 3, "Orders": [3, 3, 3]},
"KMin": 0,
"KMax": 2.3,
}
exafs_process.setConfiguration(configuration=configuration)
out = exafs_process()
k_weight_process = PyMca_k_weight(inputs={"xas_obj": out})
k_weight_process.setConfiguration({"k_weight": 0})
out = k_weight_process()
out = PyMca_ft(inputs={"xas_obj": out})()
out = PyMca_normalization(inputs={"xas_obj": out})()
out = pymca_exafs(out, exafs=configuration)
out = pymca_k_weight(out, k_weight=0)
out = pymca_ft(out)
out = pymca_normalization(out)
assert isinstance(out, XASObject)
assert out.linked_h5_file is h5_file
# then check all process are correctly registered with the valid id...
processes = xas_obj.get_process_flow()
assert len(processes) == 5
assert h5py_read_dataset(processes[1]["program"]) == "pymca_normalization"
assert h5py_read_dataset(processes[2]["program"]) == "pymca_exafs"
assert h5py_read_dataset(processes[5]["program"]) == "pymca_normalization"
......@@ -205,30 +171,26 @@ def test_h5_link_dict(tmpdir):
)
h5_file = str(tmpdir / "output_file.h5")
xas_obj.link_to_h5(h5_file)
assert xas_obj.linked_h5_file is not None
out = PyMca_normalization(inputs={"xas_obj": xas_obj.to_dict()})()
exafs_process = PyMca_exafs(inputs={"xas_obj": out})
out = pymca_normalization(xas_obj.to_dict())
configuration = {
"Knots": {"Values": (1, 2, 5), "Number": 3, "Orders": [3, 3, 3]},
"KMin": 0,
"KMax": 2.3