GoniometerTest.py 2.1 KB
Newer Older
1
2
3
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
5
#   NScD Oak Ridge National Laboratory, European Spallation Source,
#   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
# SPDX - License - Identifier: GPL - 3.0 +
7
8
9
10
import unittest
from mantid.kernel import DateAndTime
from mantid.geometry import Goniometer
from testhelpers import can_be_instantiated
Leal, Ricardo's avatar
Leal, Ricardo committed
11
from testhelpers import run_algorithm
12
13
import numpy as np

14

15
class GoniometerTest(unittest.TestCase):
Leal, Ricardo's avatar
Leal, Ricardo committed
16
    
17
18
19
20
21
    def test_Goniometer_can_be_instantiated(self):
        self.assertTrue(can_be_instantiated(Goniometer))

    def test_getEulerAngles(self):
        g = Goniometer()
22
23
24
        self.assertEqual(g.getEulerAngles()[0], 0)
        self.assertEqual(g.getEulerAngles()[1], 0)
        self.assertEqual(g.getEulerAngles()[2], 0)
25
        
Leal, Ricardo's avatar
Leal, Ricardo committed
26
    def test_setR_getR(self):
27
28
29
        g = Goniometer()
        r = np.array([(1., 0., 0.), (0., 0., 1.), (0., -1., 0.)])
        g.setR(r)
30
        self.assertTrue((g.getR() == r).all())
Leal, Ricardo's avatar
Leal, Ricardo committed
31
32
33
34
35
36
37
38
39
40
    
    def test_default_goniometer(self):
        """
        Default goniometer is the identity matrix
        """
        alg = run_algorithm('CreateWorkspace', DataX=[1, 2, 3, 4, 5], DataY=[1, 2, 3, 4, 5], NSpec=1, child=True)
        ws = alg.getProperty("OutputWorkspace").value
        run = ws.run()
        g = run.getGoniometer()
        self.assertTrue(isinstance(g, Goniometer))
41
        self.assertTrue((g.getR() == np.identity(3)).all())
Leal, Ricardo's avatar
Leal, Ricardo committed
42
43
44
45
46
47
48
49
50
51
52
53
54
        
    def test_change_default_goniometer(self):
        """
        Get the default gonimoter
        Set it to something else and make sure it was successfully changed
        """
        alg = run_algorithm('CreateWorkspace', DataX=[1, 2, 3, 4, 5], DataY=[1, 2, 3, 4, 5], NSpec=1, child=True)
        ws = alg.getProperty("OutputWorkspace").value
        run = ws.run()
        g = run.getGoniometer()
        # change the matrix:
        r = np.array([(1., 0., 0.), (0., 0., 1.), (0., -1., 0.)])
        g.setR(r)
55
        self.assertTrue((g.getR() == r).all())
56
57
58
59
      

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