Пример #1
0
def assemble_grain_data(grain_data_list,
                        pos_offset=None,
                        rotation_offset=None):
    num_grain_files = len(grain_data_list)

    num_grains_list = [None] * num_grain_files

    for i in np.arange(num_grain_files):
        num_grains_list[i] = grain_data_list[i].shape[0]

    num_grains = np.sum(num_grains_list)

    grain_data = np.zeros([num_grains, grain_data_list[0].shape[1]])

    for i in np.arange(num_grain_files):

        tmp = copy.copy(grain_data_list[i])

        if pos_offset is not None:
            pos_tile = np.tile(pos_offset[:, i], [num_grains_list[i], 1])
            tmp[:, 6:9] = tmp[:, 6:9] + pos_tile
        #Needs Testing
        if rotation_offset is not None:
            rot_tile = np.tile(
                np.atleast_2d(rotation_offset[:, i]).T,
                [1, num_grains_list[i]])
            quat_tile = rot.quatOfExpMap(rot_tile)
            grain_quats = rot.quatOfExpMap(tmp[:, 3:6].T)
            new_quats = rot.quatProduct(grain_quats, quat_tile)

            sinang = mutil.columnNorm(new_quats[1:, :])
            ang = 2. * np.arcsin(sinang)
            axis = mutil.unitVector(new_quats[1:, :])
            tmp[:, 3:6] = np.tile(np.atleast_2d(ang).T, [1, 3]) * axis.T

        grain_data[int(np.sum(num_grains_list[:i])
                       ):int(np.sum(num_grains_list[:(i + 1)])), :] = tmp

    old_grain_numbers = copy.copy(grain_data[:, 0])
    grain_data[:, 0] = np.arange(num_grains)
    return grain_data, old_grain_numbers
Пример #2
0
def assemble_grain_data(grain_data_list,pos_offset=None,rotation_offset=None):
    num_grain_files=len(grain_data_list)    
    
    num_grains_list=[None]*num_grain_files
    
    for i in np.arange(num_grain_files):
        num_grains_list[i]=grain_data_list[i].shape[0]
        
    num_grains=np.sum(num_grains_list)  
    
    grain_data=np.zeros([num_grains,grain_data_list[0].shape[1]])    
    
    for i in np.arange(num_grain_files):
        
        tmp=copy.copy(grain_data_list[i])
        
        if pos_offset is not None:
            pos_tile=np.tile(pos_offset[:,i],[num_grains_list[i],1])
            tmp[:,6:9]=tmp[:,6:9]+pos_tile
        #Needs Testing    
        if rotation_offset is not None:  
            rot_tile=np.tile(np.atleast_2d(rotation_offset[:,i]).T,[1,num_grains_list[i]])
            quat_tile=rot.quatOfExpMap(rot_tile)
            grain_quats=rot.quatOfExpMap(tmp[:,3:6].T)
            new_quats=rot.quatProduct(grain_quats,quat_tile)
            
            sinang = mutil.columnNorm(new_quats[1:,:])
            ang=2.*np.arcsin(sinang)
            axis   = mutil.unitVector(new_quats[1:,:])
            tmp[:,3:6]=np.tile(np.atleast_2d(ang).T,[1,3])*axis.T

            
        grain_data[int(np.sum(num_grains_list[:i])):int(np.sum(num_grains_list[:(i+1)])),:]=tmp
        

    old_grain_numbers=copy.copy(grain_data[:,0])
    grain_data[:,0]=np.arange(num_grains)    
    return grain_data,old_grain_numbers
Пример #3
0
def remove_duplicate_grains(grain_data,
                            qsyms,
                            dist_thresh=0.01,
                            misorient_thresh=0.1,
                            comp_diff=0.1):
    total_grains = grain_data.shape[0]

    all_comp = grain_data[:, 1]
    grain_quats = rot.quatOfExpMap(grain_data[:, 3:6].T)
    dup_list = np.array([])

    print 'Removing duplicate grains'
    for i in np.arange(total_grains - 1):
        cur_pos = grain_data[i, 3:6]
        other_pos = grain_data[(i + 1):, 3:6]
        xdist = cur_pos[0] - other_pos[:, 0]
        ydist = cur_pos[1] - other_pos[:, 1]
        zdist = cur_pos[2] - other_pos[:, 2]

        dist = np.sqrt(xdist**2. + ydist**2. + zdist**2.)

        if np.min(dist) < dist_thresh:

            q1 = sym.toFundamentalRegion(np.atleast_2d(grain_quats[:, i]).T,
                                         crysSym=qsyms)
            q2 = sym.toFundamentalRegion(np.atleast_2d(
                grain_quats[:, np.argmin(dist) + i + 1]).T,
                                         crysSym=qsyms)
            misorientation = rot.misorientation(q1, q2)[0] * 180. / np.pi

            if misorientation < misorient_thresh:
                dup_list = np.append(dup_list, np.argmin(dist) + i + 1)
                if (np.abs(all_comp[i] - all_comp[np.argmin(dist) + i + 1]) <=
                        comp_diff):
                    grain_data[
                        i, :] = (grain_data[i, :] +
                                 grain_data[np.argmin(dist) + i + 1, :]) / 2.
                elif ((all_comp[np.argmin(dist) + i + 1] - all_comp[i]) > 0):
                    grain_data[i, :] = grain_data[np.argmin(dist) + i + 1, :]

    grain_data = np.delete(grain_data, dup_list, axis=0)

    print 'Removed %d Grains' % (len(dup_list))

    grain_data[:, 0] = np.arange(grain_data.shape[0])

    return grain_data, dup_list
