Commit 89496a4d authored by payno's avatar payno

[core] move from one spectrum to several spectra.

- simplify the bases structure Spectrum and XASObject to be more generic and continue workfing with pymca.
parent 1e379335
......@@ -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
......
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,7 +31,7 @@ __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, PyMcaSpectrum
from Orange.widgets.settings import Setting
from silx.io.url import DataUrl
import h5py
......@@ -47,7 +47,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,7 +56,7 @@ class XASInputOW(OWWidget):
want_main_area = True
resizing_enabled = True
outputs = [("spectrum", XASBase)]
outputs = [("spectra", XASObject)]
_input_file_setting = Setting(str())
......@@ -99,8 +99,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()
......@@ -130,17 +130,18 @@ class XASInputOW(OWWidget):
except ... as e:
_logger.error(e)
else:
self.send("spectrum", xas_obj)
self.send("spectra", 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,
return xas.io.read_pymca_xas(
spectra_url=DataUrl(file_path=file_path,
scheme='PyMca',
data_path='spectra'),
config_url=DataUrl(file_path=file_path,
scheme='silx',
data_path='configuration'))
else:
......
......@@ -32,7 +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 XASObject
from xas.core.types import XASFactory
import xas.io
import logging
......@@ -54,7 +54,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
......
......@@ -27,7 +27,7 @@ __authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "06/11/2019"
from xas.core.types import PyMcaXAS
from xas.core.types import PyMcaSpectrum
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
from PyMca5.PyMcaPhysics.xas.XASClass import e2k
import logging
......@@ -38,38 +38,38 @@ _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 = PyMcaSpectrum().load_frm_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:
if 'Energy' not in _xas_obj.spectra or 'Mu' not in _xas_obj.spectra:
_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.setSpectrum(energy=_xas_obj.spectra['Energy'],
mu=_xas_obj.spectra['Mu'])
pymca_xas.setConfiguration(_xas_obj.configuration)
_xas_obj.spectrum.update(pymca_xas.processSpectrum())
_xas_obj.spectra.update(pymca_xas.processSpectrum())
if 'EXAFSKValues' in _xas_obj.spectrum and 'Mu' in _xas_obj.spectrum:
kValues = _xas_obj.spectrum['EXAFSKValues']
if 'EXAFSKValues' in _xas_obj.spectra and 'Mu' in _xas_obj.spectra:
kValues = _xas_obj.spectra['EXAFSKValues']
else:
if 'Mu' not in _xas_obj.spectrum:
if 'Mu' not in _xas_obj.spectra:
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']
if 'Edge' not in _xas_obj.spectra:
_xas_obj.spectra.update(pymca_xas.processSpectrum())
e0 = _xas_obj.spectra['Edge']
energy = _xas_obj.spectra['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)
_xas_obj.spectra['EXAFSKValues'] = kValues
mu = _xas_obj.spectra['Mu']
_xas_obj.spectra['EXAFS'] = pymca_xas.postEdge(k=kValues, mu=mu)
return _xas_obj
......@@ -83,7 +83,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 = PyMcaSpectrum().load_frm_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 PyMcaSpectrum
import logging
_logger = logging.getLogger(__name__)
......@@ -37,24 +37,24 @@ _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 = PyMcaSpectrum().load_frm_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:
if 'Energy' not in _xas_obj.spectra or 'Mu' not in _xas_obj.spectra:
_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()
pymca_xas.setSpectrum(energy=_xas_obj.spectra['Energy'],
mu=_xas_obj.spectra['Mu'])
_xas_obj.spectra = pymca_xas.processSpectrum()
return _xas_obj
......@@ -69,13 +69,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 = PyMcaSpectrum().load_frm_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 PyMcaSpectrum
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
import logging
......@@ -37,14 +37,14 @@ _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 = PyMcaSpectrum().load_frm_dict(xas_obj)
else:
_xas_obj = xas_obj
......@@ -68,13 +68,13 @@ def pymca_k_weight(xas_obj):
'SET_KWEIGHT']
pymca_xas = XASClass()
if 'Energy' not in _xas_obj.spectrum or 'Mu' not in _xas_obj.spectrum:
if 'Energy' not in _xas_obj.spectra or 'Mu' not in _xas_obj.spectra:
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.setSpectrum(energy=_xas_obj.spectra['Energy'],
mu=_xas_obj.spectra['Mu'])
pymca_xas.setConfiguration(_xas_obj.configuration)
_xas_obj.spectrum = pymca_xas.processSpectrum()
_xas_obj.spectra = pymca_xas.processSpectrum()
return _xas_obj
......@@ -89,14 +89,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 = PyMcaSpectrum().load_frm_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 PyMcaSpectrum
import logging
_logger = logging.getLogger(__name__)
......@@ -37,28 +37,28 @@ _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 = PyMcaSpectrum().load_frm_dict(xas_obj)
else:
_xas_obj = xas_obj
if 'Energy' not in _xas_obj.spectrum or 'Mu' not in _xas_obj.spectrum:
if 'Energy' not in _xas_obj.spectra or 'Mu' not in _xas_obj.spectra:
_logger.error('Energy and or Mu is/are not specified, unable to '
'normalize')
return
pymca_xas.setSpectrum(energy=_xas_obj.spectrum['Energy'],
mu=_xas_obj.spectrum['Mu'])
pymca_xas.setSpectrum(energy=_xas_obj.spectra['Energy'],
mu=_xas_obj.spectra['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)
_xas_obj.spectra.update(res)
return _xas_obj
......@@ -73,14 +73,14 @@ class PyMca_normalization(object):
def process(self, 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
"""
if isinstance(xas_obj, dict):
_xas_obj = PyMcaXAS().load_frm_dict(xas_obj)
_xas_obj = PyMcaSpectrum().load_frm_dict(xas_obj)
else:
_xas_obj = xas_obj
if self._settings:
......
......@@ -29,39 +29,39 @@ __date__ = "06/11/2019"
import unittest
from xas.core.process.exafs import pymca_exafs
from xas.core.types import PyMcaXAS, XASBase
from xas.core.types import PyMcaSpectrum, XASObject
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.utils.pymca import read_spectrum
import os
class TestIO(unittest.TestCase):
class TestEXAFSSingleSpectrum(unittest.TestCase):
"""Make sure the process have valid io"""
def setUp(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
spectrum = {}
spectrum['Energy'], spectrum['Mu'] = read_spectrum(data_file)
self.input_ = PyMcaXAS(spectrum=spectrum)
self.input_ = PyMcaSpectrum(spectrum=spectrum)
def testPyMcaXASAsInput(self):
res = pymca_exafs(self.input_)
self.assertTrue(isinstance(res, XASBase))
self.assertTrue('PostEdgeB' in res.spectrum)
self.assertTrue('EXAFSKValues' in res.spectrum)
self.assertTrue('EXAFSSignal' in res.spectrum)
self.assertTrue(isinstance(res, XASObject))
self.assertTrue('PostEdgeB' in res.spectra)
self.assertTrue('EXAFSKValues' in res.spectra)
self.assertTrue('EXAFSSignal' in res.spectra)
def testDictAsInput(self):
"""Test succeed if the input is a dict"""
res = pymca_exafs(self.input_.to_dict())
self.assertTrue(isinstance(res, XASBase))
self.assertTrue('PostEdgeB' in res.spectrum)
self.assertTrue('EXAFSKValues' in res.spectrum)
self.assertTrue('EXAFSSignal' in res.spectrum)
self.assertTrue(isinstance(res, XASObject))
self.assertTrue('PostEdgeB' in res.spectra)
self.assertTrue('EXAFSKValues' in res.spectra)
self.assertTrue('EXAFSSignal' in res.spectra)
def suite():
test_suite = unittest.TestSuite()
for ui in (TestIO, ):
for ui in (TestEXAFSSingleSpectrum,):
test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(ui))
return test_suite
......
......@@ -31,29 +31,29 @@ import unittest
from xas.core.process.ft import pymca_ft
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.utils.pymca import read_spectrum
from xas.core.types import PyMcaXAS, XASBase
from xas.core.types import PyMcaSpectrum, XASObject
import os
class TestIO(unittest.TestCase):
class TestFTSingleSpectrum(unittest.TestCase):
"""Make sure the process have valid io"""
def setUp(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
spectrum = {}
spectrum['Energy'], spectrum['Mu'] = read_spectrum(data_file)
self.spectrum = spectrum
self.xas_obj = PyMcaXAS(spectrum=spectrum)
self.xas_obj = PyMcaSpectrum(spectrum=spectrum)
def testPyMcaXASAsInput(self):
res = pymca_ft(xas_obj=self.xas_obj)
self.assertTrue(isinstance(res, XASBase))
self.assertTrue(isinstance(res, XASObject))
self.assertTrue('FTRadius' in res.spectrum['FT'])
self.assertTrue('FTImaginary' in res.spectrum['FT'])
self.assertTrue('FTIntensity' in res.spectrum['FT'])
def testDictAsInput(self):
res = pymca_ft(xas_obj=self.xas_obj.to_dict())
self.assertTrue(isinstance(res, XASBase))
self.assertTrue(isinstance(res, XASObject))
self.assertTrue('FTRadius' in res.spectrum['FT'])
self.assertTrue('FTImaginary' in res.spectrum['FT'])
self.assertTrue('FTIntensity' in res.spectrum['FT'])
......@@ -61,7 +61,7 @@ class TestIO(unittest.TestCase):
def suite():
test_suite = unittest.TestSuite()
for ui in (TestIO, ):
for ui in (TestFTSingleSpectrum,):
test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(ui))
return test_suite
......
......@@ -31,14 +31,14 @@ import unittest
from xas.io import read_pymca_xas
from silx.io.url import DataUrl
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.types import PyMcaXAS, XASFactory
from xas.core.types import XASObject, XASFactory
import shutil
import tempfile
import os
class TestReadWrite(unittest.TestCase):
"""Test read function for spectrum and configuration"""
"""Test read function for spectra and configuration"""
def setUp(self):
self.outputdir = tempfile.mkdtemp()
self.outputfile = os.path.join(self.outputdir, 'output_file.h5')
......@@ -48,20 +48,20 @@ class TestReadWrite(unittest.TestCase):
def testReadSpectrum(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
res = read_pymca_xas(spectrum_url=DataUrl(file_path=data_file,
scheme='PyMca'))
self.assertTrue(isinstance(res, PyMcaXAS))
self.assertTrue('Mu' in res.spectrum)
self.assertTrue('Energy' in res.spectrum)
res = read_pymca_xas(spectra_url=DataUrl(file_path=data_file,
scheme='PyMca'))
self.assertTrue(isinstance(res, XASObject))
self.assertTrue('Mu' in res.spectra)
self.assertTrue('Energy' in res.spectra)
def testReadWriteH5(self):
"""Tset io relative to h5py"""
xas_obj = PyMcaXAS(configuration={'axis': 2},
spectrum={'Energy': 2.1, 'Mu': 0.2})
xas_obj = XASObject(configuration={'axis': 2},
spectrum={'Energy': 2.1, 'Mu': 0.2})
xas_obj.dump(self.outputfile)
self.assertTrue(os.path.exists(self.outputfile))
xas_obj2 = XASFactory.from_file(self.outputfile)
xas_obj2 = XASFactory.from_data_url(self.outputfile)
assert xas_obj2
self.assertEqual(xas_obj, xas_obj2)
......
......@@ -31,11 +31,11 @@ import unittest
import os
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.process.k_weight import pymca_k_weight
from xas.core.types import PyMcaXAS
from xas.core.types import PyMcaSpectrum
from xas.core.utils.pymca import read_spectrum
class TestIO(unittest.TestCase):
class TestKWeightSingleSpectrum(unittest.TestCase):
"""Make sure the process have valid io"""
def setUp(self):
self.config = {'SET_KWEIGHT': 2.0}
......@@ -44,7 +44,7 @@ class TestIO(unittest.TestCase):
spectrum['Energy'], spectrum['Mu'] = read_spectrum(data_file)