Пример #1
0
 def test_misorientation_angle(self):
     o1 = Orientation.from_euler((0., 0., 0.))
     o2 = Orientation.from_euler((60., 0., 0.))
     self.assertAlmostEqual(
         180 / np.pi *
         o1.disorientation(o2, crystal_structure=Symmetry.triclinic)[0], 60)
     self.assertAlmostEqual(
         180 / np.pi *
         o1.disorientation(o2, crystal_structure=Symmetry.cubic)[0], 30)
Пример #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])
Пример #3
0
 def test_misorientation_matrix(self):
     for test_euler in self.test_eulers:
         o = Orientation.from_euler(test_euler)
         g = o.orientation_matrix()
         delta = np.dot(g, g.T)
         self.assertEqual(
             Orientation.misorientation_angle_from_delta(delta), 0.0)
Пример #4
0
 def test_indexation(self):
     """Verify indexing solution from a known Laue pattern."""
     euler_angles = (191.9, 69.9, 138.9)  # degrees, /!\ not in fz
     orientation = Orientation.from_euler(euler_angles)
     # list of plane normals, obtained from the detector image
     hkl_normals = np.array(
         [[0.11066932863248755, 0.8110118739480003, 0.5744667440465002],
          [0.10259261224575777, 0.36808036454584847, -0.9241166599236196],
          [0.12497400210731163, 0.38160000643453934, 0.9158400154428944],
          [0.21941448008210823, 0.5527234994434788, -0.8039614537359691],
          [0.10188581412204267, -0.17110594738052967, -0.9799704259066699],
          [0.10832511255237177, -0.19018912890874434, 0.975752922227471],
          [0.13621754927492466, -0.8942526135605741, 0.4263297343719016],
          [0.04704092862601945, -0.45245473334950004, -0.8905458243704446]])
     miller_indices = [(3, -5, 0), (5, 4, -2), (2, -5, -1), (3, -4, -5),
                       (2, -2, 3), (-3, 4, -3), (3, -4, 3), (3, -2, 3),
                       (-5, 5, -1), (5, -5, 1)]
     hkl_planes = []
     for indices in miller_indices:
         (h, k, l) = indices
         hkl_planes.append(HklPlane(h, k, l, self.ni))
     solutions = index(hkl_normals,
                       hkl_planes,
                       tol_angle=0.5,
                       tol_disorientation=3.0)
     final_orientation = Orientation(solutions[0])
     angle, ax1, ax2 = final_orientation.disorientation(
         orientation, crystal_structure=Symmetry.cubic)
     self.assertLess(angle * 180 / np.pi, 1.0)
Пример #5
0
 def test_OrientationMatrix2Euler(self):
     for test_euler in self.test_eulers:
         o = Orientation.from_euler(test_euler)
         g = o.orientation_matrix()
         calc_euler = Orientation.OrientationMatrix2Euler(g)
         calc_euler2 = Orientation.OrientationMatrix2EulerSF(g)
         for i in range(3):
             self.assertAlmostEquals(calc_euler[i], test_euler[i])
Пример #6
0
 def setUp(self):
     print('testing the Microstructure class')
     self.test_eulers = [(45., 45, 0.), (10., 20, 30.), (191.9, 69.9, 138.9)]
     self.micro = Microstructure()
     self.micro.name = 'test'
     for i in range(len(self.test_eulers)):
         euler = self.test_eulers[i]
         self.micro.grains.append(Grain(i + 1, Orientation.from_euler(euler)))
Пример #7
0
 def test_move_to_fundamental_zone(self):
     o = Orientation.from_euler([191.9, 69.9, 138.9])
     # move rotation to cubic FZ
     o_fz = o.move_to_FZ(symmetry=Symmetry.cubic, verbose=False)
     # double check new orientation in is the FZ
     self.assertTrue(o_fz.inFZ(symmetry=Symmetry.cubic))
     # verify new Euler angle values
     val = np.array([303.402, 44.955, 60.896])
     for i in range(3):
         self.assertAlmostEqual(o_fz.euler[i], val[i], 3)
