test_ft.py 3.29 KB
Newer Older
payno's avatar
payno committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2017-2019 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__ = "06/11/2019"


30
import os
payno's avatar
payno committed
31
import unittest
payno's avatar
payno committed
32
from est.core.types import XASObject, Spectrum
payno's avatar
payno committed
33

34
try:
payno's avatar
PEP8    
payno committed
35
    import PyMca5  # noqa
36
37
38
39
40
except ImportError:
    has_pymca = False
else:
    has_pymca = True
    from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
payno's avatar
payno committed
41
42
43
44
    from est.core.process.pymca.exafs import pymca_exafs
    from est.core.process.pymca.ft import pymca_ft
    from est.core.process.pymca.k_weight import pymca_k_weight
    from est.core.process.pymca.normalization import pymca_normalization
45
    from est.io.utils.spec import read_spectrum
payno's avatar
payno committed
46
47


payno's avatar
payno committed
48
@unittest.skipIf(has_pymca is False, "PyMca5 is not installed")
49
class TestFTSingleSpectrum(unittest.TestCase):
payno's avatar
payno committed
50
    """Make sure the process have valid io"""
payno's avatar
payno committed
51

52
    def setUp(self):
payno's avatar
payno committed
53
        data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
payno's avatar
payno committed
54
55
56
57
58
        energy, mu = read_spectrum(
            data_file,
            energy_col_name="Column 1",
            absorption_col_name="Column 2",
        )
59
        self.spectrum = Spectrum(energy=energy, mu=mu)
payno's avatar
payno committed
60
61
62
        self.xas_obj = XASObject(
            energy=energy, spectra=(self.spectrum,), dim1=1, dim2=1
        )
63
64
65
        # preproc xas obj
        self.xas_obj = pymca_normalization(xas_obj=self.xas_obj)
        self.xas_obj = pymca_exafs(xas_obj=self.xas_obj)
payno's avatar
payno committed
66
        self.xas_obj = pymca_k_weight(xas_obj=self.xas_obj)
67
68
69

    def testPyMcaXASAsInput(self):
        res = pymca_ft(xas_obj=self.xas_obj)
70
        self.assertTrue(isinstance(res, XASObject))
payno's avatar
payno committed
71
72
73
        self.assertTrue("FTRadius" in res.spectra.data.flat[0]["FT"])
        self.assertTrue("FTImaginary" in res.spectra.data.flat[0]["FT"])
        self.assertTrue("FTIntensity" in res.spectra.data.flat[0]["FT"])
74
75
76

    def testDictAsInput(self):
        res = pymca_ft(xas_obj=self.xas_obj.to_dict())
77
        self.assertTrue(isinstance(res, XASObject))
payno's avatar
payno committed
78
79
80
        self.assertTrue("FTRadius" in res.spectra.data.flat[0]["FT"])
        self.assertTrue("FTImaginary" in res.spectra.data.flat[0]["FT"])
        self.assertTrue("FTIntensity" in res.spectra.data.flat[0]["FT"])