Пример #4
0
def remove_duplicate_grains(grain_data,qsyms,dist_thresh=0.01,misorient_thresh=0.1,comp_diff=0.1):
    total_grains=grain_data.shape[0]

    all_comp=grain_data[:,1]
    grain_quats=rot.quatOfExpMap(grain_data[:,3:6].T)
    dup_list=np.array([])    
    
    print 'Removing duplicate grains'
    for i in np.arange(total_grains-1):
        cur_pos=grain_data[i,3:6]
        other_pos=grain_data[(i+1):,3:6]
        xdist=cur_pos[0]-other_pos[:,0]
        ydist=cur_pos[1]-other_pos[:,1]
        zdist=cur_pos[2]-other_pos[:,2]
        
        dist=np.sqrt(xdist**2.+ydist**2.+zdist**2.)
        
        if np.min(dist)<dist_thresh:
            
            q1=sym.toFundamentalRegion(np.atleast_2d(grain_quats[:,i]).T,crysSym=qsyms)
            q2=sym.toFundamentalRegion(np.atleast_2d(grain_quats[:,np.argmin(dist)+i+1]).T,crysSym=qsyms)
            misorientation=rot.misorientation(q1,q2)[0]*180./np.pi

            if misorientation < misorient_thresh:             
                dup_list=np.append(dup_list,np.argmin(dist)+i+1)
                if (np.abs(all_comp[i] - all_comp[np.argmin(dist)+i+1]) <=comp_diff):
                    grain_data[i,:]=(grain_data[i,:]+grain_data[np.argmin(dist)+i+1,:])/2.
                elif ( (all_comp[np.argmin(dist)+i+1]-all_comp[i]) >0):
                    grain_data[i,:]=grain_data[np.argmin(dist)+i+1,:]
    
    grain_data=np.delete(grain_data,dup_list,axis=0)

    print 'Removed %d Grains' % (len(dup_list))

    grain_data[:,0]=np.arange(grain_data.shape[0])

    return grain_data,dup_list
Пример #5
0
                #==============================================================================
                #   MISORIENTATION
                #==============================================================================
                print('calculate misorientation')

                tmp_data_avg = np.loadtxt(grain_out_file)
                tmp_data_grain = np.loadtxt(grain_id_out_file)

                id_avg = tmp_data_avg[:, 0]
                ori_avg = tmp_data_avg[:, 3:6]
                id_mis = tmp_data_grain[:, 0]
                ori_mis = tmp_data_grain[:, 3:6]

                mis = np.zeros(grain_map_g.shape)

                q_mor = rot.quatOfExpMap(ori_mis.T)
                q_avg = rot.quatOfExpMap(ori_avg.T)

                material_file_loc = mat_file  # hexrd material file in cpickle format
                mat_name = 'ti7al'

                mat_list = cpl.load(open(material_file_loc, 'r'))
                mat_idx = np.where([
                    mat_list[i].name == mat_name for i in range(len(mat_list))
                ])[0]

                # grab plane data, and useful things hanging off of it
                pd = mat_list[mat_idx[0]].planeData
                qsyms = sym.quatOfLaueGroup(pd.getLaueGroup())

                for w in range(0, len(test[0])):
Пример #6
0
    fc_file = sorted(
        glob.glob(os.path.join(data_dir, fc_stem % det_key.lower())))
    if len(fc_file) != 1:
        raise (RuntimeError, 'cache file not found, or multiple found')
    else:
        ims = load_images(fc_file[0])
        imsd[det_key] = OmegaImageSeries(ims)