Пример #8
0
    def plot_euler(phi1, Phi, phi2, **kwargs):
        '''Directly plot a pole figure for a single orientation given its
        three Euler angles.

        ::

          PoleFigure.plot_euler(10, 20, 30)

        :param float phi1: first Euler angle (in degree).
        :param float Phi: second Euler angle (in degree).
        :param float phi2: third Euler angle (in degree).
        '''
        PoleFigure.plot(Orientation.from_euler(np.array([phi1, Phi, phi2])),
                        **kwargs)
Пример #9
0
 def test_angle_zone(self):
     """Verify the angle between X and a particular zone axis expressed
     in (X, Y, Z), given a crystal orientation."""
     # euler angles in degrees
     phi1 = 89.4
     phi = 92.0
     phi2 = 86.8
     orientation = Orientation.from_euler([phi1, phi, phi2])
     gt = orientation.orientation_matrix().transpose()
     # zone axis
     uvw = HklDirection(1, 0, 5, self.ni)
     ZA = gt.dot(uvw.direction())
     if ZA[0] < 0:
         ZA *= -1  # make sur the ZA vector is going forward
     psi0 = np.arccos(np.dot(ZA, np.array([1., 0., 0.])))
     self.assertAlmostEqual(psi0 * 180 / np.pi, 9.2922, 3)
Пример #10
0
 def test_grain_geometry(self):
     m = Microstructure(name='test', autodelete=True)
     grain_map = np.ones((8, 8, 8), dtype=np.uint8)
     m.set_grain_map(grain_map, voxel_size=1.0)
     grain = m.grains.row
     grain['idnumber'] = 1
     grain['orientation'] = Orientation.from_euler([10, 20, 30]).rod
     grain.append()
     m.grains.flush()
     m.recompute_grain_bounding_boxes()
     m.recompute_grain_centers()
     m.recompute_grain_volumes()
     bb1 = m.compute_grain_bounding_box(gid=1)
     self.assertEqual(bb1, ((0, 8), (0, 8), (0, 8)))
     c1 = m.compute_grain_center(gid=1).tolist()
     self.assertEqual(c1, [0., 0., 0.])
     self.assertEqual(m.compute_grain_volume(gid=1), 512)
Пример #11
0
    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)
