コード例 #1
0
 def test_null_transform(self):
     self.pad = Pad(ident=1,
                    pad_geometry=self.pad_geometry,
                    detector_centre_mm=[0, 0, 0],
                    detector_unit_normal=[0, 0, 1])
     r = self.pad._get_pad_transform_matrix(detector_centre_mm=[0, 0, 0])
     np.testing.assert_allclose(r, np.eye(4))
コード例 #2
0
 def test_spherical_from_cartesian6(self):
     self.pad = Pad(ident=8,
                    pad_geometry=self.pad_geometry,
                    detector_centre_mm=[0, -1, 0],
                    detector_unit_normal=[0, 0, 1])
     self.assertAlmostEqual(self.pad.theta, np.pi / 2)
     self.assertAlmostEqual(self.pad.phi, -np.pi / 2)
コード例 #3
0
    def test_sa_rect7(self):
        # get solid angle of a rectangle
        pad_geometry = (0.5, 0.5, 0, 1.0, 1.0)  # x,y,z,w,h
        p = Pad(ident=385,
                pad_geometry=pad_geometry,
                detector_centre_mm=[0.0, 0.0, self.d_mm],
                detector_unit_normal=[0, 0, 1])
        sa1 = p.solid_angle()

        # get solid angle of a corresponding rectangle oriented towards the same
        # sphere centre
        p = Pad(ident=386,
                pad_geometry=pad_geometry,
                detector_centre_mm=[self.d_mm, 0.0, 0.0],
                detector_unit_normal=[1, 0, 0])
        sa2 = p.solid_angle()
        self.assertTrue(np.allclose(sa1, sa2))

        # get solid angle of a corresponding rectangle oriented towards the same
        # sphere centre
        p = Pad(ident=387,
                pad_geometry=pad_geometry,
                detector_centre_mm=[0.0, 0.0, -self.d_mm],
                detector_unit_normal=[0, 0, 1])
        sa3 = p.solid_angle()

        self.assertTrue(np.allclose(sa1, sa3))
コード例 #4
0
 def test_rotation(self):
     # Check that rotation matrix calculated to reorient pad matches the
     # expected coordinate system of the transformations.py module.
     self.pad = Pad(ident=1,
                    pad_geometry=self.pad_geometry,
                    detector_centre_mm=[0, 0, 0],
                    detector_unit_normal=[0, 1, 0])
     r = self.pad._get_pad_transform_matrix(detector_centre_mm=[0, 0, 0])
     # Matrix to rotate about an axis defined by a point and direction is
     # rotation_matrix(angle, direction, point=None):
     # To rotate from [0,0,1] to [0,1,0], rotate by 90deg about [1,0,0]
     tx_r1 = tx.rotation_matrix(-np.pi / 2, [1, 0, 0])
     tx_r2 = tx.rotation_matrix(np.pi / 2, [-1, 0, 0])
コード例 #5
0
    def test_sa_rect6(self):
        A, B = 0.0, 0.0
        a1, b1 = 1.0, 1.0
        # get solid angles of rectangles, none of which cross the origin
        sa1 = self.det._get_solid_angle(A, B, a1, b1, self.d_mm)

        # get solid angle of a corresponding rectangle crossing the origin
        pad_geometry = (0, 0, 0, 1.0, 1.0)  # x,y,z,w,h
        p = Pad(ident=384,
                pad_geometry=pad_geometry,
                detector_centre_mm=[0.5, 0.5, self.d_mm],
                detector_unit_normal=[0, 0, 1])
        sa5 = p.solid_angle()

        self.assertTrue(np.allclose(sa1, sa5))
コード例 #6
0
    def test_sa_rect5(self):
        A, B = 0.0, 0.0
        a1, b1 = 2.0, 1.0
        a2, b2 = 2.0, -1.0
        a3, b3 = -2.0, 1.0
        a4, b4 = -2.0, -1.0
        # get solid angles of rectangles, none of which cross the origin
        sa1 = self.det._get_solid_angle(A, B, a1, b1, self.d_mm)
        sa2 = self.det._get_solid_angle(A, B, a2, b2, self.d_mm)
        sa3 = self.det._get_solid_angle(A, B, a3, b3, self.d_mm)
        sa4 = self.det._get_solid_angle(A, B, a4, b4, self.d_mm)

        # get solid angle of a corresponding rectangle crossing the origin
        pad_geometry = (0, 0, 0, 4.0, 2.0)  # x,y,z,w,h
        p = Pad(ident=384,
                pad_geometry=pad_geometry,
                detector_centre_mm=[0, 0, self.d_mm],
                detector_unit_normal=[0, 0, 1])
        sa5 = p.solid_angle()

        self.assertTrue(np.allclose(sa1 + sa2 + sa3 + sa4, sa5))
