Commit 2cb99228 authored by payno's avatar payno

Merge branch 'fix_1' into 'master'

Fix 1

See merge request workflow/xas!5
parents 70a46db3 efbd5d2b
Pipeline #12290 passed with stage
in 4 minutes and 13 seconds
......@@ -11,20 +11,20 @@ Change Log
* add core processes to access the PyMca XASClass main functionnalities
* spectrum normalization (xas.core.process.normalization)
* spectra normalization (xas.core.process.normalization)
* exafs - Extended X-Ray Absorption Fine Structure (xas.core.process.exafs)
* fourier transform (xas.core.process.ft)
* weight (xas.core.process.weight)
* input / output
* add function for reading spectrum from .dat files
* add function for reading spectrum and configuration from .h5 files
* add function for reading spectra from .dat files
* add function for reading spectra and configuration from .h5 files
* app
* add application to process a .ows file defining a workflow without orange.
input spectrum file and output file can be specified.
input spectra file and output file can be specified.
* orangecontrib
......
process
-------
You can use the workflow definition from a .ows (orange) file with it configuration to process different spectrum.
You can use the workflow definition from a .ows (orange) file with it configuration to process different spectra.
For this you should execute the `process` application
......
......@@ -225,8 +225,8 @@
"from silx.io.url import DataUrl\n",
"spec_url = DataUrl(file_path=data_file, scheme='PyMca')\n",
"print(spec_url.scheme())\n",
"xas_obj = read_pymca_xas(spectrum_url=DataUrl(file_path=data_file, scheme='PyMca'))\n",
"assert 'Mu' in xas_obj.spectrum"
"xas_obj = read_pymca_xas(spectra_url=DataUrl(file_path=data_file, scheme='PyMca'), channel_url=DataUrl(file_path=data_file, scheme='PyMca'))\n",
"assert 'Mu' in xas_obj.spectra[0]"
]
},
{
......@@ -244,7 +244,7 @@
"source": [
"from xas.core.process.normalization import pymca_normalization\n",
"xas_obj = pymca_normalization(xas_obj.copy())\n",
"assert 'NormalizedMu' in xas_obj.spectrum"
"assert 'NormalizedMu' in xas_obj.spectra[0]"
]
},
{
......@@ -262,7 +262,7 @@
"source": [
"from xas.core.process.exafs import pymca_exafs\n",
"xas_obj = pymca_exafs(xas_obj.copy())\n",
"assert 'PostEdgeB' in xas_obj.spectrum"
"assert 'PostEdgeB' in xas_obj.spectra[0]"
]
},
{
......@@ -283,7 +283,7 @@
"l_xas_obj.configuration['SET_KWEIGHT'] = 1\n",
"\n",
"xas_obj = pymca_k_weight(l_xas_obj)\n",
"assert xas_obj.spectrum['KWeight'] == 1"
"assert xas_obj.spectra[0]['KWeight'] == 1"
]
},
{
......@@ -301,7 +301,7 @@
"source": [
"from xas.core.process.ft import pymca_ft\n",
"xas_obj = pymca_ft(xas_obj.copy())\n",
"assert 'FTRadius' in xas_obj.spectrum['FT']"
"assert 'FTRadius' in xas_obj.spectra[0]['FT']"
]
},
{
......@@ -325,10 +325,11 @@
"import xas.core.process.k_weight\n",
"import xas.core.process.exafs\n",
"import xas.core.process.ft\n",
"from xas.core.types import XASObject\n",
"import xas.io\n",
"\n",
"\n",
"read_task = Node(callback=xas.io.read_pymca_xas)\n",
"read_task = Node(callback=xas.io.read_pymca_xas_from_file)\n",
"normalization_task = Node(callback=xas.core.process.normalization.pymca_normalization)\n",
"k_weight_task = Node(callback=xas.core.process.k_weight.pymca_k_weight)\n",
"exafs_task = Node(callback=xas.core.process.exafs.pymca_exafs)\n",
......@@ -370,7 +371,8 @@
"data_file = os.path.join(PYMCA_DATA_DIR, \"EXAFS_Cu.dat\")\n",
"out = exec_workflow(scheme=scheme, input_=data_file)\n",
"assert isinstance(out, dict)\n",
"assert 'FTRadius' in out['spectrum']['FT']"
"xas_obj_out = XASObject.from_dict(out)\n",
"assert 'FTRadius' in xas_obj_out.spectra[0].ft"
]
},
{
......@@ -378,14 +380,18 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
""
]
}
],
"metadata": {
......@@ -397,7 +403,7 @@
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
"version": 3.0
},
"file_extension": ".py",
"mimetype": "text/x-python",
......@@ -408,5 +414,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 0
}
XAS input
=========
Use to load a spectrum from a .dat file or .h5 file
Use to load a spectra from a .dat file or .h5 file
.. image:: img/xas_input.png
XAS output
==========
Use to dump configuration and spectrum into a .h5 file
Use to dump configuration and spectra into a .h5 file
.. image:: img/xas_output.png
......@@ -78,11 +78,11 @@ class TestSimplePyMcaWorkflow(OrangeWorflowTest):
cls.processOrangeEvents(cls)
cls.link(cls, xasInputNode, "spectrum", xasNormalizationNode, "spectrum")
cls.link(cls, xasNormalizationNode, "spectrum", xasEXAFSNode, "spectrum")
cls.link(cls, xasEXAFSNode, "spectrum", xasKWeightNode, "spectrum")
cls.link(cls, xasKWeightNode, "spectrum", xasFTNode, "spectrum")
cls.link(cls, xasFTNode, "spectrum", xasOutputNode, "spectrum")
cls.link(cls, xasInputNode, "spectra", xasNormalizationNode, "spectra")
cls.link(cls, xasNormalizationNode, "spectra", xasEXAFSNode, "spectra")
cls.link(cls, xasEXAFSNode, "spectra", xasKWeightNode, "spectra")
cls.link(cls, xasKWeightNode, "spectra", xasFTNode, "spectra")
cls.link(cls, xasFTNode, "spectra", xasOutputNode, "spectra")
cls.processOrangeEvents(cls)
cls.xasInputWidget = cls.getWidgetForNode(cls, xasInputNode)
......
......@@ -32,7 +32,7 @@ from silx.gui import qt
from silx.gui.plot import Plot1D, LegendSelector
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from xas.core.types import XASBase
from xas.core.types import XASObject
from PyMca5.PyMcaGui.physics.xas.XASPostEdgeParameters import XASPostEdgeParameters
from Orange.widgets.settings import Setting
import xas.core.process.exafs
......@@ -80,8 +80,8 @@ class ExafsOW(OWWidget):
want_main_area = True
resizing_enabled = True
inputs = [("spectrum", XASBase, "process")]
outputs = [("spectrum", XASBase), ("curves", tuple)]
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.exafs.PyMca_exafs
......@@ -119,10 +119,10 @@ class ExafsOW(OWWidget):
process_obj = ExafsOW.process_function()
process_obj.setProperties({'_pymcaSettings': self._window._pymcaWindow.getParameters()})
xas_obj = process_obj.process(xas_obj)
self._updatePlot(xas_obj.spectrum)
self._updatePlot(xas_obj.spectra)
# emit signal for the plot
self.send("spectrum", xas_obj)
self.send("spectra", xas_obj)
def _updatePlot(self, ddict):
plot = self._window.plot
......
......@@ -33,7 +33,7 @@ from silx.gui.plot import Plot1D, LegendSelector
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.widgets.settings import Setting
from xas.core.types import XASBase
from xas.core.types import XASObject
import xas.core.process.ft
from PyMca5.PyMcaGui.physics.xas.XASFourierTransformParameters import XASFourierTransformParameters
import logging
......@@ -80,8 +80,8 @@ class FTOW(OWWidget):
want_main_area = True
resizing_enabled = True
inputs = [("spectrum", XASBase, "process")]
outputs = [("spectrum", XASBase), ("curves", tuple)]
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.ft.PyMca_ft
......@@ -122,7 +122,7 @@ class FTOW(OWWidget):
self._updatePlot(ddict=xas_obj.spectrum['FT'])
# emit signal for the plot
self.send("spectrum", xas_obj)
self.send("spectra", xas_obj)
def _updatePlot(self, ddict):
self._window.plot.clear()
......
......@@ -33,7 +33,7 @@ from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.widgets.settings import Setting
from silx.gui import qt
from xas.core.types import XASBase
from xas.core.types import XASObject
import xas.core.process.k_weight
import logging
......@@ -85,8 +85,8 @@ class KWeightOW(OWWidget):
want_main_area = True
resizing_enabled = True
inputs = [("spectrum", XASBase, "process")]
outputs = [("spectrum", XASBase), ("curves", tuple)]
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.k_weight.PyMca_k_weight
......@@ -125,7 +125,7 @@ class KWeightOW(OWWidget):
self._updatePlot(xas_obj.spectrum)
# emit signal for the plot
self.send("spectrum", xas_obj)
self.send("spectra", xas_obj)
def _updatePlot(self, ddict):
if ddict is None:
......
......@@ -35,7 +35,7 @@ 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 xas.core.types import XASBase
from xas.core.types import XASObject
import xas.core.process.normalization
import logging
......@@ -75,7 +75,7 @@ class NormalizationOW(OWWidget):
"""
name = "normalization"
id = "orange.widgets.xas.normalization"
description = "Process spectrum normalization"
description = "Process spectra normalization"
icon = "icons/normalization.png"
priority = 1
category = "esrfWidgets"
......@@ -84,9 +84,9 @@ class NormalizationOW(OWWidget):
want_main_area = True
resizing_enabled = True
inputs = [("spectrum", XASBase, "process")]
inputs = [("spectra", XASObject, "process")]
outputs = [("spectrum", XASBase), ("curves", tuple)]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.normalization.PyMca_normalization
......@@ -99,7 +99,7 @@ class NormalizationOW(OWWidget):
self._window = NormalizationWindow(parent=self)
layout = gui.vBox(self.mainArea, 'fourier transform').layout()
layout.addWidget(self._window)
self._window.plot.setWindowTitle('spectrum')
self._window.plot.setWindowTitle('spectra')
self._window.plot.getXAxis().setLabel("Energy (eV)")
self._window.plot.getYAxis().setLabel("Absorption (a.u.)")
......@@ -126,7 +126,7 @@ class NormalizationOW(OWWidget):
xas_obj = process_class(xas_obj)
self._updatePlot(xas_obj.spectrum)
# emit signal for the plot
self.send("spectrum", xas_obj)
self.send("spectra", xas_obj)
def _updateProcess(self):
self._update_settings()
......
......@@ -31,10 +31,8 @@ __date__ = "06/11/2019"
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from silx.gui import qt
from xas.core.types import XASBase, PyMcaXAS
from xas.core.types import XASObject
from Orange.widgets.settings import Setting
from silx.io.url import DataUrl
import h5py
import os
import logging
import xas.io
......@@ -47,7 +45,7 @@ class XASInputOW(OWWidget):
"""
name = "input"
id = "orange.widgets.xas.xas_input"
description = "Read .dat file and convert it to spectrum"
description = "Read .dat file and convert it to spectra"
icon = "icons/input.png"
priority = 0
category = "esrfWidgets"
......@@ -56,11 +54,11 @@ class XASInputOW(OWWidget):
want_main_area = True
resizing_enabled = True
outputs = [("spectrum", XASBase)]
outputs = [("spectra", XASObject)]
_input_file_setting = Setting(str())
process_function = xas.io.read_pymca_xas
process_function = xas.io.read_pymca_xas_from_file
def __init__(self):
super().__init__()
......@@ -99,8 +97,8 @@ class XASInputOW(OWWidget):
old = self.blockSignals(True)
dialog = qt.QFileDialog(self)
dialog.setFileMode(qt.QFileDialog.ExistingFile)
dialog.setNameFilters(["spectrum (*.dat)",
"spectrum and configruation (*.h5 *.hdf *.hdf5)"])
dialog.setNameFilters(["spectra (*.dat)",
"spectra and configruation (*.h5 *.hdf *.hdf5)"])
if not dialog.exec_():
dialog.close()
......@@ -126,22 +124,8 @@ class XASInputOW(OWWidget):
return
else:
try:
xas_obj = self._interpreteInput(file_path=self._input_file_setting)
xas_obj = XASInputOW.read_pymca_xas_from_file(file_path=self._input_file_setting)
except ... as e:
_logger.error(e)
else:
self.send("spectrum", xas_obj)
def _interpreteInput(self, file_path):
if file_path.endswith('.dat'):
return xas.io.read_pymca_xas(DataUrl(file_path=self._input_file_setting,
scheme='PyMca'))
elif h5py.is_hdf5(file_path):
return xas.io.read_pymca_xas(spectrum_url=DataUrl(file_path=file_path,
scheme='PyMca',
data_path='spectrum'),
config_url=DataUrl(file_path=file_path,
scheme='silx',
data_path='configuration'))
else:
raise ValueError('file type not managed, unable to load')
self.send("spectra", xas_obj)
......@@ -32,8 +32,7 @@ from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from silx.gui import qt
from Orange.widgets.settings import Setting
from xas.core.types import XASBase
from xas.core.types import XASFactory
from xas.core.types import XASObject
import xas.io
import logging
_logger = logging.getLogger(__file__)
......@@ -54,7 +53,7 @@ class XASOutputOW(OWWidget):
want_main_area = True
resizing_enabled = True
inputs = [("spectrum", XASBase, 'process')]
inputs = [("spectra", XASObject, 'process')]
_output_file_setting = Setting(str())
process_function = xas.io.Writer_pymca_cas
......@@ -111,7 +110,7 @@ class XASOutputOW(OWWidget):
def process(self, xas_obj):
if isinstance(xas_obj, dict):
_xas_obj = XASFactory.from_dict(xas_obj)
_xas_obj = XASObject.from_dict(xas_obj)
else:
_xas_obj = xas_obj
......
......@@ -68,7 +68,7 @@ RELEASE_LEVEL_VALUE = {"dev": 0,
"final": 15}
MAJOR = 0
MINOR = 1
MINOR = 2
MICRO = 0
RELEV = "dev" # <16
SERIAL = 1 # <16
......
......@@ -35,7 +35,6 @@ def exec_(scheme, input_=None, output_=None):
if len(scheme._start_actor.listDownStreamActor) is 0:
_logger.warning('no downstream node defined')
return None
scheme._start_actor.trigger(input_)
scheme._end_actor.join()
return scheme._end_actor.outData
......
......@@ -27,7 +27,7 @@ __authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "06/11/2019"
from xas.core.types import PyMcaXAS
from xas.core.types import XASObject
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
from PyMca5.PyMcaPhysics.xas.XASClass import e2k
import logging
......@@ -38,38 +38,48 @@ _logger = logging.getLogger(__name__)
def pymca_exafs(xas_obj):
"""
:param xas_obj: object containing the configuration and spectrum to process
:type: Union[XASBase, dict]
:return: spectrum dict
:rtype: XASBase
:param xas_obj: object containing the configuration and spectra to process
:type: Union[XASObject, dict]
:return: spectra dict
:rtype: XASObject
"""
if isinstance(xas_obj, dict):
_xas_obj = PyMcaXAS().load_frm_dict(xas_obj)
_xas_obj = XASObject.from_dict(xas_obj)
else:
_xas_obj = xas_obj
pymca_xas = XASClass()
if 'Energy' not in _xas_obj.spectrum or 'Mu' not in _xas_obj.spectrum:
_logger.error('Energy and or Mu is/are not specified, unable to '
'compute exafs')
return
pymca_xas.setSpectrum(energy=_xas_obj.spectrum['Energy'],
mu=_xas_obj.spectrum['Mu'])
pymca_xas.setConfiguration(_xas_obj.configuration)
_xas_obj.spectrum.update(pymca_xas.processSpectrum())
if 'EXAFSKValues' in _xas_obj.spectrum and 'Mu' in _xas_obj.spectrum:
kValues = _xas_obj.spectrum['EXAFSKValues']
else:
if 'Mu' not in _xas_obj.spectrum:
print('********************** computing **********************')
if 'Edge' not in _xas_obj.spectrum:
_xas_obj.spectrum.update(pymca_xas.processSpectrum())
e0 = _xas_obj.spectrum['Edge']
energy = _xas_obj.spectrum['Energy']
kValues = e2k(energy - e0)
_xas_obj.spectrum['EXAFSKValues'] = kValues
mu = _xas_obj.spectrum['Mu']
_xas_obj.spectrum['EXAFS'] = pymca_xas.postEdge(k=kValues, mu=mu)
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
......@@ -83,7 +93,7 @@ class PyMca_exafs(object):
def process(self, xas_obj):
if isinstance(xas_obj, dict):
_xas_obj = PyMcaXAS().load_frm_dict(xas_obj)
_xas_obj = XASObject.from_dict(xas_obj)
else:
_xas_obj = xas_obj
if self._settings:
......
......@@ -28,7 +28,7 @@ __license__ = "MIT"
__date__ = "06/11/2019"
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
from xas.core.types import PyMcaXAS
from xas.core.types import XASObject, Spectrum
import logging
_logger = logging.getLogger(__name__)
......@@ -37,24 +37,32 @@ _logger = logging.getLogger(__name__)
def pymca_ft(xas_obj):
"""
:param xas_obj: object containing the configuration and spectrum to process
:type: Union[XASBase, dict]
:return: spectrum dict
:param xas_obj: object containing the configuration and spectra to process
:type: Union[XASObject, dict]
:return: spectra dict
:rtype: dict
"""
if isinstance(xas_obj, dict):
_xas_obj = PyMcaXAS().load_frm_dict(xas_obj)
_xas_obj = XASObject.from_dict(xas_obj)
else:
_xas_obj = xas_obj
pymca_xas = XASClass()
if 'Energy' not in _xas_obj.spectrum or 'Mu' not in _xas_obj.spectrum:
_logger.error('Energy and or Mu is/are not specified, unable to '
'compute exafs')
return
pymca_xas.setConfiguration(_xas_obj.configuration)
pymca_xas.setSpectrum(energy=_xas_obj.spectrum['Energy'],
mu=_xas_obj.spectrum['Mu'])
_xas_obj.spectrum = pymca_xas.processSpectrum()
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
......@@ -69,13 +77,13 @@ class PyMca_ft(object):
def process(self, xas_obj):
"""
:param xas_obj: object containing the configuration and spectrum to process
:type: Union[XASBase, dict]
:return: spectrum dict
:param xas_obj: object containing the configuration and spectra to process
:type: Union[XASObject, dict]
:return: spectra dict
:rtype: dict
"""
if isinstance(xas_obj, dict):
_xas_obj = PyMcaXAS().load_frm_dict(xas_obj)
_xas_obj = XASObject.from_dict(xas_obj)
else:
_xas_obj = xas_obj
if self._settings:
......
......@@ -27,7 +27,7 @@ __authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "06/11/2019"
from xas.core.types import PyMcaXAS
from xas.core.types import XASObject, Spectrum
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
import logging
......@@ -37,22 +37,21 @@ _logger = logging.getLogger(__name__)
def pymca_k_weight(xas_obj):
"""
:param xas_obj: object containing the configuration and spectrum to process
:type: Union[XASBase, dict]
:return: spectrum dict
:param xas_obj: object containing the configuration and spectra to process
:type: Union[XASObject, dict]
:return: spectra dict
:rtype: dict
"""
assert xas_obj is not None
if isinstance(xas_obj, dict):
_xas_obj = PyMcaXAS().load_frm_dict(xas_obj)
_xas_obj = XASObject.from_dict(xas_obj)
else:
_xas_obj = xas_obj
assert _xas_obj is not None
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')
'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'):
......@@ -67,14 +66,22 @@ def pymca_k_weight(xas_obj):
_xas_obj.configuration['Normalization']['KWeight'] = _xas_obj.configuration[
'SET_KWEIGHT']
pymca_xas = XASClass()
if 'Energy' not in _xas_obj.spectrum or 'Mu' not in _xas_obj.spectrum:
raise ValueError('Energy and or Mu is/are not specified, unable to '
'compute exafs')
pymca_xas.setSpectrum(energy=_xas_obj.spectrum['Energy'],
mu=_xas_obj.spectrum['Mu'])
pymca_xas.setConfiguration(_xas_obj.configuration)
_xas_obj.spectrum = pymca_xas.processSpectrum()
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
......@@ -89,14 +96,14 @@ class PyMca_k_weight(object):
def process(self, xas_obj):
"""
:param xas_obj: object containing the configuration and spectrum to process
:type: Union[XASBase, dict]
:return: spectrum dict
:param xas_obj: object containing the configuration and spectra to process
:type: Union[XASObject, dict]
:return: spectra dict
:rtype: dict
"""
assert xas_obj is not None
if isinstance(xas_obj, dict):
_xas_obj = PyMcaXAS().load_frm_dict(xas_obj)
_xas_obj = XASObject.from_dict(xas_obj)
else:
_xas_obj = xas_obj
if self._k_weight:
......
......@@ -29,7 +29,7 @@ __date__ = "06/11/2019"
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
from xas.core.types import PyMcaXAS
from xas.core.types import XASObject, Spectrum
import logging
_logger = logging.getLogger(__name__)
......@@ -37,28 +37,46 @@ _logger = logging.getLogger(__name__)
def pymca_normalization(xas_obj):
"""
:param xas_obj: object containing the configuration and spectrum to process
:type: Union[XASBase, dict]. If is a dict, should contain configuration or
spectrum keys. Otherwise is simply the spectrum
:return: spectrum dict
:param xas_obj: object containing the configuration and spectra to process
:type: Union[XASObject, dict]. If is a dict, should contain configuration or
spectra keys. Otherwise is simply the spectra
:return: spectra dict
:rtype: dict
"""
pymca_xas = XASClass()
if isinstance(xas_obj, dict):
_xas_obj = PyMcaXAS().load_frm_dict(xas_obj)
_xas_obj = XASObject().load_frm_dict(xas_obj)
else:
_xas_obj = xas_obj
if 'Energy' not in _xas_obj.spectrum or 'Mu' not in _xas_obj.spectrum:
_logger.error('Energy and or Mu is/are not specified, unable to '
'normalize')
if _xas_obj.energy is None:
_logger.error('Energy not specified, unable to normalize spectra')
return
pymca_xas.setSpectrum(energy=_xas_obj.spectrum['Energy'],
mu=_xas_obj.spectrum['Mu'])
pymca_xas.setConfiguration(_xas_obj.configuration)
_xas_obj.configuration = pymca_xas.getConfiguration()
pymca_xas.processSpectrum()
res = pymca_xas.normalize()
_xas_obj.spectrum.update(res)
def _process_spectrum(spectrum, configuration):
if spectrum.mu is None: