File: test_ccd_normalizer.py

package info (click to toggle)
xrayutilities 1.7.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,660 kB
  • sloc: python: 49,871; ansic: 4,585; makefile: 15
file content (64 lines) | stat: -rw-r--r-- 2,168 bytes parent folder | download
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# This file is part of xrayutilities.
#
# xrayutilities is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2015-2020 Dominik Kriegner <dominik.kriegner@gmail.com>

import os.path
import unittest

import numpy
import xrayutilities as xu

testfile = "pilatus100K.tif"
datadir = os.path.join(os.path.dirname(__file__), "data")
fullfilename = os.path.join(datadir, testfile)


@unittest.skipIf(
    not os.path.isfile(fullfilename),
    "additional test data needed (http://xrayutilities.sf.io)",
)
class TestCCD_Normalizer(unittest.TestCase):
    dshape = (2, 195, 487)
    dmax = 0.1
    dmin = -0.2
    nmax = 21

    @classmethod
    def setUpClass(cls):
        imgreader = xu.io.Pilatus100K()
        cls.img = imgreader.readImage(testfile, path=datadir)
        cls.ccddata = numpy.asarray((cls.img, 2 * cls.img))
        cls.fakedata = numpy.array(
            [(1.0, 10.0), (2.0, 21.0)],
            dtype=[("time", float), ("moni", float)],
        )
        cls.normalizer = xu.IntensityNormalizer(
            mon="moni", time="time", av_mon=1.0
        )
        cls.normdata = cls.normalizer(cls.fakedata, ccd=cls.ccddata)

    def test_datashape(self):
        self.assertTrue(numpy.all(self.dshape == self.normdata.shape))

    def test_datavalues(self):
        self.assertAlmostEqual(self.dmax, self.normdata.max(), places=10)
        self.assertAlmostEqual(self.dmin, self.normdata.min(), places=10)
        testhist, binedges = numpy.histogram(self.normdata, bins=30)
        self.assertEqual(self.nmax, testhist[-1])


if __name__ == "__main__":
    unittest.main()