コード例 #7
0
class PadTests(unittest.TestCase):
    def setUp(self):
        # pad lies along -ve z-axis (normal doesn't matter)
        self.pad_geometry = (0, 0, 0, 1, 1)  # x,y,z,w,h

    def test_null_transform(self):
        self.pad = Pad(ident=1,
                       pad_geometry=self.pad_geometry,
                       detector_centre_mm=[0, 0, 0],
                       detector_unit_normal=[0, 0, 1])
        r = self.pad._get_pad_transform_matrix(detector_centre_mm=[0, 0, 0])
        np.testing.assert_allclose(r, np.eye(4))

    @unittest.skip
    def test_rotation(self):
        # Check that rotation matrix calculated to reorient pad matches the
        # expected coordinate system of the transformations.py module.
        self.pad = Pad(ident=1,
                       pad_geometry=self.pad_geometry,
                       detector_centre_mm=[0, 0, 0],
                       detector_unit_normal=[0, 1, 0])
        r = self.pad._get_pad_transform_matrix(detector_centre_mm=[0, 0, 0])
        # Matrix to rotate about an axis defined by a point and direction is
        # rotation_matrix(angle, direction, point=None):
        # To rotate from [0,0,1] to [0,1,0], rotate by 90deg about [1,0,0]
        tx_r1 = tx.rotation_matrix(-np.pi / 2, [1, 0, 0])
        tx_r2 = tx.rotation_matrix(np.pi / 2, [-1, 0, 0])

    def test_spherical_from_cartesian1(self):
        self.pad = Pad(ident=1,
                       pad_geometry=self.pad_geometry,
                       detector_centre_mm=[0, 0, 1],
                       detector_unit_normal=[0, 0, 1])
        self.assertAlmostEqual(self.pad.theta, 0.0)

    def test_spherical_from_cartesian2(self):
        self.pad = Pad(ident=1,
                       pad_geometry=self.pad_geometry,
                       detector_centre_mm=[1, 0, 0],
                       detector_unit_normal=[0, 0, 1])
        self.assertAlmostEqual(self.pad.theta, np.pi / 2)
        self.assertAlmostEqual(self.pad.phi, 0.0)

    def test_spherical_from_cartesian3(self):
        self.pad = Pad(ident=1,
                       pad_geometry=self.pad_geometry,
                       detector_centre_mm=[0, 1, 0],
                       detector_unit_normal=[0, 0, 1])
        self.assertAlmostEqual(self.pad.theta, np.pi / 2)
        self.assertAlmostEqual(self.pad.phi, np.pi / 2)

    def test_spherical_from_cartesian4(self):
        self.pad = Pad(ident=1,
                       pad_geometry=self.pad_geometry,
                       detector_centre_mm=[0, 0, -1],
                       detector_unit_normal=[0, 0, 1])
        self.assertAlmostEqual(self.pad.theta, np.pi)

    def test_spherical_from_cartesian5(self):
        self.pad = Pad(ident=1,
                       pad_geometry=self.pad_geometry,
                       detector_centre_mm=[-1, 0, 0],
                       detector_unit_normal=[0, 0, 1])
        self.assertAlmostEqual(self.pad.theta, np.pi / 2)
        self.assertAlmostEqual(self.pad.phi, np.pi)

    def test_spherical_from_cartesian6(self):
        self.pad = Pad(ident=8,
                       pad_geometry=self.pad_geometry,
                       detector_centre_mm=[0, -1, 0],
                       detector_unit_normal=[0, 0, 1])
        self.assertAlmostEqual(self.pad.theta, np.pi / 2)
        self.assertAlmostEqual(self.pad.phi, -np.pi / 2)

    def tearDown(self):
        """The Pad class maintains an internal check to ensure pad objects
        aren't replaced. Clear the internal check state.

        """
        Pad.clear_pads()
コード例 #8
0
    def tearDown(self):
        """The Pad class maintains an internal check to ensure pad objects
        aren't replaced. Clear the internal check state.

        """
        Pad.clear_pads()
コード例 #9
0
 def setUp(self):
     Pad.clear_pads()
     self.det = Maia()
コード例 #10
0
 def test_spherical_from_cartesian1(self):
     self.pad = Pad(ident=1,
                    pad_geometry=self.pad_geometry,
                    detector_centre_mm=[0, 0, 1],
                    detector_unit_normal=[0, 0, 1])
     self.assertAlmostEqual(self.pad.theta, 0.0)