Commit d748b44e authored by payno's avatar payno

Merge branch 'fix_9' into 'master'

[gui] add advancement on the processing

See merge request !7
parents 72419023 2cd39480
Pipeline #12384 passed with stage
in 4 minutes and 25 seconds
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2016-2017 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.
#
# ###########################################################################*/
__authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "07/08/2019"
from silx.gui import qt
from xas.core.process.progress import Progress
class QProgress(Progress, qt.QObject):
sigProgress = qt.Signal(int)
def __init__(self, name):
Progress.__init__(self, name)
qt.QObject.__init__(self)
def startProcess(self):
self.sigProgress.emit(0)
def setAdvancement(self, value):
self.sigProgress.emit(value)
def endProcess(self):
self.sigProgress.emit(100)
......@@ -289,7 +289,7 @@ class OrangeWorflowTest(TestCase):
self.canvas_window.set_widget_registry(self.widget_registry)
self.canvas_window.show()
# Process events to make sure the self.canvas_window layout has
# Progress events to make sure the self.canvas_window layout has
# a chance to activate (the welcome dialog is modal and will
# block the event queue, plus we need a chance to receive open file
# signals when running without a splash screen)
......
......@@ -35,6 +35,7 @@ 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 PyMca5.PyMcaGui.physics.xas.XASPostEdgeParameters import XASPostEdgeParameters
import logging
......@@ -148,7 +149,7 @@ class ExafsOW(OWWidget):
"""
name = "exafs"
id = "orange.widgets.xas.exafs"
description = "Process signal extraction"
description = "Progress signal extraction"
icon = "icons/exafs.png"
priority = 3
category = "esrfWidgets"
......@@ -175,6 +176,9 @@ class ExafsOW(OWWidget):
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)
......@@ -193,9 +197,11 @@ class ExafsOW(OWWidget):
return
self._latest_xas_obj = xas_obj.copy()
process_obj = ExafsOW.process_function()
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
......@@ -203,3 +209,12 @@ class ExafsOW(OWWidget):
def _update_settings(self):
self._pymcaSettings = self._window._pymcaWindow.getParameters()
def _setProgressValue(self, value):
self._progress.widget.progressBarSet(value)
class QPyMca_exafs(xas.core.process.exafs.PyMca_exafs):
def __init__(self):
xas.core.process.exafs.PyMca_exafs.__init__(self)
self._advancement = QProgress('exafs')
......@@ -35,6 +35,7 @@ from Orange.widgets.widget import OWWidget
from Orange.widgets.settings import Setting
from xas.core.types import XASObject, Spectrum
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
import logging
......@@ -120,7 +121,7 @@ class FTOW(OWWidget):
"""
name = "fourier transform"
id = "orange.widgets.xas.ft"
description = "Process fourier transform"
description = "Progress fourier transform"
icon = "icons/ft.png"
priority = 4
category = "esrfWidgets"
......@@ -144,6 +145,9 @@ class FTOW(OWWidget):
layout = gui.vBox(self.mainArea, 'fourier transform').layout()
layout.addWidget(self._window)
# progress
self._progress = gui.ProgressBar(self, 100)
# manage settings
if self._pymcaSettings != dict():
self._window._pymcaWindow.setParameters(self._pymcaSettings)
......@@ -161,10 +165,11 @@ class FTOW(OWWidget):
return
self._latest_xas_obj = xas_obj.copy()
process_obj = FTOW.process_function()
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
......@@ -172,3 +177,12 @@ class FTOW(OWWidget):
def _update_settings(self):
self._pymcaSettings = self._window._pymcaWindow.getParameters()
def _setProgressValue(self, value):
self._progress.widget.progressBarSet(value)
class QPyMca_ft(xas.core.process.ft.PyMca_ft):
def __init__(self):
xas.core.process.ft.PyMca_ft.__init__(self)
self._advancement = QProgress('exafs')
......@@ -35,6 +35,7 @@ from Orange.widgets.settings import Setting
from silx.gui import qt
from xas.core.types import XASObject, Spectrum
import xas.core.process.k_weight
from ..progress import QProgress
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
import logging
......@@ -139,7 +140,7 @@ class KWeightOW(OWWidget):
"""
name = "k weight"
id = "orange.widgets.xas.k_weight"
description = "Process k weight"
description = "Progress k weight"
icon = "icons/k_weight.png"
priority = 2
category = "esrfWidgets"
......@@ -163,6 +164,9 @@ class KWeightOW(OWWidget):
layout.addWidget(self._window)
self._latest_xas_obj = None
# progress
self._progress = gui.ProgressBar(self, 100)
# manage settings
if self._kWeightSetting != 3:
self._window._k_spin_box.setValue(self._kWeightSetting)
......@@ -180,9 +184,11 @@ class KWeightOW(OWWidget):
return
self._latest_xas_obj = xas_obj.copy()
process_obj = KWeightOW.process_function()
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
......@@ -190,3 +196,12 @@ class KWeightOW(OWWidget):
def _update_settings(self):
self._kWeightSetting = self._window._k_spin_box.value()
def _setProgressValue(self, value):
self._progress.widget.progressBarSet(value)
class QPyMca_K_weight(xas.core.process.k_weight.PyMca_k_weight):
def __init__(self):
xas.core.process.k_weight.PyMca_k_weight.__init__(self)
self._advancement = QProgress('k weight')
......@@ -34,7 +34,7 @@ from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.widgets.settings import Setting
from PyMca5.PyMcaGui.physics.xas.XASNormalizationParameters import XASNormalizationParameters
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
from ..progress import QProgress
from xas.core.types import XASObject, Spectrum
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
import xas.core.process.normalization
......@@ -157,7 +157,7 @@ class NormalizationOW(OWWidget):
"""
name = "normalization"
id = "orange.widgets.xas.normalization"
description = "Process spectra normalization"
description = "Progress spectra normalization"
icon = "icons/normalization.png"
priority = 1
category = "esrfWidgets"
......@@ -176,14 +176,15 @@ class NormalizationOW(OWWidget):
"""Store the configuration of the PyMca XASClass"""
def __init__(self):
super().__init__()
OWWidget.__init__(self)
self._latest_xas_obj = None
self._window = NormalizationWindow(parent=self)
layout = gui.vBox(self.mainArea, 'fourier transform').layout()
layout.addWidget(self._window)
self._window.xasObjViewer.setWindowTitle('spectra')
self.pymca_xas = XASClass()
# progress
self._progress = gui.ProgressBar(self, 100)
# manage settings
if self._pymcaSettings != dict():
......@@ -202,9 +203,11 @@ class NormalizationOW(OWWidget):
# TODO: move process to multiprocessing + add advancement progress
self._latest_xas_obj = xas_obj.copy()
process_class = NormalizationOW.process_function()
process_class.setProperties({'_pymcaSettings': self._window._pymcaWindow.getParameters()})
xas_obj = process_class(xas_obj)
process_obj = QPyMca_normalization()
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=xas_obj)
# emit signal for the plot
......@@ -217,3 +220,12 @@ class NormalizationOW(OWWidget):
def _update_settings(self):
self._pymcaSettings = self._window._pymcaWindow.getParameters()
def _setProgressValue(self, value):
self._progress.widget.progressBarSet(value)
class QPyMca_normalization(xas.core.process.normalization.PyMca_normalization):
def __init__(self):
xas.core.process.normalization.PyMca_normalization.__init__(self)
self._advancement = QProgress('normalization')
......@@ -28,6 +28,7 @@ __license__ = "MIT"
__date__ = "06/11/2019"
from xas.core.types import XASObject
from .progress import Progress
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
from PyMca5.PyMcaPhysics.xas.XASClass import e2k
import logging
......@@ -35,6 +36,36 @@ import logging
_logger = logging.getLogger(__name__)
def _process_spectrum(spectrum, configuration):
"""process a single spectrum"""
pymca_xas = XASClass()
pymca_xas.setSpectrum(energy=spectrum.energy,
mu=spectrum.mu)
pymca_xas.setConfiguration(configuration)
spectrum.update(pymca_xas.processSpectrum())
if 'Energy' not in spectrum or 'Mu' not in spectrum:
_logger.error('Energy and or Mu is/are not specified, unable to '
'compute exafs')
return None, None
if 'EXAFSKValues' in spectrum and 'Mu' in spectrum:
kValues = spectrum['EXAFSKValues']
else:
if 'Mu' not in spectrum:
print('********************** computing **********************')
if 'Edge' not in spectrum:
spectrum.update(pymca_xas.processSpectrum())
e0 = spectrum['Edge']
energy = spectrum['Energy']
kValues = e2k(energy - e0)
spectrum['EXAFSKValues'] = kValues
mu = spectrum.mu
spectrum['EXAFS'] = pymca_xas.postEdge(k=kValues, mu=mu)
return configuration, spectrum
def pymca_exafs(xas_obj):
"""
......@@ -43,48 +74,15 @@ def pymca_exafs(xas_obj):
:return: spectra dict
:rtype: XASObject
"""
if isinstance(xas_obj, dict):
_xas_obj = XASObject.from_dict(xas_obj)
else:
_xas_obj = xas_obj
def _process_spectrum(spectrum, configuration):
"""process a single spectrum"""
pymca_xas = XASClass()
pymca_xas.setSpectrum(energy=spectrum.energy,
mu=spectrum.mu)
pymca_xas.setConfiguration(configuration)
spectrum.update(pymca_xas.processSpectrum())
if 'Energy' not in spectrum or 'Mu' not in spectrum:
_logger.error('Energy and or Mu is/are not specified, unable to '
'compute exafs')
return None, None
if 'EXAFSKValues' in spectrum and 'Mu' in spectrum:
kValues = spectrum['EXAFSKValues']
else:
if 'Mu' not in spectrum:
print('********************** computing **********************')
if 'Edge' not in spectrum:
spectrum.update(pymca_xas.processSpectrum())
e0 = spectrum['Edge']
energy = spectrum['Energy']
kValues = e2k(energy - e0)
spectrum['EXAFSKValues'] = kValues
mu = spectrum.mu
spectrum['EXAFS'] = pymca_xas.postEdge(k=kValues, mu=mu)
return configuration, spectrum
# TODO: look for vectorized this
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)
assert isinstance(_xas_obj, XASObject)
return _xas_obj
exafs_obj = PyMca_exafs()
return exafs_obj.process(xas_obj=xas_obj)
class PyMca_exafs(object):
"""Process spectra for exafs and get information about the processing
advancement"""
def __init__(self):
self._advancement = Progress('exafs')
self._settings = None
def setProperties(self, properties):
......@@ -99,6 +97,13 @@ class PyMca_exafs(object):
if self._settings:
_xas_obj.configuration['EXAFS'] = self._settings
return pymca_exafs(xas_obj=xas_obj)
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._advancement.endProcess()
assert isinstance(_xas_obj, XASObject)
return _xas_obj
__call__ = process
......@@ -29,11 +29,26 @@ __date__ = "06/11/2019"
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
from xas.core.types import XASObject, Spectrum
from .progress import Progress
import logging
_logger = logging.getLogger(__name__)
def _process_spectrum(spectrum, configuration):
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 '
'compute exafs')
return None, None
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
def pymca_ft(xas_obj):
"""
......@@ -42,33 +57,14 @@ def pymca_ft(xas_obj):
:return: spectra dict
:rtype: dict
"""
if isinstance(xas_obj, dict):
_xas_obj = XASObject.from_dict(xas_obj)
else:
_xas_obj = xas_obj
def _process_spectrum(spectrum, configuration):
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 '
'compute exafs')
return None, None
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
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)
return _xas_obj
ft_obj = PyMca_ft()
return ft_obj.process(xas_obj=xas_obj)
class PyMca_ft(object):
def __init__(self):
self._settings = None
self._advancement = Progress('ft')
def setProperties(self, properties):
if '_pymcaSettings' in properties:
......@@ -88,6 +84,14 @@ class PyMca_ft(object):
_xas_obj = xas_obj
if self._settings:
_xas_obj.configuration['FT'] = self._settings
return pymca_ft(xas_obj=xas_obj)
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._advancement.endProcess()
return _xas_obj
__call__ = process
......@@ -29,11 +29,26 @@ __date__ = "06/11/2019"
from xas.core.types import XASObject, Spectrum
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
from .progress import Progress
import logging
_logger = logging.getLogger(__name__)
def _process_spectrum(spectrum, configuration):
assert spectrum is not None
pymca_xas = XASClass()
if spectrum.energy is None or spectrum.mu is None:
raise ValueError('Energy and or Mu is/are not specified, unable to '
'compute exafs')
pymca_xas.setSpectrum(energy=spectrum.energy,
mu=spectrum.mu)
pymca_xas.setConfiguration(configuration)
spectrum = Spectrum.from_dict(pymca_xas.processSpectrum())
return configuration, spectrum
def pymca_k_weight(xas_obj):
"""
......@@ -42,52 +57,14 @@ def pymca_k_weight(xas_obj):
:return: spectra dict
: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
if 'SET_KWEIGHT' not in _xas_obj.configuration:
_logger.warning(
'Missing configuration to know which value we should set '
'to k weight, will be set to 0 by default')
_xas_obj.configuration['SET_KWEIGHT'] = 0
for key in ('FT', 'EXAFS', 'Normalization'):
if key not in _xas_obj.configuration:
_xas_obj.configuration[key] = {}
_xas_obj.configuration['KWeight'] = _xas_obj.configuration['SET_KWEIGHT']
_xas_obj.configuration['FT']['KWeight'] = _xas_obj.configuration[
'SET_KWEIGHT']
_xas_obj.configuration['EXAFS']['KWeight'] = _xas_obj.configuration[
'SET_KWEIGHT']
_xas_obj.configuration['Normalization']['KWeight'] = _xas_obj.configuration[
'SET_KWEIGHT']
def _process_spectrum(spectrum, configuration):
assert spectrum is not None
pymca_xas = XASClass()
if spectrum.energy is None or spectrum.mu is None:
raise ValueError('Energy and or Mu is/are not specified, unable to '
'compute exafs')
pymca_xas.setSpectrum(energy=spectrum.energy,
mu=spectrum.mu)
pymca_xas.setConfiguration(configuration)
spectrum = Spectrum.from_dict(pymca_xas.processSpectrum())
return configuration, spectrum
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)
return _xas_obj
k_weight_obj = PyMca_k_weight()
return k_weight_obj.process(xas_obj=xas_obj)
class PyMca_k_weight(object):
def __init__(self):
self._k_weight = None
self._advancement = Progress('k weight')
def setProperties(self, properties):
if '_kWeightSetting' in properties:
......@@ -109,6 +86,34 @@ class PyMca_k_weight(object):
if self._k_weight:
_xas_obj.configuration['SET_KWEIGHT'] = self._k_weight
return pymca_k_weight(xas_obj=xas_obj)
if 'SET_KWEIGHT' not in _xas_obj.configuration:
_logger.warning(
'Missing configuration to know which value we should set '
'to k weight, will be set to 0 by default')
_xas_obj.configuration['SET_KWEIGHT'] = 0
for key in ('FT', 'EXAFS', 'Normalization'):
if key not in _xas_obj.configuration:
_xas_obj.configuration[key] = {}
_xas_obj.configuration['KWeight'] = _xas_obj.configuration[
'SET_KWEIGHT']
_xas_obj.configuration['FT']['KWeight'] = _xas_obj.configuration[
'SET_KWEIGHT']
_xas_obj.configuration['EXAFS']['KWeight'] = _xas_obj.configuration[
'SET_KWEIGHT']
_xas_obj.configuration['Normalization']['KWeight'] = \
_xas_obj.configuration[
'SET_KWEIGHT']
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._advancement.endProcess()
return _xas_obj
__call__ = process
......@@ -30,10 +30,32 @@ __date__ = "06/11/2019"
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
from xas.core.types import XASObject, Spectrum
from .progress import Progress
import logging
_logger = logging.getLogger(__name__)
def _process_spectrum(spectrum, configuration):
if spectrum.mu is None:
_logger.error('Mu is not specified, unable to normalize')
return
pymca_xas = XASClass()
pymca_xas.setSpectrum(energy=spectrum.energy,
mu=spectrum.mu)
pymca_xas.setConfiguration(configuration)
configuration = pymca_xas.getConfiguration()
try:
pymca_xas.processSpectrum()
# TODO: next line can be removed
ddict = spectrum.to_dict()
res = pymca_xas.normalize()
ddict.update(res)
spectrum = Spectrum.from_dict(ddict)
except (IndexError, ValueError) as e:
_logger.error(e)
return configuration, spectrum
def pymca_normalization(xas_obj):
"""
......@@ -43,46 +65,14 @@ def pymca_normalization(xas_obj):
:return: spectra dict
:rtype: dict
"""
if isinstance(xas_obj, dict):
_xas_obj = XASObject().load_frm_dict(xas_obj)
else:
_xas_obj = xas_obj
if _xas_obj.energy is None:
_logger.error('Energy not specified, unable to normalize spectra')
return
def _process_spectrum(spectrum, configuration):
if spectrum.mu is None:
_logger.error('Mu is not specified, unable to normalize')
return
pymca_xas = XASClass()
pymca_xas.setSpectrum(energy=spectrum.energy,
mu=spectrum.mu)
pymca_xas.setConfiguration(configuration)
configuration = pymca_xas.getConfiguration()
try:
pymca_xas.processSpectrum()
# TODO: next line can be removed
ddict = spectrum.to_dict()
res = pymca_xas.normalize()
ddict.update(res)
spectrum = Spectrum.from_dict(ddict)
except (IndexError, ValueError) as e:
_logger.error(e)
return configuration, spectrum
# TODO: this part could be optimized using vectorization or multiprocess for
# example.
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)
return _xas_obj
normalization_obj = PyMca_normalization()
return normalization_obj.process(xas_obj=xas_obj)
class PyMca_normalization(object):
def __init__(self):
self._settings = None
self._advancement = Progress('normalization')
def setProperties(self, properties):
if '_pymcaSettings' in properties:
......@@ -101,9 +91,22 @@ class PyMca_normalization(object):
_xas_obj = XASObject.from_dict(xas_obj)
else:
_xas_obj = xas_obj
if _xas_obj.energy is None:
_logger.error('Energy not specified, unable to normalize spectra')
return
if self._settings:
_xas_obj.configuration['Normalization'] = self._settings
return pymca_normalization(_xas_obj)
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._advancement.endProcess()
return _xas_obj
__call__ = process
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2016-2017 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.
#
# ###########################################################################*/
__authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "07/08/2019"