Пример #12
0
 def load(file_path='experiment.txt'):
     with open(file_path, 'r') as f:
         dict_exp = json.load(f)
     name = dict_exp['Sample']['Name']
     sample = Sample(name=name)
     sample.data_dir = dict_exp['Sample']['Data Dir']
     sample.set_position(dict_exp['Sample']['Position'])
     if 'Geometry' in dict_exp['Sample']:
         sample_geo = ObjectGeometry()
         sample_geo.set_type(dict_exp['Sample']['Geometry']['Type'])
         sample.set_geometry(sample_geo)
     if 'Material' in dict_exp['Sample']:
         a, b, c = dict_exp['Sample']['Material']['Lengths']
         alpha, beta, gamma = dict_exp['Sample']['Material']['Angles']
         centering = dict_exp['Sample']['Material']['Centering']
         symmetry = Symmetry.from_string(
             dict_exp['Sample']['Material']['Symmetry'])
         material = Lattice.from_parameters(a,
                                            b,
                                            c,
                                            alpha,
                                            beta,
                                            gamma,
                                            centering=centering,
                                            symmetry=symmetry)
         sample.set_material(material)
     if 'Microstructure' in dict_exp['Sample']:
         micro = Microstructure(
             name=dict_exp['Sample']['Microstructure']['Name'],
             file_path=os.path.dirname(file_path))
         # crystal lattice
         if 'Lattice' in dict_exp['Sample']['Microstructure']:
             a, b, c = dict_exp['Sample']['Microstructure']['Lattice'][
                 'Lengths']
             alpha, beta, gamma = dict_exp['Sample']['Microstructure'][
                 'Lattice']['Angles']
             centering = dict_exp['Sample']['Microstructure']['Lattice'][
                 'Centering']
             symmetry = Symmetry.from_string(
                 dict_exp['Sample']['Microstructure']['Lattice']
                 ['Symmetry'])
             lattice = Lattice.from_parameters(a,
                                               b,
                                               c,
                                               alpha,
                                               beta,
                                               gamma,
                                               centering=centering,
                                               symmetry=symmetry)
             micro.set_lattice(lattice)
         grain = micro.grains.row
         for i in range(len(
                 dict_exp['Sample']['Microstructure']['Grains'])):
             dict_grain = dict_exp['Sample']['Microstructure']['Grains'][i]
             grain['idnumber'] = int(dict_grain['Id'])
             euler = dict_grain['Orientation']['Euler Angles (degrees)']
             grain['orientation'] = Orientation.from_euler(euler).rod
             grain['center'] = np.array(dict_grain['Position'])
             grain['volume'] = dict_grain['Volume']
             #                if 'hkl_planes' in dict_grain:
             #                    grain.hkl_planes = dict_grain['hkl_planes']
             grain.append()
         micro.grains.flush()
         sample.set_microstructure(micro)
         sample.microstructure.autodelete = True
     # lazy behaviour, we load only the grain_ids path, the actual array is loaded in memory if needed
     sample.grain_ids_path = dict_exp['Sample']['Grain Ids Path']
     exp = Experiment()
     exp.set_sample(sample)
     source = XraySource()
     source.set_position(dict_exp['Source']['Position'])
     if 'Min Energy (keV)' in dict_exp['Source']:
         source.set_min_energy(dict_exp['Source']['Min Energy (keV)'])
     if 'Max Energy (keV)' in dict_exp['Source']:
         source.set_max_energy(dict_exp['Source']['Max Energy (keV)'])
     exp.set_source(source)
     for i in range(len(dict_exp['Detectors'])):
         dict_det = dict_exp['Detectors'][i]
         if dict_det['Class'] == 'Detector2d':
             det = Detector2d(size=dict_det['Size (pixels)'])
             det.ref_pos = dict_det['Reference Position (mm)']
         if dict_det['Class'] == 'RegArrayDetector2d':
             det = RegArrayDetector2d(size=dict_det['Size (pixels)'])
             det.pixel_size = dict_det['Pixel Size (mm)']
             det.ref_pos = dict_det['Reference Position (mm)']
             if 'Min Energy (keV)' in dict_exp['Detectors']:
                 det.tilt = dict_det['Tilts (deg)']
             if 'Binning' in dict_det:
                 det.set_binning(dict_det['Binning'])
             det.u_dir = np.array(dict_det['u_dir'])
             det.v_dir = np.array(dict_det['v_dir'])
             det.w_dir = np.array(dict_det['w_dir'])
         exp.add_detector(det)
     return exp
Пример #13
0
import numpy as np
import vtk
from pymicro.view.vtk_utils import lattice_3d, unit_arrow_3d, axes_actor, text, setup_camera, \
    apply_orientation_to_actor, set_opacity
from pymicro.view.scene3d import Scene3D
from pymicro.crystal.microstructure import Orientation
from pymicro.crystal.lattice import Lattice, HklDirection

s3d = Scene3D(display=False, ren_size=(600, 600))
s3d.name = 'euler_angles_and_orientation_matrix'
euler_angles = np.array([142.8, 32.0, 214.4])
(phi1, Phi, phi2) = euler_angles
orientation = Orientation.from_euler(euler_angles)
g = orientation.orientation_matrix()

lab_frame = axes_actor(1, fontSize=50)
lab_frame.SetCylinderRadius(0.02)
s3d.add(lab_frame)

