test_k_weight.py 2.81 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
31
import unittest
payno's avatar
payno committed
32
from est.core.types import Spectrum, XASObject
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
    from est.core.process.pymca.k_weight import pymca_k_weight
42

payno's avatar
payno committed
43
    from est.core.process.pymca.normalization import pymca_normalization
44
    from est.io.utils.spec import read_spectrum
payno's avatar
payno committed
45
46


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

51
    def setUp(self):
payno's avatar
payno committed
52
        self.config = {
payno's avatar
payno committed
53
54
            "SET_KWEIGHT": 2.0,
            "EXAFS": {"Knots": {"Values": (1, 2, 5), "Number": 3, "Orders": [3, 3, 3]}},
payno's avatar
payno committed
55
56
        }

57
        data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
payno's avatar
payno committed
58
59
60
61
62
        energy, mu = read_spectrum(
            data_file,
            energy_col_name="Column 1",
            absorption_col_name="Column 2",
        )
63

64
        self.spectrum = Spectrum(energy=energy, mu=mu)
payno's avatar
payno committed
65
66
67
68
69
70
71
        self.xas_obj = XASObject(
            energy=energy,
            spectra=(self.spectrum,),
            configuration=self.config,
            dim1=1,
            dim2=1,
        )
72
73

    def testWithXASObjAsInput(self):
payno's avatar
payno committed
74
        self.xas_obj = pymca_normalization(self.xas_obj)
75
76
77
        pymca_k_weight(xas_obj=self.xas_obj)

    def testWithDictAsInput(self):
payno's avatar
payno committed
78
        self.xas_obj = pymca_normalization(self.xas_obj)
79
        pymca_k_weight(xas_obj=self.xas_obj.to_dict())