test_input_information.py 3.49 KB
Newer Older
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
30
31
# 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__ = "07/21/2021"


from est.io.utils.information import InputInformation
from est.io.utils.information import SpecInputInformation
32
from est.app.utils import get_xas_obj
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from silx.io.url import DataUrl
import unittest
import os

try:
    import PyMca5
except ImportError:
    has_pymca = False
else:
    has_pymca = True
    from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR


@unittest.skipIf(has_pymca is False, "PyMca5 is not installed")
class TestInputInformation(unittest.TestCase):
    """Test the TestInputInformation"""

    def testSpecInput(self):
        """Test the different way of providing a spec file entry are
        all valid"""
        self.data_input_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
54
        # first way providing directly url
55
56
57
58
59
60
61
62
63
64
65
66
        input_information_1 = InputInformation(
            spectra_url=DataUrl(
                file_path=self.data_input_file,
                scheme="PyMca",
                data_path="Column 1",
            ),
            channel_url=DataUrl(
                file_path=self.data_input_file,
                scheme="PyMca",
                data_path="Column 2",
            ),
        )
67
68
69
        xas_obj_1 = get_xas_obj(input_information_1)
        self.assertTrue(input_information_1.channel_url is not None)
        self.assertTrue(xas_obj_1.energy is not None)
70

71
        # second way providing only a spec file
72
73
74
75
76
        input_information_2 = InputInformation(
            spec_input=SpecInputInformation(
                spec_file=self.data_input_file,
                energy_abs_col_name="Column 1",
                input_abs_col_name="Column 2",
77
            ),
78
        )
79
80
81
        xas_obj_2 = get_xas_obj(input_information_2)
        self.assertTrue(xas_obj_2.energy is not None)
        self.assertTrue(xas_obj_2.spectra.data.flat[0] is not None)
82

83
84
85
86
87
88
89
90
91
        # third way providing a spec file and column names
        input_information_3 = InputInformation(
            spec_input=SpecInputInformation(
                spec_file=self.data_input_file,
            ),
        )
        xas_obj_3 = get_xas_obj(input_information_3)
        self.assertTrue(xas_obj_3.energy is not None)
        self.assertTrue(xas_obj_3.spectra.data.flat[0] is not None)