Esempio n. 1
0
def misorientation_wrt_un_yplane(omega,plane_normal,coords,vec_proj=None):
    """
    Returns the misorientation of each voxel with respect its
    upper neighbor.

    Args:
        omega (np.array): Voxel based rotation matrices, plane only, sort
            before calling this function
        plane_normal (string) : String with either 'x','y',z' to indicate
            in which plane the misorientation should be evaluated
        coords (list(int)): 2 indices in a list
        vec_proj (np.array), optional: Vector to project misorientation on

    Returns:
        misorient (np.array): Misorientation angle of each voxel
            with respect to its upper neighbor.
    """
    if plane_normal=='y':

        idx = omega.shape[0]
        listx = range(0,idx)
        
        idy   = 1
        listy = [coords[1]+1]
        
        idz   = omega.shape[2]
        listz = range(0,idz-1)
        
    else:
        print 'not implemented'
        return
      
    misorient = np.zeros([idx, idy, idz-1])
    
    for ix,i in enumerate(listx):
        for iy,j in enumerate(listy):
            for iz,k in enumerate(listz):

                # Reference is this pixel
	        Rref = omega[i,j,k,:,:]

                R = omega[i,j-1,k+1,:,:]

                gamma, Rmis = calculate_gamma(Rref, R)

                if vec_proj is not None:
                    r = rot_mat_to_rot_vec(Rmis,gamma)#np.array([ Rmis[1,0], Rmis[0,2], Rmis[2,1] ])
                    gamma = np.dot(vec_proj, r)

                misorient[ix,iy,iz] = ch.rad_to_grad(gamma)

    return misorient
Esempio n. 2
0
def misorientation_KAM8_yplane(omega,plane_normal,coords,vec_proj=None):
    """
    Returns the misorientation of each voxel with respect its
    8 neighboring voxels

    Args:
        omega (np.array): Voxel based rotation matrices, plane only, sort
            before calling this function
        plane_normal (string) : String with either 'x','y',z' to indicate
            in which plane the misorientation should be evaluated
        coords (list(int)): 2 indices in a list
        vec_proj (np.array), optional: Vector to project misorientation on

    Returns:
        misorient (np.array): Misorientation angle of each voxel
            with respect to each of its 8 neighbor voxels.
    """

    print 'calculating misorientation projected in',vec_proj

    if plane_normal=='y':

        idx = omega.shape[0]
        listx = range(1,idx-1)
        
        idy   = 1
        listy = [coords[1]+1]
        
        idz   = omega.shape[2]
        listz = range(1,idz-1)
        
    else:
        print 'not implemented'
        return
      
    KAM8 = np.zeros([idx-2, idy, idz-2])

    for ix,i in enumerate(listx):
        for iy,j in enumerate(listy):
            for iz,k in enumerate(listz):

                gamma_sum = 0.
                Rmis_sum = 0.
                
                # average over 8 nearest neighbors
	        Rref = omega[i,j,k,:,:]

                # lower left
                R = omega[i-1,j-1,k-1,:,:]

                gamma, Rmis = calculate_gamma(Rref, R)

                if vec_proj is not None:
                    r = rot_mat_to_rot_vec(Rmis,gamma)#np.array([ Rmis[1,0], Rmis[0,2], Rmis[2,1] ])
                    gamma = np.dot(vec_proj, r)

                gamma_sum += gamma

                # lower
                R = omega[i-1,j-1,k,:,:]

                gamma, Rmis = calculate_gamma(Rref, R)

                if vec_proj is not None:
                    r = rot_mat_to_rot_vec(Rmis,gamma)#np.array([ Rmis[1,0], Rmis[0,2], Rmis[2,1] ])
                    gamma = np.dot(vec_proj, r)

                gamma_sum += gamma

                # lower right
                R = omega[i-1,j-1,k+1,:,:]

                gamma, Rmis = calculate_gamma(Rref, R)

                if vec_proj is not None:
                    r = rot_mat_to_rot_vec(Rmis,gamma)#np.array([ Rmis[1,0], Rmis[0,2], Rmis[2,1] ])
                    gamma = np.dot(vec_proj, r)

                gamma_sum += gamma

                # left
                R = omega[i,j-1,k-1,:,:]

                gamma, Rmis = calculate_gamma(Rref, R)

                if vec_proj is not None:
                    r = rot_mat_to_rot_vec(Rmis,gamma)#np.array([ Rmis[1,0], Rmis[0,2], Rmis[2,1] ])
                    gamma = np.dot(vec_proj, r)

                gamma_sum += gamma

                # right
                R = omega[i,j-1,k+1,:,:]

                gamma, Rmis = calculate_gamma(Rref, R)

                if vec_proj is not None:
                    r = rot_mat_to_rot_vec(Rmis,gamma)#np.array([ Rmis[1,0], Rmis[0,2], Rmis[2,1] ])
                    gamma = np.dot(vec_proj, r)

                gamma_sum += gamma

                # upper left
                R = omega[i+1,j-1,k-1,:,:]

                gamma, Rmis = calculate_gamma(Rref, R)

                if vec_proj is not None:
                    r = rot_mat_to_rot_vec(Rmis,gamma)#np.array([ Rmis[1,0], Rmis[0,2], Rmis[2,1] ])
                    gamma = np.dot(vec_proj, r)

                gamma_sum += gamma

                # upper
                R = omega[i+1,j-1,k,:,:]

                gamma, Rmis = calculate_gamma(Rref, R)

                if vec_proj is not None:
                    r = rot_mat_to_rot_vec(Rmis,gamma)#np.array([ Rmis[1,0], Rmis[0,2], Rmis[2,1] ])
                    gamma = np.dot(vec_proj, r)

                gamma_sum += gamma

                # upper right
                R = omega[i+1,j-1,k+1,:,:]

                gamma, Rmis = calculate_gamma(Rref, R)

                if vec_proj is not None:
                    r = rot_mat_to_rot_vec(Rmis,gamma)#np.array([ Rmis[1,0], Rmis[0,2], Rmis[2,1] ])
                    gamma = np.dot(vec_proj, r)

                gamma_sum += gamma

                val = gamma_sum/8.

                KAM8[ix,iy,iz] = ch.rad_to_grad(val)
                
    return KAM8
