diff --git a/doc/tutorials/example_larch.ows b/doc/tutorials/example_larch.ows index 660be161d03d4440dfd218e6b531102d5ae8485a..7e792a797a21c3fe146f1ec69551236ff69ffbb8 100644 --- a/doc/tutorials/example_larch.ows +++ b/doc/tutorials/example_larch.ows @@ -29,8 +29,8 @@ - {'_configuration_url_setting': '', '_energy_url_setting': '', '_input_file_setting': '/users/payno/.local/share/virtualenvs/xas_venv/lib/python3.7/site-packages/PyMca5/PyMcaData/EXAFS_Cu.dat', '_spectra_url_setting': '', 'controlAreaVisible': True, 'savedWidgetGeometry': b'\x01\xd9\xd0\xcb\x00\x03\x00\x00\x00\x00\x04\xb6\x00\x00\x01p\x00\x00\x06K\x00\x00\x02\xcb\x00\x00\x04\xb9\x00\x00\x01\x8d\x00\x00\x06H\x00\x00\x02\xc8\x00\x00\x00\x00\x00\x00\x00\x00\x07\x80\x00\x00\x04\xb9\x00\x00\x01\x8d\x00\x00\x06H\x00\x00\x02\xc8', '__version__': 1} - {'_output_file_setting': '/tmp/tmpwjo9ijrc/output.h5', 'controlAreaVisible': True, 'savedWidgetGeometry': b'\x01\xd9\xd0\xcb\x00\x03\x00\x00\x00\x00\x031\x00\x00\x01\xdc\x00\x00\x04H\x00\x00\x02\x7f\x00\x00\x034\x00\x00\x01\xf9\x00\x00\x04E\x00\x00\x02|\x00\x00\x00\x00\x00\x00\x00\x00\x07\x80\x00\x00\x034\x00\x00\x01\xf9\x00\x00\x04E\x00\x00\x02|', '__version__': 1} + {'_configuration_url_setting': '', '_energy_url_setting': '', '_input_file_setting': '', '_spectra_url_setting': '', 'controlAreaVisible': True, 'savedWidgetGeometry': b'\x01\xd9\xd0\xcb\x00\x03\x00\x00\x00\x00\x04\xb6\x00\x00\x01p\x00\x00\x06K\x00\x00\x02\xcb\x00\x00\x04\xb9\x00\x00\x01\x8d\x00\x00\x06H\x00\x00\x02\xc8\x00\x00\x00\x00\x00\x00\x00\x00\x07\x80\x00\x00\x04\xb9\x00\x00\x01\x8d\x00\x00\x06H\x00\x00\x02\xc8', '__version__': 1} + {'_output_file_setting': '', 'controlAreaVisible': True, 'savedWidgetGeometry': b'\x01\xd9\xd0\xcb\x00\x03\x00\x00\x00\x00\x031\x00\x00\x01\xdc\x00\x00\x04H\x00\x00\x02\x7f\x00\x00\x034\x00\x00\x01\xf9\x00\x00\x04E\x00\x00\x02|\x00\x00\x00\x00\x00\x00\x00\x00\x07\x80\x00\x00\x034\x00\x00\x01\xf9\x00\x00\x04E\x00\x00\x02|', '__version__': 1} {'_larchSettings': {}, 'controlAreaVisible': True, 'savedWidgetGeometry': b'\x01\xd9\xd0\xcb\x00\x03\x00\x00\x00\x00\x01\xb0\x00\x00\x00\x8b\x00\x00\x05\xbc\x00\x00\x03\xbb\x00\x00\x01\xb3\x00\x00\x00\xa8\x00\x00\x05\xb9\x00\x00\x03\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x07\x80\x00\x00\x01\xb3\x00\x00\x00\xa8\x00\x00\x05\xb9\x00\x00\x03\xb8', '__version__': 1} {'_settings': {}, 'controlAreaVisible': True, 'savedWidgetGeometry': b'\x01\xd9\xd0\xcb\x00\x03\x00\x00\x00\x00\x08\xd0\x00\x00\x00\xfc\x00\x00\x0c\xb9\x00\x00\x03\xef\x00\x00\x08\xd3\x00\x00\x01\x19\x00\x00\x0c\xb6\x00\x00\x03\xec\x00\x00\x00\x01\x00\x00\x00\x00\x07\x80\x00\x00\x08\xd3\x00\x00\x01\x19\x00\x00\x0c\xb6\x00\x00\x03\xec', '__version__': 1} {'_larchSettings': {'kmin': 0, 'kmax': 20, 'kweight': 0, 'dk': 3, 'dk2': None, 'with_phase': False, 'window': 'kaiser', 'rmax_out': 10.0, 'nfft': 2048, 'kstep': 0.05}, 'controlAreaVisible': True, 'savedWidgetGeometry': b'\x01\xd9\xd0\xcb\x00\x03\x00\x00\x00\x00\x01\xc1\x00\x00\x00\xa9\x00\x00\x05\xaa\x00\x00\x03\x9c\x00\x00\x01\xc4\x00\x00\x00\xc6\x00\x00\x05\xa7\x00\x00\x03\x99\x00\x00\x00\x00\x00\x00\x00\x00\x07\x80\x00\x00\x01\xc4\x00\x00\x00\xc6\x00\x00\x05\xa7\x00\x00\x03\x99', '__version__': 1} diff --git a/doc/tutorials/example_pymca.ows b/doc/tutorials/example_pymca.ows index 2acbd7111dc230c0a6f0c1404ab74126209439f8..a41e2a5a973e1e3cbb63513d3b864c7f6343011f 100644 --- a/doc/tutorials/example_pymca.ows +++ b/doc/tutorials/example_pymca.ows @@ -33,8 +33,8 @@ - {'_configuration_url_setting': '', '_energy_url_setting': '', '_input_file_setting': '/users/payno/.local/share/virtualenvs/xas_venv/lib/python3.7/site-packages/PyMca5/PyMcaData/EXAFS_Cu.dat', '_spectra_url_setting': '', 'controlAreaVisible': True, 'savedWidgetGeometry': b'\x01\xd9\xd0\xcb\x00\x03\x00\x00\x00\x00\x04\xb6\x00\x00\x01p\x00\x00\x06K\x00\x00\x02\xcb\x00\x00\x04\xb9\x00\x00\x01\x8d\x00\x00\x06H\x00\x00\x02\xc8\x00\x00\x00\x00\x00\x00\x00\x00\x07\x80\x00\x00\x04\xb9\x00\x00\x01\x8d\x00\x00\x06H\x00\x00\x02\xc8', '__version__': 1} - {'_output_file_setting': '/tmp/tmpwjo9ijrc/output.h5', 'controlAreaVisible': True, 'savedWidgetGeometry': b'\x01\xd9\xd0\xcb\x00\x03\x00\x00\x00\x00\x031\x00\x00\x01\xdc\x00\x00\x04H\x00\x00\x02\x7f\x00\x00\x034\x00\x00\x01\xf9\x00\x00\x04E\x00\x00\x02|\x00\x00\x00\x00\x00\x00\x00\x00\x07\x80\x00\x00\x034\x00\x00\x01\xf9\x00\x00\x04E\x00\x00\x02|', '__version__': 1} + {'_configuration_url_setting': '', '_energy_url_setting': '', '_input_file_setting': '', '_spectra_url_setting': '', 'controlAreaVisible': True, 'savedWidgetGeometry': b'\x01\xd9\xd0\xcb\x00\x03\x00\x00\x00\x00\x04\xb6\x00\x00\x01p\x00\x00\x06K\x00\x00\x02\xcb\x00\x00\x04\xb9\x00\x00\x01\x8d\x00\x00\x06H\x00\x00\x02\xc8\x00\x00\x00\x00\x00\x00\x00\x00\x07\x80\x00\x00\x04\xb9\x00\x00\x01\x8d\x00\x00\x06H\x00\x00\x02\xc8', '__version__': 1} + {'_output_file_setting': '', 'controlAreaVisible': True, 'savedWidgetGeometry': b'\x01\xd9\xd0\xcb\x00\x03\x00\x00\x00\x00\x031\x00\x00\x01\xdc\x00\x00\x04H\x00\x00\x02\x7f\x00\x00\x034\x00\x00\x01\xf9\x00\x00\x04E\x00\x00\x02|\x00\x00\x00\x00\x00\x00\x00\x00\x07\x80\x00\x00\x034\x00\x00\x01\xf9\x00\x00\x04E\x00\x00\x02|', '__version__': 1} {'_pymcaSettings': {'JumpNormalizationMethod': 'Constant', 'E0MinValue': None, 'E0MaxValue': None, 'E0Method': 'Auto - 5pt SG', 'E0Value': 200.0, 'PreEdge': {'Method': 'Polynomial', 'Polynomial': 'Parabolic', 'Regions': [-100.0, -40.0]}, 'PostEdge': {'Method': 'Polynomial', 'Polynomial': 'Linear', 'Regions': [10.0, 300.0]}}, 'controlAreaVisible': True, 'savedWidgetGeometry': b'\x01\xd9\xd0\xcb\x00\x03\x00\x00\x00\x00\x03\xd0\x00\x00\x02\x10\x00\x00\x07\xb9\x00\x00\x05\x03\x00\x00\x03\xd3\x00\x00\x02-\x00\x00\x07\xb6\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x80\x00\x00\x03\xd3\x00\x00\x02-\x00\x00\x07\xb6\x00\x00\x05\x00', '__version__': 1} {'_larchSettings': {'KMin': 2.0, 'KMax': 20.0, 'KWeight': 2, 'Knots': {'Number': 4, 'Values': [5.6, 9.2, 12.8, 16.4], 'Orders': [3, 3, 3, 3, 3]}}, 'controlAreaVisible': True, 'savedWidgetGeometry': b'\x01\xd9\xd0\xcb\x00\x03\x00\x00\x00\x00\x03`\x00\x00\x00\xe2\x00\x00\x07I\x00\x00\x03\xd5\x00\x00\x03c\x00\x00\x00\xff\x00\x00\x07F\x00\x00\x03\xd2\x00\x00\x00\x00\x00\x00\x00\x00\x07\x80\x00\x00\x03c\x00\x00\x00\xff\x00\x00\x07F\x00\x00\x03\xd2', '__version__': 1} {'_kWeightSetting': 3, 'controlAreaVisible': True, 'savedWidgetGeometry': b'\x01\xd9\xd0\xcb\x00\x03\x00\x00\x00\x00\n\xd6\x00\x00\x01\xd5\x00\x00\x0b\xa3\x00\x00\x02\x86\x00\x00\n\xd9\x00\x00\x01\xf2\x00\x00\x0b\xa0\x00\x00\x02\x83\x00\x00\x00\x01\x00\x00\x00\x00\x07\x80\x00\x00\n\xd9\x00\x00\x01\xf2\x00\x00\x0b\xa0\x00\x00\x02\x83', '__version__': 1} diff --git a/xas/core/process/pymca/exafs.py b/xas/core/process/pymca/exafs.py index 0df788461f1ba45ae0938e85ba3a36b18e4f1210..b811d27026130429b7594ed033243b85adbd1ec6 100644 --- a/xas/core/process/pymca/exafs.py +++ b/xas/core/process/pymca/exafs.py @@ -97,6 +97,10 @@ def process_spectr_exafs(spectrum, configuration, overwrite=True, callback=None, callback() res_spectrum = Spectrum.from_dict(ddict=ddict) + # store k values for larch compatibilities + res_spectrum.k = kValues + # chi not defined, failed compatibility larch / pymca + # res_spectrum.chi = chi def get_output(original_spec, res_spec): if overwrite: diff --git a/xas/core/process/test/test_workflow.py b/xas/core/process/test/test_workflow.py index 0e2cdbe0c11a901c04289e2f9778d773cfc6e145..4da30ac9bafe3278bbf3b85a885b4ee37547f5f9 100644 --- a/xas/core/process/test/test_workflow.py +++ b/xas/core/process/test/test_workflow.py @@ -24,18 +24,101 @@ # ###########################################################################*/ __authors__ = ["H. Payno"] __license__ = "MIT" -__date__ = "05/08/2019" +__date__ = "07/08/2019" import unittest +import os +import tempfile +import shutil +from xas.core.types import Spectrum, XASObject +from xas.core.io import XASWriter +try: + import larch +except ImportError: + has_larch = False +else: + has_larch = True + from xas.core.process.larch.autobk import Larch_autobk + from xas.core.process.larch.pre_edge import Larch_pre_edge + from xas.core.process.larch.xftf import Larch_xftf +try: + import PyMca5 +except ImportError: + has_pymca = False +else: + has_pymca = True + from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR + from xas.io.utils.pymca import read_spectrum + from xas.core.process.pymca.normalization import PyMca_normalization + from xas.core.process.pymca.exafs import PyMca_exafs + from xas.core.process.pymca.ft import PyMca_ft + from xas.core.process.pymca.k_weight import PyMca_k_weight -# class TestMeldWorkflow_1(unittest.TestCase): -# """ -# Test the following workflow: read_xmu -> pymca normalize -> -# """ -# def + +@unittest.skipIf(not has_pymca or not has_larch, 'pymca and/or larch not installed') +class TestMeldWorkflow(unittest.TestCase): + """ + Test the following workflow: read_xmu -> pymca normalize -> + """ + def setUp(self): + data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat") + energy, mu = read_spectrum(data_file) + self.spectrum = Spectrum(energy=energy, mu=mu) + self.xas_obj = XASObject(energy=energy, spectra=(self.spectrum,), + dim1=1, dim2=1) + assert self.xas_obj.linked_h5_file is not None + self.output_dir = tempfile.mkdtemp() + self.h5_file = os.path.join(self.output_dir, 'output_file.h5') + self.configuration_exafs = { + "Knots": {"Values": (1, 2, 5), "Number": 3, 'Orders': [3, 3, 3]}, + 'KMin': 0, + 'KMax': 2.3, + } + def tearDown(self): + shutil.rmtree(self.output_dir) + + def test_workflow_normalize_autobk_kweight_ft(self): + """Test the following workflow: + pymca normalize -> larch autobk -> kweight -> pymca ft + """ + self.xas_obj.configuration = {'EXAFS': self.configuration_exafs} + # pymca normalization + out = PyMca_normalization()(xas_obj=self.xas_obj) + # larch autobk + out = Larch_autobk()(xas_obj=out) + # k weight + kweight_process = PyMca_k_weight() + kweight_process.setConfiguration({'k_weight': 0}) + out = kweight_process(xas_obj=out) + # pymca ft + out = PyMca_ft()(xas_obj=out) + + self.assertTrue(out.spectra[0].ft.intensity is not None) + self.assertTrue(len(out.spectra[0].ft.intensity) > 1) + + def test_workflow_preedge_exafs_xftf(self): + """Test the following workflow: + larch pre_edge -> pymca exafs -> larch xftf + """ + # larch pre edge + out = Larch_pre_edge()(self.xas_obj) + # pymca exafs + exafs = PyMca_exafs() + + exafs.setConfiguration(self.configuration_exafs) + out = exafs(xas_obj=out) + # for now we cannot link xftf because chi is not set by pymca exafs + # # larch xftf + # # TODO: look, k and/or chi not specified + # out = Larch_xftf()(xas_obj=out) + + writer = XASWriter() + writer.output_file = self.h5_file + writer(out) def suite(): test_suite = unittest.TestSuite() - # TODO: add test melting pymca process and larch process + for ui in (TestMeldWorkflow, ): + test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(ui)) return test_suite