crystal_frame = axes_actor(0.6, fontSize=50, axisLabels=None)
crystal_frame.SetCylinderRadius(0.05)
collection = vtk.vtkPropCollection()
crystal_frame.GetActors(collection)
for i in range(collection.GetNumberOfItems()):
    collection.GetItemAsObject(i).GetProperty().SetColor(0.0, 0.0, 0.0)
apply_orientation_to_actor(crystal_frame, orientation)
s3d.add(crystal_frame)

a = 1.0
l = Lattice.face_centered_cubic(a)
fcc_lattice = lattice_3d(l, crystal_orientation=orientation)
Пример #14
0
from pymicro.view.vtk_utils import *
from pymicro.view.vtk_anim import *
from pymicro.view.scene3d import Scene3D
from pymicro.crystal.microstructure import Orientation
from pymicro.crystal.lattice import Lattice

s3d = Scene3D(display=True, ren_size=(600, 600))
euler_angles = np.array([142.8, 32.0, 214.4])
(phi1, Phi, phi2) = euler_angles
orientation = Orientation.from_euler(euler_angles)

scene = vtkAnimationScene(s3d.get_renderer(), s3d.renWin.GetSize())
scene.save_image = True
scene.timer_incr = 1
scene.timer_end = 179
scene.verbose = False
scene.prefix = 'euler_angles_anim'

lab_frame = axes_actor(1, fontSize=50)
lab_frame.SetCylinderRadius(0.02)
s3d.add(lab_frame)

crystal_frame = axes_actor(0.6, fontSize=50, axisLabels=None)
crystal_frame.SetCylinderRadius(0.04)
collection = vtk.vtkPropCollection()
crystal_frame.GetActors(collection)
for i in range(collection.GetNumberOfItems()):
    collection.GetItemAsObject(i).GetProperty().SetColor(0.0, 0.0, 0.0)
crystal_frame.SetVisibility(0)
s3d.add(crystal_frame)
Пример #15
0
 def test_MaxSchimdFactor(self):
     o = Orientation.from_euler([0., 0., 0.])
     oct_ss = SlipSystem.get_slip_systems(plane_type='111')
     self.assertAlmostEqual(
         max(o.compute_all_schmid_factors(oct_ss, verbose=True)), 0.4082, 4)
Пример #16
0
 def test_SchimdFactor(self):
     o = Orientation.from_euler([0., 0., 0.])
     ss = SlipSystem(HklPlane(1, 1, 1), HklDirection(0, 1, -1))
     self.assertAlmostEqual(o.schmid_factor(ss), 0.4082, 4)
Пример #17
0
import vtk, numpy, os
from pymicro.crystal.microstructure import Orientation, Grain
from pymicro.crystal.texture import PoleFigure
from pymicro.view.scene3d import Scene3D
from pymicro.view.vtk_utils import pole_figure_3d, axes_actor, setup_camera

'''
Create a 3d scene with a cubic crystal lattice at the center.
Hkl planes are added to the lattice and their normal displayed.
A sphere is added to show how a pole figure can be constructed.
'''

base_name = os.path.splitext(__file__)[0]
s3d = Scene3D(display=False, ren_size=(800, 800), name=base_name)

orientation = Orientation.from_euler(numpy.array([142.8, 32.0, 214.4]))
pf = PoleFigure(hkl='111')
pf.microstructure.grains.append(Grain(1, orientation))
pole_figure = pole_figure_3d(pf, radius=1.0, show_lattice=True)

# add all actors to the 3d scene
s3d.add(pole_figure)
axes = axes_actor(1.0, fontSize=60)
s3d.add(axes)

# set up camera
cam = setup_camera(size=(1, 1, 1))
cam.SetViewUp(0, 0, 1)
cam.SetPosition(0, -4, 0)
cam.SetFocalPoint(0, 0, 0)
s3d.set_camera(cam)
Пример #18
0
 def test_Orientation(self):
     o = Orientation.from_euler([45, 45, 0])
     self.assertAlmostEqual(o.phi1(), 45.)
     self.assertAlmostEqual(o.Phi(), 45.)