Esempio n. 3
0
def misorientation_wrt_coord(omega,plane_normal,coords,vec_proj=None):
    """
    Returns the misorientation of each voxel with respect to a
    reference coordinate.

    Args:
        omega (np.array): Voxel based rotation matrices, plane only, sort
            before calling this function
        plane_normal (string) : String with either 'x','y',z' to indicate
            in which plane the misorientation should be evaluated
        coords (list(int)): 2 indices in a list
        vec_proj (np.array), optional: Vector to project misorientation on

    Returns:
        misorient (np.array): Misorientation angle of each voxel
            with respect to given reference voxel.
    """

    print 'calculating misorientation projected in',vec_proj
    print 'reference position ', coords

    
    if plane_normal=='x':
        idx   = 1
        listx = [coords[0]]
        idy   = omega.shape[1]
        listy = range(idy)
        idz   = omega.shape[2]
        listz = range(idz)
    elif plane_normal=='y':
        idx = omega.shape[0]
        listx = range(idx)
        idy   = 1
        listy = [coords[1]]
        idz   = omega.shape[2]
        listz = range(idz)
    elif plane_normal=='z':
        idx   = omega.shape[0]
        listx = range(idx)
        idy   = omega.shape[1]
        listy = range(idy)
        idz   = 1
        listz = [coords[2]]
      
    misorient = np.zeros([idx, idy, idz])
  
    Rref = omega[coords[0],coords[1],coords[2],:,:]

    for ix,i in enumerate(listx):
        for iy,j in enumerate(listy):
            for iz,k in enumerate(listz):

	        R = omega[i,j,k,:,:]
	
	        gamma, Rmis = calculate_gamma(Rref, R)

                # project in desired direction, if necessary
                if vec_proj is not None:
                    r = rot_mat_to_rot_vec(Rmis,gamma) #np.array([ Rmis[1,0], Rmis[0,2], Rmis[2,1] ])

                    gamma = np.dot(vec_proj, r)
	
	        
	        misorient[ix,iy,iz] = ch.rad_to_grad(gamma)
	        	  
    return misorient