Exemplo n.º 1
0
 def test_select_lambda(self):
     """Verify the wavelength diffracted by a given hkl plane."""
     orientation = Orientation.cube()
     hkl = HklPlane(-1, -1, -1, self.ni)
     (the_lambda, theta) = select_lambda(hkl, orientation)
     self.assertAlmostEqual(the_lambda, 5.277, 3)
     self.assertAlmostEqual(theta * 180 / np.pi, 35.264, 3)
Exemplo n.º 2
0
 def test_IPF_color(self):
     o1 = Orientation.cube()  # 001 // Z
     o2 = Orientation.from_euler([35.264, 45., 0.])  # 011 // Z
     o3 = Orientation.from_euler([0., 54.736, 45.])  # 111 // Z
     orientations = [o1, o2, o3]
     targets = [np.array([1., 0., 0.]), np.array([0., 1., 0.]), np.array([0., 0., 1.])]
     for case in range(2):
         o = orientations[case]
         print(o)
         target = targets[case]
         col = o.get_ipf_colour()
         print(col)
         for i in range(3):
             self.assertAlmostEqual(col[i], target[i])
Exemplo n.º 3
0
    def test_gnomonic_projection_point(self):
        """Verify that the gnomonic projection of two diffracted points on a detector give access to the angle 
        between the lattice plane normals."""
        olivine = Lattice.orthorhombic(
            1.022, 0.596, 0.481)  # nm Barret & Massalski convention
        orientation = Orientation.cube()
        p1 = HklPlane(2, 0, -3, olivine)
        p2 = HklPlane(3, -1, -3, olivine)
        detector = RegArrayDetector2d(size=(512, 512),
                                      u_dir=[0, -1, 0],
                                      v_dir=[0, 0, -1])
        detector.pixel_size = 0.200  # mm, 0.1 mm with factor 2 binning
        detector.ucen = 235
        detector.vcen = 297
        detector.ref_pos = np.array([131., 0., 0.]) + \
                           (detector.size[0] / 2 - detector.ucen) * detector.u_dir * detector.pixel_size + \
                           (detector.size[1] / 2 - detector.vcen) * detector.v_dir * detector.pixel_size  # mm

        angle = 180 / np.pi * np.arccos(np.dot(p1.normal(), p2.normal()))
        # test the gnomonic projection for normal and not normal X-ray incidence
        for ksi in [0.0, 1.0]:  # deg
            Xu = np.array(
                [np.cos(ksi * np.pi / 180), 0.,
                 np.sin(ksi * np.pi / 180)])
            OC = detector.project_along_direction(
                Xu
            )  # C is the intersection of the direct beam with the detector
            K1 = diffracted_vector(p1, orientation, Xu=Xu)
            K2 = diffracted_vector(p2, orientation, Xu=Xu)
            R1 = detector.project_along_direction(K1, origin=[0., 0., 0.])
            R2 = detector.project_along_direction(K2, origin=[0., 0., 0.])
            OP1 = gnomonic_projection_point(R1, OC=OC)[0]
            OP2 = gnomonic_projection_point(R2, OC=OC)[0]
            hkl_normal1 = OP1 / np.linalg.norm(OP1)
            hkl_normal2 = (OP2 / np.linalg.norm(OP2))
            # the projection must give the normal to the diffracting plane
            for i in range(3):
                self.assertAlmostEqual(hkl_normal1[i], p1.normal()[i], 6)
                self.assertAlmostEqual(hkl_normal2[i], p2.normal()[i], 6)
            angle_gp = 180 / np.pi * np.arccos(np.dot(hkl_normal1,
                                                      hkl_normal2))
            self.assertAlmostEqual(angle, angle_gp, 6)