Пример #19
0
from pymicro.view.vtk_utils import *
from pymicro.crystal.lattice import HklPlane
from pymicro.crystal.microstructure import Orientation
from math import sqrt
import numpy as np
'''
Create a 3d scene with a hexagonal crystal lattice.
Hkl planes are added to the lattice and displayed.
'''
# Create the Renderer and RenderWindow
ren = vtk.vtkRenderer()
ren.SetBackground(white)

# crystal orientation
o = Orientation.from_euler((15.0, -45.0, 0.0))
o = None

# hexagonal lattice
a = 1.0  # 0.321 # nm
c = 1.5  # 0.521 # nm
l = Lattice.hexagonal(a, c)
grid = hexagonal_lattice_grid(l)
print(np.array(HklPlane.four_to_three_indices(1, 0, -1, 0)) /
      0.6)  # prismatic 1
print(np.array(HklPlane.four_to_three_indices(0, 1, -1, 0)) /
      0.6)  # prismatic 2
print(np.array(HklPlane.four_to_three_indices(0, 1, -1, 1)) / 0.6 *
      3)  # pyramidal 1
print(np.array(HklPlane.four_to_three_indices(1, 1, -2, 2)) / 0.6 *
      3)  # pyramidal 2
print(np.array(HklPlane.four_to_three_indices(0, 0, 0, 1)))  # basal
Пример #20
0
 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))
Пример #21
0
    def segment_grains(self, tol=5.):
        """Segment the grains based on the euler angle maps.

        The segmentation is carried out using a region growing algorithm based
        on an orientation similarity criterion.

        The id 0 is reserved to the background which is assigned to pixels with
        a confidence index lower than 0.2. Other pixels are first marqued as
        unlabeled using -1, then pixels are evaluated one by one.
        A new grain is created and non already assigned neighboring pixels are
        evaluated based on the crystal misorientation. If the misorientation is
        lower than `tol`, the pixel is assigned to the current grain and its
        neighbors added to the list of candidates. When no more candidates are
        present, the next pixel is evaluated and a new grain is created.

        :param tol: misorientation tolerance in degrees
        :return: a numpy array of the grain labels.
        """
        # segment the grains
        grain_ids = np.zeros_like(self.iq, dtype='int')
        grain_ids += -1  # mark all pixels as non assigned
        # start by assigning bad pixel to grain 0
        grain_ids[self.ci <= 0.2] = 0

        n_grains = 0
        for j in range(self.rows):
            for i in range(self.cols):
                if grain_ids[i, j] >= 0:
                    continue  # skip pixel
                # create new grain with the pixel as seed
                n_grains += 1
                # print('segmenting grain %d' % n_grains)
                grain_ids[i, j] = n_grains
                candidates = [(i, j)]
                # apply region growing based on the angle misorientation (strong connectivity)
                while len(candidates) > 0:
                    pixel = candidates.pop()
                    # print('* pixel is {}, euler: {}'.format(pixel, np.degrees(euler[pixel])))
                    # get orientation of this pixel
                    o = Orientation.from_euler(np.degrees(self.euler[pixel]))
                    # look around this pixel
                    east = (pixel[0] - 1, pixel[1])
                    north = (pixel[0], pixel[1] - 1)
                    west = (pixel[0] + 1, pixel[1])
                    south = (pixel[0], pixel[1] + 1)
                    neighbors = [east, north, west, south]
                    # look at unlabeled connected pixels
                    neighbor_list = [
                        n for n in neighbors if 0 <= n[0] < self.cols
                        and 0 <= n[1] < self.rows and grain_ids[n] == -1
                    ]
                    # print(' * neighbors list is {}'.format([east, north, west, south]))
                    for neighbor in neighbor_list:
                        # check misorientation
                        o_neighbor = Orientation.from_euler(
                            np.degrees(self.euler[neighbor]))
                        mis, _, _ = o.disorientation(
                            o_neighbor, crystal_structure=Symmetry.hexagonal)
                        if mis * 180 / np.pi < tol:
                            # add to this grain
                            grain_ids[neighbor] = n_grains
                            # add to the list of candidates
                            candidates.append(neighbor)
                    progress = 100 * np.sum(grain_ids >= 0) / (self.cols *
                                                               self.rows)
            print('segmentation progress: {0:.2f} %'.format(progress),
                  end='\r')
        print('\n%d grains were segmented' % len(np.unique(grain_ids)))
        return grain_ids