eta_ome = instrument.GenerateEtaOmeMaps(
    imsd,
    instr,
    pd,
    active_hkls=active_hkls,
    threshold=cfg.find_orientations.orientation_maps.threshold,
    ome_period=cfg.find_orientations.omega.period)

grains_data = np.loadtxt(ref_grains_out)
expmaps = grains_data[:, 3:6]
quats = rot.quatOfExpMap(expmaps.T)

#%%

for i in range(0, len(expmaps)):
    this_quat = quats[:, i]
    qball = quaternion_ball(this_quat, mis_thresh)
    test_compl = test_GOE(cfg, qball, eta_ome, eta_tol=0.25)
    GOE, compl = thresh_GOE(qball, test_compl, comp_thresh)

    print('Writing Grain %d' % i)
    write_GOE(GOE, compl, i, dump_dir)
cmaplist = [cmap(i) for i in range(cmap.N)]

#%%

symmetry_symbol = 'd6h'  #cubic high, d6h for hex high
crystal_symmetry = sym.quatOfLaueGroup(symmetry_symbol)

# grain = 97
# grain_id = int(grain_data['scan21'][grain,0])

# mis_ang = []
# rotmats_grain = []
# expmaps_grain = []
# Eulers_grain = np.zeros([len(no_load_scans),3])

quats_init = rot.quatOfExpMap(grain_data['scan21'][:, 3:6].T)

expmaps_init = grain_data['scan21'][:, 3:6].T

quats_final = rot.quatOfExpMap(
    (grain_data['scan%d' % no_load_scans[-1]][:, 3:6].T))

expmaps_final = grain_data['scan111'][:, 3:6].T

grainlist = []
for i in range(ngrains):
    mis = rot.misorientation(quats_init[:, i:i + 1], quats_final[:, i:i + 1],
                             (crystal_symmetry, ))[0]
    mis_deg = np.degrees(mis)
    if mis_deg > 0.05:
        grainlist.append(i)
Пример #8
0
for i in range(
        len(scanIDs)):  #puts all of the data from the FF into dictionaries
    grain_fname = '/Users/rachellim/Documents/Research/Dye_CHESS_Jan20/fd1-q-1_filtered/filtered_scan_%04d_grains.out' % scanIDs[
        i]
    stress_fname = '/Users/rachellim/Documents/Research/Dye_CHESS_Jan20/fd1-q-1_filtered_stress/scan_%04d_stress.cpl' % scanIDs[
        i]

    grain_data['scan%d' % scanIDs[i]] = np.loadtxt(grain_fname)
    stress_data['scan%d' % scanIDs[i]] = cpl.load(open(stress_fname))

    RSS_all[i, :, :] = stress_data['scan%d' % scanIDs[i]]['RSS']  #RSS

ngrains = len(RSS)

quats_init = rot.quatOfExpMap(grain_data['scan12'][:, 3:6].T)

#==============================================================================
# %%  Make color list
#==============================================================================

colors = np.arange(0, len(scanIDs))

colornums = np.arange(10, 256, 246 / len(scanIDs))
cmap = plt.cm.inferno_r
cmaplist = [cmap(i) for i in range(cmap.N)]

#%%

symmetry_symbol = 'd6h'  #cubic high, d6h for hex high
crystal_symmetry = sym.quatOfLaueGroup(symmetry_symbol)
Пример #9
0
#%%

delta_strain11 = np.diff(strain11)
delta_strain22 = np.diff(strain22)
delta_strain33 = np.diff(strain33)
delta_stress11 = np.diff(stress11)
delta_stress22 = np.diff(stress22)
delta_stress33 = np.diff(stress33)
delta_vonmises = np.diff(vonmises)
delta_hydrostatic = np.diff(hydrostatic)

#%% Calculate misorientation from initial orientation

mis = np.zeros([ngrains, len(scanIDs)])

quats_init = rot.quatOfExpMap(grain_data['scan%d' % scanIDs[0]][:, 3:6].T)

for i in range(len(scanIDs)):
    quats_this = rot.quatOfExpMap(grain_data['scan%d' % scanIDs[i]][:, 3:6].T)
    for j in range(len(quats_init.T)):
        mis[j, i] = np.degrees(
            rot.misorientation(quats_init[:, j:j + 1], quats_this[:,
                                                                  j:j + 1])[0])

#%% Stress reasonability check

mean_stress11 = np.mean(stress11, axis=0)
mean_stress22 = np.mean(stress22, axis=0)
mean_stress33 = np.mean(stress33, axis=0)
mean_vonmises = np.mean(vonmises, axis=0)
mean_hydrostatic = np.mean(hydrostatic, axis=0)