def test_topotomo_tilts(self): # tests cases from ma2285 experiment on id11, omega offset = -90 T = np.array([[0, -1, 0], [1, 0, 0], [0, 0, 1]]) al = Lattice.from_symbol('Al') p = HklPlane(0, 0, 2, lattice=al) rod = [0.1449, -0.0281, 0.0616] o = Orientation.from_rodrigues(rod) (ut, lt) = o.topotomo_tilts(p, T) self.assertAlmostEqual(180 / np.pi * ut, 2.236, 3) self.assertAlmostEqual(180 / np.pi * lt, 16.615, 3) # use test case from AlLi_sam8_dct_cen_ p = HklPlane(2, 0, 2, lattice=al) rod = [0.0499, -0.3048, 0.1040] o = Orientation.from_rodrigues(rod) (ut, lt) = o.topotomo_tilts(p, T) self.assertAlmostEqual(180 / np.pi * ut, -11.04, 2) self.assertAlmostEqual(180 / np.pi * lt, -0.53, 2) # test case from ma3921 T = Orientation.compute_instrument_transformation_matrix(-1.2, 0.7, 90) Ti7Al = Lattice.hexagonal(0.2931, 0.4694) # nm (h, k, l) = HklPlane.four_to_three_indices(-1, 2, -1, 0) p = HklPlane(h, k, l, Ti7Al) o = Orientation.from_rodrigues([0.7531, 0.3537, 0.0621]) (ut, lt) = o.topotomo_tilts(p, T) self.assertAlmostEqual(180 / np.pi * ut, 11.275, 2) self.assertAlmostEqual(180 / np.pi * lt, -4.437, 2)
def test_topotomo_tilts(self): al = Lattice.from_symbol('Al') p = HklPlane(0, 0, 2, lattice=al) rod = [0.1449, -0.0281, 0.0616] o = Orientation.from_rodrigues(rod) (ut, lt) = o.topotomo_tilts(p) self.assertAlmostEqual(180 / np.pi * ut, 2.236, 3) self.assertAlmostEqual(180 / np.pi * lt, -16.615, 3) # use test case from AlLi_sam8_dct_cen_ p = HklPlane(2, 0, 2, lattice=al) rod = [0.0499, -0.3048, 0.1040] o = Orientation.from_rodrigues(rod) (ut, lt) = o.topotomo_tilts(p) self.assertAlmostEqual(180 / np.pi * ut, -11.04, 2) self.assertAlmostEqual(180 / np.pi * lt, 0.53, 2)
def load_grain(self, gid=1): print('loading grain from file 4_grains/phase_01/grain_%04d.mat' % gid) with h5py.File( os.path.join(self.exp.get_sample().data_dir, '4_grains/phase_01/grain_%04d.mat' % gid)) as gmat: g = Grain(gid, Orientation.from_rodrigues(gmat['R_vector'][()])) g.om_exp = gmat['om_exp'][0, :] g.uv_exp = gmat['uv_exp'][:, :] g.center = gmat['center'][:, 0] try: ref_included = gmat['proj/included'][0][0] g.included = gmat[ref_included][0, :] ref_ondet = gmat['proj/ondet'][0][0] g.ondet = gmat[ref_ondet][0, :] # grab the projection stack ref_stack = gmat['proj']['stack'][0][0] g.stack_exp = gmat[ref_stack][()].transpose( 1, 2, 0) # now in [ndx, u, v] form g.hklsp = gmat['allblobs/hklsp'][:, :] except AttributeError: # classic file organization g.included = gmat['proj/included'][0, :] g.ondet = gmat['proj/ondet'][0, :] g.stack_exp = gmat['proj/stack'][()].transpose( 1, 2, 0) # now in [ndx, u, v] form # for the Ti7AL data set, we have to hack around the DCT + TT work in progress #ref_hklsp = gmat['allblobs/hklsp'][()][0][0] #g.hklsp = gmat[ref_hklsp][:, :] g.hklsp = gmat['allblobs/hklsp'][:, :] self.grain = g if self.verbose: print('experimental proj stack shape: {}'.format( g.stack_exp.shape))
def test_apply_orientation_to_actor(self): o = Orientation.from_rodrigues([0.0885, 0.3889, 0.3268]) Bt = o.orientation_matrix().transpose( ) # to go from crystal to lab coordinate Vl = Bt.Vc l = Lattice.cubic(1.0) (a, b, c) = l._lengths grid = lattice_grid(l) actor = lattice_edges(grid) apply_orientation_to_actor(actor, o) m = actor.GetUserTransform().GetMatrix() for i in range(3): for j in range(3): self.assertEqual(Bt[i, j], m.GetElement(i, j))
def test_Bragg_condition(self): al = Lattice.from_symbol('Al') p = HklPlane(0, 0, 2, lattice=al) lambda_keV = 42 lambda_nm = lambda_keV_to_nm(lambda_keV) rod = [0.1449, -0.0281, 0.0616] o = Orientation.from_rodrigues(rod) (w1, w2) = o.dct_omega_angles(p, lambda_keV, verbose=False) # test the two solution of the rotating crystal for omega in (w1, w2): alpha = o.compute_XG_angle(p, omega, verbose=True) theta_bragg = p.bragg_angle(lambda_keV) self.assertAlmostEqual(alpha, 180 / np.pi * (np.pi / 2 - theta_bragg))
def get_color_from_field(self, grain): """Get the color of the given grain according to the chosen field. This function will return the color associated with the given grain. Depending on how the pole figure has been configured (see the `set_map_field` function), it will be obtained from: * the grain id, according to the `Microstructure.rand_cmap` function * ipf the colour will reflect the orientation according to the IPF coloring scheme * the field value mapped on a pyplot color map if the lut field of the PoleFigure instance is a string. * a color directly read from the lut field; in this case the field value must reflect the category of the given grain. :param grain: the `Grain` instance. :return: the color as a 3 element numpy array representing the rgb values. """ if self.map_field: if self.map_field == 'grain_id': col = Microstructure.rand_cmap().colors[grain['idnumber']] elif self.map_field == 'ipf': if self.axis == 'X': axis = np.array([1., 0., 0.]) elif self.axis == 'Y': axis = np.array([0., 1., 0.]) else: axis = np.array([0., 0., 1.]) col = Orientation.from_rodrigues( grain['orientation']).get_ipf_colour(axis=axis) else: # retrieve the position of the grain in the list rank = self.microstructure.get_grain_ids().tolist().index( grain['idnumber']) if type(self.lut) is str: # get the color map from pyplot color_map = cm.get_cmap(self.lut, 256) # use the field value for this grain and the field range bounds color = int(255 * max( min((self.field[rank] - self.field_min_level) / float(self.field_max_level - self.field_min_level), 1.0), 0.0)) col = color_map(np.arange(256))[color] else: col = self.lut[ self.field[rank]] # directly access the color return col else: return np.array([0., 0., 0.])
def setUp(self): """testing the laue module:""" self.ni = Lattice.from_symbol('Ni') self.al = Lattice.face_centered_cubic(0.40495) self.g4 = Orientation.from_rodrigues( [0.0499199, -0.30475322, 0.10396082]) self.spots = np.array([[76, 211], [77, 281], [86, 435], [90, 563], [112, 128], [151, 459], [151, 639], [161, 543], [170, 325], [176, 248], [189, 70], [190, 375], [213, 670], [250, 167], [294, 54], [310, 153], [323, 262], [358, 444], [360, 507], [369, 163], [378, 535], [384, 86], [402, 555], [442, 139], [444, 224], [452, 565], [476, 292], [496, 88], [501, 547], [514, 166], [522, 525], [531, 433], [536, 494], [559, 264], [581, 57], [625, 168], [663, 607], [679, 69], [686, 363], [694, 240], [703, 315], [728, 437], [728, 518], [743, 609], [756, 128], [786, 413], [789, 271], [790, 534], [791, 205], [818, 123]])
def test_dct_omega_angles(self): # test with a BCC Titanium lattice lambda_keV = 30 lambda_nm = 1.2398 / lambda_keV a = 0.3306 # lattice parameter in nm Ti_bcc = Lattice.cubic(a) (h, k, l) = (0, 1, 1) hkl = HklPlane(h, k, l, lattice=Ti_bcc) o = Orientation.from_euler((103.517, 42.911, 266.452)) theta = hkl.bragg_angle(lambda_keV, verbose=False) gt = o.orientation_matrix( ) # our B (here called gt) corresponds to g^{-1} in Poulsen 2004 A = h * gt[0, 0] + k * gt[1, 0] + l * gt[2, 0] B = -h * gt[0, 1] - k * gt[1, 1] - l * gt[2, 1] C = -2 * a * np.sin( theta )**2 / lambda_nm # the minus sign comes from the main equation Delta = 4 * (A**2 + B**2 - C**2) self.assertEqual(Delta > 0, True) t1 = (B - 0.5 * np.sqrt(Delta)) / (A + C) t2 = (B + 0.5 * np.sqrt(Delta)) / (A + C) # verifying A cos(w) + B sin(w) = C:' for t in (t1, t2): x = A * (1 - t**2) / (1 + t**2) + B * 2 * t / (1 + t**2) self.assertAlmostEqual(x, C, 2) # verifying (A + C) * t**2 - 2 * B * t + (C - A) = 0' for t in (t1, t2): self.assertAlmostEqual((A + C) * t**2 - 2 * B * t + (C - A), 0.0, 2) (w1, w2) = o.dct_omega_angles(hkl, lambda_keV, verbose=False) self.assertAlmostEqual(w1, 196.709, 2) self.assertAlmostEqual(w2, 28.334, 2) # test with an FCC Aluminium-Lithium lattice a = 0.40495 # lattice parameter in nm Al_fcc = Lattice.face_centered_cubic(a) hkl = HklPlane(-1, 1, 1, Al_fcc) o = Orientation.from_rodrigues([0.0499, -0.3048, 0.1040]) w1, w2 = o.dct_omega_angles(hkl, 40, verbose=False) self.assertAlmostEqual(w1, 109.2, 1) self.assertAlmostEqual(w2, 296.9, 1)
def test_in_fundamental_zone(self): rod = [0.1449, -0.0281, 0.0616] o = Orientation.from_rodrigues(rod) self.assertTrue(o.inFZ(symmetry=Symmetry.cubic)) o = Orientation.from_euler([191.9, 69.9, 138.9]) self.assertFalse(o.inFZ(symmetry=Symmetry.cubic))
A small crystal lattice is also displayed aside the grain to picture its orientation. ''' data_dir = '../data' scan = 'grain1_112x112x121_uint8.raw' im_file = os.path.join(data_dir, scan) # Create the 3D scene base_name = os.path.splitext(__file__)[0] s3d = Scene3D(display=False, ren_size=(800, 800), name=base_name, background=black) # create a python Grain object from the image data orientation = Orientation.from_rodrigues(np.array([0.3889, -0.0885, 0.3268])) grain = Grain(1, orientation) grain_data = HST_read(im_file, header_size=0, autoparse_filename=True, verbose=True) grain.position = ndimage.measurements.center_of_mass(grain_data, grain_data) print('grain position: %s' % str(grain.position)) grain.volume = ndimage.measurements.sum(grain_data) # label is 1.0 here grain.add_vtk_mesh(grain_data, contour=False) print('adding bounding box') grain_bbox = box_3d(size=np.shape(grain_data), line_color=white) print('adding grain with slip planes') z_offsets = np.linspace(-50, 50, 6, endpoint=True)