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', overwrite_hdf5=True)
    micro.autodelete = True
    gid_list = [1158, 1349, 1585, 1805, 1833, 2268]
    euler_list = [(344.776, 52.2589, 53.9933), 
                  (344.899, 125.961, 217.330),
                  (228.039, 57.4791, 143.171),
                  (186.741, 60.333, 43.311),
                  (151.709, 55.0406, 44.1051),
                  (237.262, 125.149, 225.615),
                  ]
    micro.add_grains(euler_list, grain_ids=gid_list)

    # 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')
    del pf
    del micro

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

    from matplotlib import image

    image.thumbnail(image_name, 'thumb_' + image_name, 0.2)
示例#2
0
def index(hkl_normals, hkl_planes, tol_angle=0.5, tol_disorientation=1.0, symmetry=Symmetry.cubic, display=False):
    # angles between normal from the gnomonic projection
    angles_exp = np.zeros((len(hkl_normals), len(hkl_normals)), dtype=float)
    print('\nlist of angles between points on the detector')
    for i in range(len(hkl_normals)):
        for j in range(i + 1, len(hkl_normals)):
            angle = 180 / pi * np.arccos(np.dot(hkl_normals[i], hkl_normals[j]))
            angles_exp[i, j] = angle
            print('%.2f, OP%d, OP%d' % (angles_exp[i, j], i, j))
    # keep a list of the hkl values as string
    hkl_str = []
    for p in hkl_planes:
        (h, k, l) = p.miller_indices()
        hkl_str.append('(%d%d%d)' % (h, k, l))
    # compute theoretical angle between each plane normal, store the results using a structured array
    angles_th = np.empty(len(hkl_planes) * (len(hkl_planes) - 1) / 2,
                         dtype=[('angle', 'f4'), ('hkl1', 'i4'), ('hkl2', 'i4')])
    index = 0
    for i in range(len(hkl_planes)):
        for j in range(i + 1, len(hkl_planes)):
            angle = 180 / pi * np.arccos(np.dot(hkl_planes[i].normal(), hkl_planes[j].normal()))
            angles_th[index] = (angle, i, j)
            index += 1

    # sort the array by increasing angle
    angles_th.sort(order='angle')
    print('\nsorted list of angles between hkl plane normals')
    for i in range(len(angles_th)):
        print('%.3f, (%d, %d) -> %s, %s' % (
            angles_th['angle'][i], angles_th['hkl1'][i], angles_th['hkl2'][i], hkl_str[angles_th['hkl1'][i]],
            hkl_str[angles_th['hkl2'][i]]))

    # index by triplets
    normal_indexed = triplet_indexing(hkl_normals, angles_exp, angles_th, tol=tol_angle)
    print('indexed list length is %d' % len(normal_indexed))
    print(normal_indexed)

    # Compute the orientation matrix g for all different triplets
    g_indexation = []
    for i in range(len(normal_indexed)):
        # a given indexed triplet allow to construct 3 orientation matrices (which should be identical)
        pos = [[0, 1, 3, 4], [1, 2, 4, 5], [2, 0, 5, 3]]
        for j in range(3):
            orientation_matrix = transformation_matrix(
                hkl_planes[normal_indexed[i][pos[j][2]]], hkl_planes[normal_indexed[i][pos[j][3]]],
                hkl_normals[normal_indexed[i][pos[j][0]]], hkl_normals[normal_indexed[i][pos[j][1]]])
        # move to the fundamental zone
        om_fz = symmetry.move_rotation_to_FZ(orientation_matrix)  # we only add the third one
        g_indexation.append(om_fz)
    final_orientation_matrix, vote, ci, vote_field = poll_system(g_indexation, dis_tol=tol_disorientation)
    if final_orientation_matrix == 0:
        print('Troubles in the data set !')
    else:
        print('\n\n\n### FINAL SOLUTION(S) ###\n')
        for n in range(len(final_orientation_matrix)):
            print('- SOLUTION %d -' % (n + 1))
            final_orientation = Orientation(final_orientation_matrix[n])
            print(final_orientation.inFZ())
            print ('- Cristal orientation in Fundamental Zone \n {0:s} \n'.format(final_orientation.euler))
            print('- Rodrigues vector in the fundamental Zone \n {0:s} \n'.format(final_orientation.rod))
            if display:
                from pymicro.crystal.texture import PoleFigure
                PoleFigure.plot(final_orientation, axis='Z')
        return final_orientation_matrix, ci
示例#3
0
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__':
    '''
    111 Pole figure of a copper sample containing 10000 grains with a fibre
    texture.
    '''
    eulers = Orientation.read_euler_txt('../data/Cu_111.dat')
    micro = Microstructure(name='Cu_111')
    for index in eulers:
        micro.grains.append(Grain(index, eulers[index]))

    # create pole figure (both direct and inverse)
    pf = PoleFigure(hkl='111',
                    proj='stereo',
                    microstructure=micro,
                    verbose=False)
    pf.color_by_grain_id = False
    pf.mksize = 5
    pf.pflegend = False
    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)

    from matplotlib import image

    image.thumbnail(image_name, 'thumb_' + image_name, 0.2)
