Commit d0fb21f4 authored by payno's avatar payno

[orangecontrib] generalize the pymca process from ProcessQThread and ProcessRunnable

parent dc4002ff
......@@ -29,6 +29,55 @@ __date__ = "06/07/2019"
from silx.gui import qt
from Orange.widgets import gui
import logging
_logger = logging.getLogger(__file__)
class _PyMcaProcessForOrangeMixIn(object):
"""
Group processing and progress display in a common class for pymca process
"""
def __init__(self):
# progress
self._progress = gui.ProgressBar(self, 100)
"""progress bar"""
self.__processingThread = None
"""Thread for processing"""
# progress
self._progress = gui.ProgressBar(self, 100)
def _endProcess(self, xas_obj):
if self._callback_finish:
try:
self.getProcessingThread()._process_obj._advancement.sigProgress.disconnect(self._setProgressValue)
except ... as e:
_logger.error(str(e))
self.getProcessingThread().finished.disconnect(self._callback_finish)
self._callback_finish = None
if xas_obj is None:
return
else:
self._window.xasObjViewer.setXASObj(xas_obj=xas_obj)
# emit signal for the plot
self.send("spectra", xas_obj)
def _stopProcessing(self):
if self.__processingThread is None:
return
else:
self.__processingThread.finished.disconnect(self._callback_finish)
self.__processingThread.quit()
def getProcessingThread(self):
if self.__processingThread is None:
self.__processingThread = ProcessQThread(parent=self)
return self.__processingThread
def _setProgressValue(self, value):
self._progress.widget.progressBarSet(value)
class ProcessRunnable(qt.QRunnable):
......@@ -51,10 +100,13 @@ class ProcessRunnable(qt.QRunnable):
self._function = fct
def run(self):
self._configuration, self._spectrum = self._function(
spectrum=self._spectrum,
configuration=self._configuration,
overwrite=True)
try:
self._configuration, self._spectrum = self._function(
spectrum=self._spectrum,
configuration=self._configuration,
overwrite=True)
except (KeyError, ValueError) as e:
_logger.error(e)
if self._callback:
self._callback()
......
......@@ -35,9 +35,11 @@ from Orange.widgets.widget import OWWidget
from Orange.widgets.settings import Setting
from xas.core.types import XASObject, Spectrum
import xas.core.process.exafs
from ..progress import QProgress
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
from ..progress import QProgress
from orangecontrib.xas.process import _PyMcaProcessForOrangeMixIn, ProcessRunnable
from PyMca5.PyMcaGui.physics.xas.XASPostEdgeParameters import XASPostEdgeParameters
import functools
import logging
_logger = logging.getLogger(__file__)
......@@ -143,7 +145,7 @@ class ExafsWindow(qt.QMainWindow):
self.xasObjViewer._mapView.keySelectionDocker.setVisible(self.xasObjViewer.getViewType() is ViewType.map)
class ExafsOW(OWWidget):
class ExafsOW(_PyMcaProcessForOrangeMixIn, OWWidget):
"""
Widget used for signal extraction
"""
......@@ -168,17 +170,14 @@ class ExafsOW(OWWidget):
def __init__(self):
super().__init__()
self._latest_xas_obj = None
self._window = ExafsWindow()
layout = gui.vBox(self.mainArea, 'fourier transform').layout()
layout.addWidget(self._window)
self._latest_xas_obj = None
self._window.xasObjViewer._spectrumView._plot.getXAxis().setLabel("K")
self._window.xasObjViewer._spectrumView._plot.getYAxis().setLabel("Normalized Units")
# progress
self._progress = gui.ProgressBar(self, 100)
# manage settings
if self._pymcaSettings != dict():
self._window._pymcaWindow.setParameters(self._pymcaSettings)
......@@ -192,29 +191,49 @@ class ExafsOW(OWWidget):
if self._latest_xas_obj:
self.process(self._latest_xas_obj)
def _update_settings(self):
self._pymcaSettings = self._window._pymcaWindow.getParameters()
def process(self, xas_obj):
if xas_obj is None:
return
self._stopProcessing()
self._latest_xas_obj = xas_obj.copy()
# setup the exafs process
process_obj = QPyMca_exafs()
process_obj._advancement.sigProgress.connect(self._setProgressValue)
process_obj.setProperties({'_pymcaSettings': self._window._pymcaWindow.getParameters()})
xas_obj = process_obj.process(xas_obj)
process_obj._advancement.sigProgress.disconnect(self._setProgressValue)
self._window.xasObjViewer.setXASObj(xas_obj)
# emit signal for the plot
self.send("spectra", xas_obj)
def _update_settings(self):
self._pymcaSettings = self._window._pymcaWindow.getParameters()
# update the processing thread
thread = self.getProcessingThread()
thread.init(process_obj=process_obj, xas_obj=xas_obj)
self._callback_finish = functools.partial(self._endProcess, xas_obj)
thread.finished.connect(self._callback_finish)
# start processing
thread.start(priority=qt.QThread.LowPriority)
def _setProgressValue(self, value):
self._progress.widget.progressBarSet(value)
class QPyMca_exafs(xas.core.process.exafs.PyMca_exafs):
"""
Normalization able to give advancement using qt.Signal and QThreadPool
"""
def __init__(self):
xas.core.process.exafs.PyMca_exafs.__init__(self)
self._advancement = QProgress(self.name)
self._advancement = QProgress('normalization')
def _pool_process(self, xas_obj):
self.pool = qt.QThreadPool()
self.pool.setMaxThreadCount(5)
for spectrum in xas_obj.spectra:
runnable = ProcessRunnable(fct=xas.core.process.exafs.process_spectr_exafs,
spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement)
self.pool.start(runnable)
self.pool.waitForDone()
......@@ -38,6 +38,8 @@ import xas.core.process.ft
from ..progress import QProgress
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
from PyMca5.PyMcaGui.physics.xas.XASFourierTransformParameters import XASFourierTransformParameters
from orangecontrib.xas.process import _PyMcaProcessForOrangeMixIn, ProcessRunnable
import functools
import logging
_logger = logging.getLogger(__file__)
......@@ -115,7 +117,7 @@ class FTWindow(qt.QMainWindow):
self.xasObjViewer._mapView.keySelectionDocker.setVisible(self.xasObjViewer.getViewType() is ViewType.map)
class FTOW(OWWidget):
class FTOW(_PyMcaProcessForOrangeMixIn, OWWidget):
"""
Widget used for signal extraction
"""
......@@ -140,8 +142,8 @@ class FTOW(OWWidget):
def __init__(self):
super().__init__()
self._window = FTWindow(parent=self)
self._latest_xas_obj = None
self._window = FTWindow(parent=self)
layout = gui.vBox(self.mainArea, 'fourier transform').layout()
layout.addWidget(self._window)
......@@ -164,16 +166,22 @@ class FTOW(OWWidget):
if xas_obj is None:
return
self._stopProcessing()
self._latest_xas_obj = xas_obj.copy()
# setup the ft process
process_obj = QPyMca_ft()
process_obj._advancement.sigProgress.connect(self._setProgressValue)
process_obj.setProperties({'_pymcaSettings': self._window._pymcaWindow.getParameters()})
xas_obj = process_obj.process(xas_obj)
process_obj._advancement.sigProgress.disconnect(self._setProgressValue)
self._window.xasObjViewer.setXASObj(xas_obj)
# emit signal for the plot
self.send("spectra", xas_obj)
# update the processing thread
thread = self.getProcessingThread()
thread.init(process_obj=process_obj, xas_obj=xas_obj)
self._callback_finish = functools.partial(self._endProcess, xas_obj)
thread.finished.connect(self._callback_finish)
# start processing
thread.start(priority=qt.QThread.LowPriority)
def _update_settings(self):
self._pymcaSettings = self._window._pymcaWindow.getParameters()
......@@ -183,6 +191,20 @@ class FTOW(OWWidget):
class QPyMca_ft(xas.core.process.ft.PyMca_ft):
"""
Normalization able to give advancement using qt.Signal and QThreadPool
"""
def __init__(self):
xas.core.process.ft.PyMca_ft.__init__(self)
self._advancement = QProgress(self.name)
self._advancement = QProgress('normalization')
def _pool_process(self, xas_obj):
self.pool = qt.QThreadPool()
self.pool.setMaxThreadCount(5)
for spectrum in xas_obj.spectra:
runnable = ProcessRunnable(fct=xas.core.process.ft.process_spectr_ft,
spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement)
self.pool.start(runnable)
self.pool.waitForDone()
......@@ -36,7 +36,9 @@ from silx.gui import qt
from xas.core.types import XASObject, Spectrum
import xas.core.process.k_weight
from ..progress import QProgress
from orangecontrib.xas.process import _PyMcaProcessForOrangeMixIn, ProcessRunnable
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
import functools
import logging
_logger = logging.getLogger(__file__)
......@@ -134,7 +136,7 @@ class KWeightWindow(qt.QMainWindow):
self.xasObjViewer._mapView.keySelectionDocker.setVisible(self.xasObjViewer.getViewType() is ViewType.map)
class KWeightOW(OWWidget):
class KWeightOW(_PyMcaProcessForOrangeMixIn, OWWidget):
"""
Widget used for signal extraction
"""
......@@ -159,10 +161,10 @@ class KWeightOW(OWWidget):
def __init__(self):
super().__init__()
self._latest_xas_obj = None
layout = gui.vBox(self.mainArea, 'fourier transform').layout()
self._window = KWeightWindow(parent=self)
layout.addWidget(self._window)
self._latest_xas_obj = None
# progress
self._progress = gui.ProgressBar(self, 100)
......@@ -183,16 +185,22 @@ class KWeightOW(OWWidget):
if xas_obj is None:
return
self._stopProcessing()
self._latest_xas_obj = xas_obj.copy()
process_obj = QPyMca_K_weight()
# setup the k weight process
process_obj = QPyMca_k_weight()
process_obj._advancement.sigProgress.connect(self._setProgressValue)
process_obj.setProperties({'_kWeightSetting': self._window._k_spin_box.value()})
xas_obj = process_obj.process(xas_obj)
process_obj._advancement.sigProgress.disconnect(self._setProgressValue)
self._window.xasObjViewer.setXASObj(xas_obj)
# emit signal for the plot
self.send("spectra", xas_obj)
# update the processing thread
# update the processing thread
thread = self.getProcessingThread()
thread.init(process_obj=process_obj, xas_obj=xas_obj)
self._callback_finish = functools.partial(self._endProcess, xas_obj)
thread.finished.connect(self._callback_finish)
# start processing
thread.start(priority=qt.QThread.LowPriority)
def _update_settings(self):
self._kWeightSetting = self._window._k_spin_box.value()
......@@ -201,7 +209,21 @@ class KWeightOW(OWWidget):
self._progress.widget.progressBarSet(value)
class QPyMca_K_weight(xas.core.process.k_weight.PyMca_k_weight):
class QPyMca_k_weight(xas.core.process.k_weight.PyMca_k_weight):
"""
Normalization able to give advancement using qt.Signal and QThreadPool
"""
def __init__(self):
xas.core.process.k_weight.PyMca_k_weight.__init__(self)
self._advancement = QProgress(self.name)
self._advancement = QProgress('normalization')
def _pool_process(self, xas_obj):
self.pool = qt.QThreadPool()
self.pool.setMaxThreadCount(5)
for spectrum in xas_obj.spectra:
runnable = ProcessRunnable(fct=xas.core.process.k_weight.process_spectr_k,
spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement)
self.pool.start(runnable)
self.pool.waitForDone()
......@@ -38,7 +38,7 @@ from ..progress import QProgress
from xas.core.types import XASObject, Spectrum
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
import xas.core.process.normalization
from orangecontrib.xas.process import ProcessQThread, ProcessRunnable
from orangecontrib.xas.process import _PyMcaProcessForOrangeMixIn, ProcessRunnable
import functools
import logging
......@@ -153,7 +153,7 @@ class NormalizationWindow(qt.QMainWindow):
self.xasObjViewer._mapView.keySelectionDocker.setVisible(self.xasObjViewer.getViewType() is ViewType.map)
class NormalizationOW(OWWidget):
class NormalizationOW(_PyMcaProcessForOrangeMixIn, OWWidget):
"""
Widget used for signal extraction
"""
......@@ -178,17 +178,13 @@ class NormalizationOW(OWWidget):
"""Store the configuration of the PyMca XASClass"""
def __init__(self):
OWWidget.__init__(self)
super().__init__()
self._latest_xas_obj = None
self._window = NormalizationWindow(parent=self)
layout = gui.vBox(self.mainArea, 'fourier transform').layout()
layout.addWidget(self._window)
self.__processingThread = None
self._window.xasObjViewer.setWindowTitle('spectra')
# progress
self._progress = gui.ProgressBar(self, 100)
# manage settings
if self._pymcaSettings != dict():
self._window._pymcaWindow.setParameters(self._pymcaSettings)
......@@ -200,19 +196,27 @@ class NormalizationOW(OWWidget):
_sig = self._window._pymcaWindow.sigXASNormalizationParametersSignal
_sig.connect(self._updateProcess)
def _updateProcess(self):
self._update_settings()
if self._latest_xas_obj:
self.process(self._latest_xas_obj)
def _update_settings(self):
self._pymcaSettings = self._window._pymcaWindow.getParameters()
def process(self, xas_obj):
if xas_obj is None:
return
self._stopProcessing()
self._latest_xas_obj = xas_obj.copy()
# setup the normalization process
process_obj = QPyMca_normalization()
process_obj._advancement.sigProgress.connect(self._setProgressValue)
process_obj.setProperties({'_pymcaSettings': self._window._pymcaWindow.getParameters()})
# connect processing thread
# update the processing thread
thread = self.getProcessingThread()
thread.init(process_obj=process_obj, xas_obj=xas_obj)
self._callback_finish = functools.partial(self._endProcess, xas_obj)
......@@ -220,48 +224,6 @@ class NormalizationOW(OWWidget):
# start processing
thread.start(priority=qt.QThread.LowPriority)
def _stopProcessing(self):
if self.__processingThread is None:
return
else:
self.__processingThread.finished.disconnect(self._callback_finish)
self.__processingThread.quit()
def getProcessingThread(self):
if self.__processingThread is None:
self.__processingThread = ProcessQThread(parent=self)
return self.__processingThread
def _updateProcess(self):
self._update_settings()
if self._latest_xas_obj:
self.process(self._latest_xas_obj)
def _update_settings(self):
self._pymcaSettings = self._window._pymcaWindow.getParameters()
def _setProgressValue(self, value):
self._progress.widget.progressBarSet(value)
def _endProcess(self, xas_obj):
if self._callback_finish:
try:
self.getProcessingThread()._process_obj._advancement.sigProgress.disconnect(self._setProgressValue)
except ... as e:
_logger.error(str(e))
self.getProcessingThread().finished.disconnect(self._callback_finish)
self._callback_finish = None
if xas_obj is None:
return
else:
self._window.xasObjViewer.setXASObj(xas_obj=xas_obj)
# emit signal for the plot
self.send("spectra", xas_obj)
from xas.core.process.normalization import _process_spectr_norm
class QPyMca_normalization(xas.core.process.normalization.PyMca_normalization):
"""
......@@ -276,7 +238,7 @@ class QPyMca_normalization(xas.core.process.normalization.PyMca_normalization):
self.pool = qt.QThreadPool()
self.pool.setMaxThreadCount(5)
for spectrum in xas_obj.spectra:
runnable = ProcessRunnable(fct=_process_spectr_norm,
runnable = ProcessRunnable(fct=xas.core.process.normalization.process_spectr_norm,
spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement)
......
......@@ -40,6 +40,7 @@ import os
import logging
_logger = logging.getLogger(__file__)
_DEBUG = True
class XASInputOW(OWWidget):
"""
......@@ -99,6 +100,8 @@ class XASInputOW(OWWidget):
except ValueError as e:
qt.QMessageBox.warning(self, '', str(e))
else:
if _DEBUG is True and xas_obj.n_spectrum > 100:
xas_obj._setSpectra(xas_obj.spectra[0:100])
self.send("spectra", xas_obj)
def _manageSettings(self):
......
......@@ -27,22 +27,37 @@ __authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "06/11/2019"
from xas.core.types import XASObject
from xas.core.types import XASObject, Spectrum
from .process import Process
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
from PyMca5.PyMcaPhysics.xas.XASClass import e2k
import multiprocessing
import functools
import logging
_logger = logging.getLogger(__name__)
def _process_spectrum(spectrum, configuration):
"""process a single spectrum"""
def process_spectr_exafs(spectrum, configuration, overwrite=True):
"""
:param :class:`.Spectrum` spectrum: spectrum to process
:param dict configuration: configuration of the pymca normalization
:param bool overwrite: False if we want to return a new Spectrum instance
:return:
:rtype: tuple (configuration, spectrum)
"""
pymca_xas = XASClass()
pymca_xas.setSpectrum(energy=spectrum.energy,
mu=spectrum.mu)
pymca_xas.setConfiguration(configuration)
spectrum.update(pymca_xas.processSpectrum())
pymca_xas.processSpectrum()
# try:
# pymca_xas.processSpectrum()
# except (IndexError, ValueError) as e:
# _logger.error(e)
# return None, None
if 'Energy' not in spectrum or 'Mu' not in spectrum:
_logger.error('Energy and or Mu is/are not specified, unable to '
......@@ -61,9 +76,12 @@ def _process_spectrum(spectrum, configuration):
kValues = e2k(energy - e0)
spectrum['EXAFSKValues'] = kValues
mu = spectrum.mu
spectrum['EXAFS'] = pymca_xas.postEdge(k=kValues, mu=mu)
return configuration, spectrum
if overwrite:
spectrum['EXAFS'] = pymca_xas.postEdge(k=kValues, mu=mu)
return configuration, spectrum
else:
new_spectrum = Spectrum(energy=spectrum.energy, mu=energy.mu)
return configuration, new_spectrum
def pymca_exafs(xas_obj):
......@@ -90,20 +108,23 @@ class PyMca_exafs(Process):
self._settings = properties['_pymcaSettings']
def process(self, xas_obj):
if isinstance(xas_obj, dict):
_xas_obj = XASObject.from_dict(xas_obj)
else:
_xas_obj = xas_obj
_xas_obj = self._getXasObject(xas_obj=xas_obj)
if self._settings:
_xas_obj.configuration['EXAFS'] = self._settings
self._advancement.reset(max_=_xas_obj.n_spectrum)
self._advancement.startProcess()
for i_spectrum, spectrum in enumerate(_xas_obj.spectra):
_xas_obj.configuration, _xas_obj.spectra[i_spectrum] = _process_spectrum(spectrum=spectrum,
configuration=_xas_obj.configuration)
self._advancement.setAdvancement(int(i_spectrum / _xas_obj.n_spectrum * 100))
self._pool_process(xas_obj=xas_obj)
self._advancement.endProcess()
assert isinstance(_xas_obj, XASObject)
return _xas_obj
def _pool_process(self, xas_obj):
with multiprocessing.Pool(5) as p:
partial_ = functools.partial(process_spectr_exafs,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
overwrite=True)
p.map(partial_, xas_obj.spectra)
xas_obj.configuration = xas_obj.spectra[0].configuration
__call__ = process
......@@ -30,12 +30,22 @@ __date__ = "06/11/2019"
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
from xas.core.types import XASObject, Spectrum
from .process import Process
import functools
import multiprocessing
import logging
_logger = logging.getLogger(__name__)
def _process_spectrum(spectrum, configuration):
def process_spectr_ft(spectrum, configuration, overwrite=True):
"""
:param :class:`.Spectrum` spectrum: spectrum to process
:param dict configuration: configuration of the pymca normalization
:param bool overwrite: False if we want to return a new Spectrum instance
:return:
:rtype: tuple (configuration, spectrum)
"""
pymca_xas = XASClass()
if spectrum.energy is None or spectrum.mu is None:
_logger.error('Energy and or Mu is/are not specified, unable to '
......@@ -44,9 +54,12 @@ def _process_spectrum(spectrum, configuration):
pymca_xas.setConfiguration(configuration)
pymca_xas.setSpectrum(energy=spectrum.energy,
mu=spectrum.mu)
spectrum = Spectrum.from_dict(pymca_xas.processSpectrum())
assert 'FT' in spectrum
return configuration, spectrum
spectrum_ = Spectrum.from_dict(pymca_xas.processSpectrum())
if overwrite:
spectrum.load_frm_dict(spectrum_.to_dict())
return configuration, spectrum
else:
return configuration, spectrum_
def pymca_ft(xas_obj):
......@@ -78,20 +91,23 @@ class PyMca_ft(Process):
:return: spectra dict
:rtype: dict
"""
if isinstance(xas_obj, dict):
_xas_obj = XASObject.from_dict(xas_obj)
else:
_xas_obj = xas_obj
_xas_obj = self._getXasObject(xas_obj=xas_obj)
if self._settings:
_xas_obj.configuration['FT'] = self._settings
self._advancement.reset(max_=_xas_obj.n_spectrum)
self._advancement.startProcess()
for i_spectrum, spectrum in enumerate(_xas_obj.spectra):
_xas_obj.configuration, _xas_obj.spectra[
i_spectrum] = _process_spectrum(spectrum=spectrum,
configuration=_xas_obj.configuration)
self._advancement.setAdvancement(int((i_spectrum * _xas_obj.n_spectrum) * 100))
self._pool_process(xas_obj=xas_obj)
self._advancement.endProcess()
return _xas_obj
def _pool_process(self, xas_obj):
with multiprocessing.Pool(5) as p:
partial_ = functools.partial(process_spectr_ft,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
overwrite=True)
p.map(partial_, xas_obj.spectra)
xas_obj.configuration = xas_obj.spectra[0].configuration
__call__ = process
......@@ -29,13 +29,23 @@ __date__ = "06/11/2019"
from xas.core.types import XASObject, Spectrum
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
import multiprocessing
import functools
from .process import Process
import logging
_logger = logging.getLogger(__name__)
def _process_spectrum(spectrum, configuration):
def process_spectr_k(spectrum, configuration, overwrite=True):
"""
:param :class:`.Spectrum` spectrum: spectrum to process
:param dict configuration: configuration of the pymca normalization
:param bool overwrite: False if we want to return a new Spectrum instance
:return:
:rtype: tuple (configuration, spectrum)
"""
assert spectrum is not None
pymca_xas = XASClass()
......@@ -45,8 +55,12 @@ def _process_spectrum(spectrum, configuration):
pymca_xas.setSpectrum(energy=spectrum.energy,
mu=spectrum.mu)
pymca_xas.setConfiguration(configuration)
spectrum = Spectrum.from_dict(pymca_xas.processSpectrum())
return configuration, spectrum
spectrum_ = Spectrum.from_dict(pymca_xas.processSpectrum())
if overwrite:
spectrum.load_frm_dict(spectrum_.to_dict())
return configuration, spectrum
else:
return configuration, spectrum_
def pymca_k_weight(xas_obj):
......@@ -79,10 +93,7 @@ class PyMca_k_weight(Process):
:rtype: dict
"""
assert xas_obj is not None
if isinstance(xas_obj, dict):
_xas_obj = XASObject.from_dict(xas_obj)
else:
_xas_obj = xas_obj
_xas_obj = self._getXasObject(xas_obj=xas_obj)
if self._k_weight:
_xas_obj.configuration['SET_KWEIGHT'] = self._k_weight
......@@ -106,14 +117,21 @@ class PyMca_k_weight(Process):
_xas_obj.configuration[
'SET_KWEIGHT']
self._advancement.reset(max_=_xas_obj.n_spectrum)
self._advancement.startProcess()
for i_spectrum, spectrum in enumerate(_xas_obj.spectra):
_xas_obj.configuration, _xas_obj.spectra[
i_spectrum] = _process_spectrum(spectrum=spectrum,
configuration=_xas_obj.configuration)
self._advancement.setAdvancement(int((i_spectrum * _xas_obj.n_spectrum) * 100))
self._pool_process(xas_obj=xas_obj)
self._advancement.endProcess()
return _xas_obj
def _pool_process(self, xas_obj):
"""process normalization from a pool"""
with multiprocessing.Pool(5) as p:
partial_ = functools.partial(process_spectr_k,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
overwrite=True)
p.map(partial_, xas_obj.spectra)
xas_obj.configuration = xas_obj.spectra[0].configuration
__call__ = process
......@@ -37,7 +37,15 @@ import logging
_logger = logging.getLogger(__name__)