Пример #22
0
import numpy as np
import os
from pymicro.crystal.microstructure import Microstructure, Orientation, Grain
from pymicro.crystal.texture import PoleFigure
from matplotlib import pyplot as plt

# read data from Z-set calculation (50% tension load)
data = np.genfromtxt('../data/R_1g.dat')
t, R11, R22, R33, R12, R23, R31, R21, R32, R13, _, _, _, _ = data.T
step = 1  # plot every step point
max_step = data.shape[0]

# create a microstructure with the initial grain orientation
micro = Microstructure(name='1g', autodelete=True)
g = Grain(50, Orientation.from_euler((12.293, 149.266, -167.068)))
micro.add_grains([(12.293, 149.266, -167.068)], grain_ids=[50])

ipf = PoleFigure(proj='stereo', microstructure=micro)
ipf.mksize = 100
ipf.set_map_field('grain_id')

fig = plt.figure(1, figsize=(6, 5))  # for IPF
ax1 = fig.add_subplot(111, aspect='equal')
print('** plotting the initial orientation (with label for legend) **')
ipf.plot_sst(ax=ax1, mk='.', col='k', ann=False)
ax1.set_title('grain rotation in tension')
axis = np.array([0, 0, 1])

grain = micro.get_grain(50)
cgid = Microstructure.rand_cmap().colors[grain.id]  # color by grain id
g = grain.orientation_matrix()
Пример #23
0
        assembly.AddPart(hklplaneActor)
    return assembly


'''
Create a 3d scene with the mesh outline.
Two planes are used to figure out the crack.
Both hkl planes are added at the crack tip and displayed.
'''

# Create the 3D scene
base_name = os.path.splitext(__file__)[0]
s3d = Scene3D(display=False, ren_size=(800, 800), name=base_name)

# specify the grain orientation
o1 = Orientation.from_euler(numpy.array([45., 0., 0.]))  # grain 1

# choose slip plane normals and directions to display in grain
n1 = numpy.array([1.0, 1.0, -1.0])
l1 = numpy.array([1.0, 1.0, 2.0])
d1 = '[112]'
n2 = numpy.array([1.0, 1.0, 1.0])
l2 = numpy.array([1.0, 1.0, -2.0])
d2 = '[11-2]'
nld = [[n1, l1, d1], [n2, l2, d2]]