示例#4
0
    poles are colored according using IPF coloring and resized proportionally 
    to each grain volume.
    """
    # create a microstructure with a random texture and 200 grains
    micro = Microstructure.random_texture(n=200)
    micro.autodelete = True

    # set random values for the grain volumes
    np.random.seed(22)
    for g in micro.grains:
        g['volume'] = 100 * np.random.random()**3
        g.update()
    micro.grains.flush()

    # first pole figure
    pf = PoleFigure(microstructure=micro)
    pf.resize_markers = True
    pf.set_hkl_poles('001')
    pf.axis = 'Z'
    pf.set_map_field('ipf')
    pf.plot_pole_figures(plot_sst=True, display=False, save_as='png')
    del pf
    del micro

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

    from matplotlib import image

    image.thumbnail(image_name, 'thumb_' + image_name, 0.2)
示例#5
0
from pymicro.crystal.microstructure import Microstructure, Grain, Orientation
from matplotlib import pyplot as plt

if __name__ == '__main__':
    """
    A pole figure plotted using contours.

    .. note::

      Use this example carefully since this is just using a matplotlib contourf 
      function, and has not been tested properly.
    """
    euler_list = np.genfromtxt('../data/pp100', usecols=(0, 1, 2))
    micro = Microstructure(name='test', autodelete=True)
    micro.add_grains(euler_list)

    pf = PoleFigure(hkl='111', proj='stereo', microstructure=micro)
    pf.mksize = 40
    fig = plt.figure(1, figsize=(12, 5))
    ax1 = fig.add_subplot(121, aspect='equal')
    ax2 = fig.add_subplot(122, aspect='equal')
    pf.create_pf_contour(ax=ax1, ang_step=20)
    pf.plot_pf(ax=ax2)
    image_name = os.path.splitext(__file__)[0] + '.png'
    print('writting %s' % image_name)
    plt.savefig(image_name, format='png')

    from matplotlib import image

    image.thumbnail(image_name, 'thumb_' + image_name, 0.2)
    del pf, micro
示例#6
0
from pymicro.crystal.microstructure import Microstructure, Grain, Orientation
from matplotlib import pyplot as plt, colors, colorbar, cm
'''
An inverse pole figure with symboled colored by the grain size.
'''
eulers = Orientation.read_orientations('../data/EBSD_20grains.txt',
                                       data_type='euler',
                                       usecols=[1, 2, 3])
grain_sizes = np.genfromtxt('../data/EBSD_20grains.txt', usecols=[9])
micro = Microstructure(name='test')
for i in range(20):
    micro.grains.append(Grain(i + 1, eulers[i + 1]))
    micro.get_grain(i + 1).volume = grain_sizes[i]

# build a custom pole figure
pf = PoleFigure(microstructure=micro, hkl='001')  #, lattice=Ti7Al)
#pf.resize_markers = True
pf.mksize = 100
pf.set_map_field('strain',
                 grain_sizes,
                 field_min_level=0.0,
                 field_max_level=1000.,
                 lut='jet')
fig = plt.figure(figsize=(8, 5))
ax1 = fig.add_axes([0.05, 0.05, 0.8, 0.9], aspect='equal')
pf.plot_sst(ax=ax1, mk='o')
ax1.set_title('%s-axis SST inverse %s projection' % (pf.axis, pf.proj))

# to add the color bar
ax2 = fig.add_axes([0.85, 0.05, 0.05, 0.9])
norm = colors.Normalize(vmin=0., vmax=1000.)
示例#7
0
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)
s3d.render()
示例#8
0
import os, numpy as np
from pymicro.crystal.texture import PoleFigure
from pymicro.crystal.microstructure import Microstructure, Grain, Orientation
from matplotlib import pyplot as plt

if __name__ == '__main__':
    '''
    A pole figure plotted using contours.
    '''
    eulers = Orientation.read_orientations('../data/pp100', data_type='euler')
    micro = Microstructure(name='test')
    for i in range(100):
        micro.grains.append(Grain(i + 1, eulers[i + 1]))

    pf = PoleFigure(microstructure=micro)
    pf.mksize = 40
    pf.proj = 'stereo'
    pf.set_hkl_poles('111')
    fig = plt.figure(1, figsize=(12, 5))
    ax1 = fig.add_subplot(121, aspect='equal')
    ax2 = fig.add_subplot(122, aspect='equal')
    pf.create_pf_contour(ax=ax1, ang_step=20)
    pf.plot_pf(ax=ax2)

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

    from matplotlib import image

    image.thumbnail(image_name, 'thumb_' + image_name, 0.2)
示例#9
0
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()
axis_rot_sst_prev = np.array(ipf.sst_symmetry_cubic(g.dot(axis)))
print('** plotting ipf loading axis trajectory **')