Commit 3b897cdc authored by payno's avatar payno
Browse files

[core][larch][pre_edge] replace callback by callbacks

parent b267e79e
......@@ -79,7 +79,9 @@ def process_spectr_autobk(spectrum, configuration, overwrite=True,
else:
_spectrum = Spectrum().load_frm_dict(spectrum.to_dict())
autobk(_spectrum, group=_spectrum, **opts)
if callbacks:
for callback in callbacks:
callback()
return configuration, _spectrum
......@@ -126,7 +128,7 @@ class Larch_autobk(Process):
for spectrum in xas_obj.spectra:
process_spectr_autobk(spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=True)
else:
from multiprocessing import Manager
......@@ -140,7 +142,7 @@ class Larch_autobk(Process):
with multiprocessing.Pool(5) as p:
partial_ = functools.partial(process_spectr_autobk,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=False,
output=res_list,
output_dict=output_dict)
......
......@@ -78,7 +78,9 @@ def process_spectr_mback(spectrum, configuration, overwrite=True, callback=None,
else:
_spectrum = Spectrum().load_frm_dict(spectrum.to_dict())
mback(_spectrum.energy, _spectrum.mu, group=_spectrum, **opts)
if callbacks:
for callback in callbacks:
callback()
return configuration, _spectrum
......@@ -125,7 +127,7 @@ class Larch_mback(Process):
for spectrum in xas_obj.spectra:
process_spectr_mback(spectrum=spectrum,
configuration=xas_obj.configuration['mback'],
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=True)
else:
from multiprocessing import Manager
......@@ -139,7 +141,7 @@ class Larch_mback(Process):
with multiprocessing.Pool(5) as p:
partial_ = functools.partial(process_spectr_mback,
configuration=xas_obj.configuration['mback'],
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=False,
output=res_list,
output_dict=output_dict)
......
......@@ -82,7 +82,9 @@ def process_spectr_mback_norm(spectrum, configuration, overwrite=True,
else:
_spectrum = Spectrum().load_frm_dict(spectrum.to_dict())
mback_norm(_spectrum, group=_spectrum, **opts)
if callbacks:
for callback in callbacks:
callback()
return configuration, _spectrum
......@@ -130,7 +132,7 @@ class Larch_mback_norm(Process):
for spectrum in xas_obj.spectra:
process_spectr_mback_norm(spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=True)
else:
from multiprocessing import Manager
......
......@@ -37,7 +37,7 @@ if _DEBUG:
from larch.symboltable import Group
def process_spectr_pre_edge(spectrum, configuration, overwrite=True, callback=None,
def process_spectr_pre_edge(spectrum, configuration, overwrite=True, callbacks=None,
output=None, output_dict=None):
"""
......@@ -47,7 +47,7 @@ def process_spectr_pre_edge(spectrum, configuration, overwrite=True, callback=No
:type: dict
:param overwrite: False if we want to return a new Spectrum instance
:type: bool
:param callback: callback to execute.
:param callbacks: callbacks to execute.
:param output: list to store the result, needed for pool processing
:type: multiprocessing.manager.list
:param output_dict: key is: input spectrum, value is index in the output
......@@ -77,6 +77,9 @@ def process_spectr_pre_edge(spectrum, configuration, overwrite=True, callback=No
else:
_spectrum = Spectrum().load_frm_dict(spectrum=spectrum)
pre_edge(_spectrum, group=_spectrum, **opts)
if callbacks:
for callback in callbacks:
callback()
return configuration, _spectrum
......@@ -125,7 +128,7 @@ class Larch_pre_edge(Process):
for spectrum in xas_obj.spectra:
process_spectr_pre_edge(spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=True)
else:
from multiprocessing import Manager
......@@ -139,7 +142,7 @@ class Larch_pre_edge(Process):
with multiprocessing.Pool(5) as p:
partial_ = functools.partial(process_spectr_pre_edge,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=False,
output=res_list,
output_dict=output_dict)
......
......@@ -77,6 +77,9 @@ def process_spectr_xftf(spectrum, configuration, overwrite=True, callback=None,
else:
_spectrum = Spectrum().load_frm_dict(spectrum.to_dict())
xftf(_spectrum, **opts)
if callbacks:
for callback in callbacks:
callback()
return configuration, _spectrum
......@@ -126,7 +129,7 @@ class Larch_xftf(Process):
for spectrum in xas_obj.spectra:
process_spectr_xftf(spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=True)
else:
from multiprocessing import Manager
......@@ -140,7 +143,7 @@ class Larch_xftf(Process):
with multiprocessing.Pool(5) as p:
partial_ = functools.partial(process_spectr_xftf,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=False,
output=res_list,
output_dict=output_dict)
......
......@@ -97,8 +97,9 @@ def process_spectr_exafs(spectrum, configuration, overwrite=True, callback=None,
exafs *= pow(kValues, ddict["KWeight"])
ddict["EXAFSNormalized"] = exafs
if callback:
callback()
if callbacks:
for callback in callbacks:
callback()
res_spectrum = Spectrum.from_dict(ddict=ddict)
......@@ -162,7 +163,7 @@ class PyMca_exafs(Process):
assert 'NormalizedBackground' in spectrum
process_spectr_exafs(spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=True)
assert 'EXAFSKValues' in spectrum
else:
......@@ -177,7 +178,7 @@ class PyMca_exafs(Process):
with multiprocessing.Pool(5) as p:
partial_ = functools.partial(process_spectr_exafs,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=False,
output=res_list,
output_dict=output_dict)
......
......@@ -108,8 +108,9 @@ def process_spectr_ft(spectrum, configuration, overwrite=True, callback=None,
assert "FTRadius" in ft
assert ft["FTRadius"] is not None
assert ft["FTIntensity"] is not None
if callback:
callback()
if callbacks:
for callback in callbacks:
callback()
if overwrite:
spectrum_ = spectrum
......@@ -180,7 +181,7 @@ class PyMca_ft(Process):
for spectrum in xas_obj.spectra:
process_spectr_ft(spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=True)
else:
from multiprocessing import Manager
......@@ -194,7 +195,7 @@ class PyMca_ft(Process):
with multiprocessing.Pool(1) as p:
partial_ = functools.partial(process_spectr_ft,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=False,
output=res_list,
output_dict=output_dict)
......
......@@ -91,8 +91,9 @@ def process_spectr_k(spectrum, configuration, overwrite=True, callback=None,
spectrum_["EXAFSNormalized"] = exafs
configuration_ = pymca_xas.getConfiguration()
if callback:
callback()
if callbacks:
for callback in callbacks:
callback()
if output is not None:
assert output_dict is not None
......@@ -181,14 +182,14 @@ class PyMca_k_weight(Process):
for spectrum in xas_obj.spectra:
process_spectr_k(spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=True)
assert 'KWeight' in xas_obj.configuration
else:
with multiprocessing.Pool(5) as p:
partial_ = functools.partial(process_spectr_k,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=True)
p.map(partial_, xas_obj.spectra)
......
......@@ -77,8 +77,9 @@ def process_spectr_norm(spectrum, configuration, overwrite=True, callback=None,
except (IndexError, ValueError) as e:
_logger.error(e)
return None, None
if callback:
callback()
if callbacks:
for callback in callbacks:
callback()
def get_output(orignal_spec, res_spec):
if overwrite:
......@@ -154,7 +155,7 @@ class PyMca_normalization(Process):
for spectrum in xas_obj.spectra:
process_spectr_norm(spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=True)
else:
from multiprocessing import Manager
......@@ -168,7 +169,7 @@ class PyMca_normalization(Process):
with multiprocessing.Pool(5) as p:
partial_ = functools.partial(process_spectr_norm,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
callbacks=self.callbacks,
overwrite=False,
output=res_list,
output_dict=output_dict)
......
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