def test_HklPlane_normal(self): ZrO2 = Lattice.tetragonal(3.64, 5.27) p = HklPlane(1, 1, 1, ZrO2) n = p.normal() self.assertAlmostEqual(n[0], 0.635, 3) self.assertAlmostEqual(n[1], 0.635, 3) self.assertAlmostEqual(n[2], 0.439, 3)
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)
def plot_sst(self, ax=None, mk='s', ann=False): """ Create the inverse pole figure in the unit standard triangle. :param ax: a reference to a pyplot ax to draw the poles. :param mk: marker used to plot the poles (square by default). :param bool ann: Annotate the pole with the coordinates of the vector if True (False by default). """ # first draw the boundary of the symmetry domain limited by 3 hkl plane normals, called here A, B and C symmetry = self.lattice._symmetry if symmetry is Symmetry.cubic: sst_poles = [(0, 0, 1), (1, 0, 1), (1, 1, 1)] ax.axis([-0.05, 0.45, -0.05, 0.40]) elif symmetry is Symmetry.hexagonal: sst_poles = [(0, 0, 1), (2, -1, 0), (1, 0, 0)] ax.axis([-0.05, 1.05, -0.05, 0.6]) else: print('unssuported symmetry: %s' % symmetry) A = HklPlane(*sst_poles[0], lattice=self.lattice) B = HklPlane(*sst_poles[1], lattice=self.lattice) C = HklPlane(*sst_poles[2], lattice=self.lattice) self.plot_line_between_crystal_dir(A.normal(), B.normal(), ax=ax, col='k') self.plot_line_between_crystal_dir(B.normal(), C.normal(), ax=ax, col='k') self.plot_line_between_crystal_dir(C.normal(), A.normal(), ax=ax, col='k') # display the 3 crystal axes poles = [A, B, C] v_align = ['top', 'top', 'bottom'] for i in range(3): hkl = poles[i] c_dir = hkl.normal() c = c_dir + self.z c /= c[2] # SP'/SP = r/z with r=1 pole_str = '%d%d%d' % hkl.miller_indices() if symmetry is Symmetry.hexagonal: pole_str = '%d%d%d%d' % HklPlane.three_to_four_indices( *hkl.miller_indices()) ax.annotate(pole_str, (c[0], c[1] - (2 * (i < 2) - 1) * 0.01), xycoords='data', fontsize=12, horizontalalignment='center', verticalalignment=v_align[i]) # now plot the sample axis for grain in self.microstructure.grains: # move to the fundamental zone g = grain.orientation_matrix() # compute axis and apply SST symmetry if self.axis == 'Z': axis = self.z elif self.axis == 'Y': axis = self.y else: axis = self.x axis_rot = self.sst_symmetry(g.dot(axis)) label = '' if self.map_field == 'grain_id': label = 'grain ' + str(grain.id) self.plot_crystal_dir(axis_rot, mk=mk, col=self.get_color_from_field(grain), ax=ax, ann=ann, lab=label) if self.verbose: print('plotting %s in crystal CS: %s' % (self.axis, axis_rot)) ax.axis('off') ax.set_title('%s-axis SST inverse %s projection' % (self.axis, self.proj))
def test_HklPlane(self): p = HklPlane(1, 1, 1) n = p.normal() self.assertEqual(np.linalg.norm(n), 1)