# we use a unit lattice cell to represent the mesh
l_xyz = Lattice.face_centered_cubic(1.0)
g1 = create_mesh_outline_3d_with_planes(l_xyz, o1, nld)
s3d.add(g1)
Пример #24
0
 def load(file_path='experiment.txt'):
     with open(file_path, 'r') as f:
         dict_exp = json.load(f)
     sample = Sample()
     sample.set_name(dict_exp['Sample']['Name'])
     sample.set_position(dict_exp['Sample']['Position'])
     if 'Geometry' in dict_exp['Sample']:
         sample_geo = ObjectGeometry()
         sample_geo.set_type(dict_exp['Sample']['Geometry']['Type'])
         sample.set_geometry(sample_geo)
     if 'Material' in dict_exp['Sample']:
         a, b, c = dict_exp['Sample']['Material']['Lengths']
         alpha, beta, gamma = dict_exp['Sample']['Material']['Angles']
         centering = dict_exp['Sample']['Material']['Centering']
         symmetry = Symmetry.from_string(
             dict_exp['Sample']['Material']['Symmetry'])
         material = Lattice.from_parameters(a,
                                            b,
                                            c,
                                            alpha,
                                            beta,
                                            gamma,
                                            centering=centering,
                                            symmetry=symmetry)
         sample.set_material(material)
     if 'Microstructure' in dict_exp['Sample']:
         micro = Microstructure(
             dict_exp['Sample']['Microstructure']['Name'])
         for i in range(len(
                 dict_exp['Sample']['Microstructure']['Grains'])):
             dict_grain = dict_exp['Sample']['Microstructure']['Grains'][i]
             grain = Grain(
                 dict_grain['Id'],
                 Orientation.from_euler(
                     dict_grain['Orientation']['Euler Angles (degrees)']))
             grain.position = np.array(dict_grain['Position'])
             grain.volume = dict_grain['Volume']
             micro.grains.append(grain)
         sample.set_microstructure(micro)
     exp = Experiment()
     exp.set_sample(sample)
     source = XraySource()
     source.set_position(dict_exp['Source']['Position'])
     if 'Min Energy (keV)' in dict_exp['Source']:
         source.set_min_energy(dict_exp['Source']['Min Energy (keV)'])
     if 'Max Energy (keV)' in dict_exp['Source']:
         source.set_max_energy(dict_exp['Source']['Max Energy (keV)'])
     exp.set_source(source)
     for i in range(len(dict_exp['Detectors'])):
         dict_det = dict_exp['Detectors'][i]
         if dict_det['Class'] == 'Detector2d':
             det = Detector2d(size=dict_det['Size (pixels)'])
             det.ref_pos = dict_det['Reference Position (mm)']
         if dict_det['Class'] == 'RegArrayDetector2d':
             det = RegArrayDetector2d(size=dict_det['Size (pixels)'])
             det.pixel_size = dict_det['Pixel Size (mm)']
             det.ref_pos = dict_det['Reference Position (mm)']
             if 'Binning' in dict_det:
                 det.set_binning(dict_det['Binning'])
             det.u_dir = np.array(dict_det['u_dir'])
             det.v_dir = np.array(dict_det['v_dir'])
             det.w_dir = np.array(dict_det['w_dir'])
         exp.add_detector(det)
     return exp
Пример #25
0
#!/usr/bin/env python
import os, numpy as np
from pymicro.crystal.microstructure import Microstructure, Grain, Orientation
from pymicro.crystal.texture import PoleFigure
from matplotlib import pyplot as plt, colors, cm

if __name__ == '__main__':
    '''
    Pole figure of a gold sample containing 6 grains with a strong <111> fiber texture.
    A Microstructure object is first created with the 6 grains of interest.
    The grain ids corerespond to the actual grain number (in an EBSD scan for instance).
    A PoleFigure object is then created using this microstructure and the pole figures
    (both direct and inverse) are drawn by calling the plot_pole_figures() method.
    '''
    micro = Microstructure(name='Au_6grains')
    micro.grains.append(Grain(1158, Orientation.from_euler(np.array([344.776, 52.2589, 53.9933]))))
    micro.grains.append(Grain(1349, Orientation.from_euler(np.array([344.899, 125.961, 217.330]))))
    micro.grains.append(Grain(1585, Orientation.from_euler(np.array([228.039, 57.4791, 143.171]))))
    micro.grains.append(Grain(1805, Orientation.from_euler(np.array([186.741, 60.333, 43.311]))))
    micro.grains.append(Grain(1833, Orientation.from_euler(np.array([151.709, 55.0406, 44.1051]))))
    micro.grains.append(Grain(2268, Orientation.from_euler(np.array([237.262, 125.149, 225.615]))))

    # create pole figure (both direct and inverse)
    pf = PoleFigure(hkl='111', axis='Z', proj='stereo', microstructure=micro)
    pf.mksize = 100
    pf.set_map_field('grain_id')
    pf.pflegend = True  # this works well for a few grains
    pf.plot_pole_figures(plot_sst=True, display=False, save_as='png')

    image_name = os.path.splitext(__file__)[0] + '.png'
    print('writting %s' % image_name)