def test_IPF(self, lattice): direction = np.random.random(3) * 2.0 - 1 for rot in [Rotation.from_random() for r in range(n // 100)]: R = damask.Orientation(rot, lattice) color = R.IPFcolor(direction) for equivalent in R.equivalentOrientations(): assert np.allclose(color, R.IPFcolor(direction))
def test_add_IPFcolor(self, default, d): default.add_IPFcolor('orientation', d) loc = { 'orientation': default.get_dataset_location('orientation'), 'color': default.get_dataset_location('IPFcolor_[{} {} {}]'.format(*d)) } qu = default.read_dataset(loc['orientation']).view(np.double).reshape( -1, 4) crystal_structure = default.get_crystal_structure() in_memory = np.empty((qu.shape[0], 3), np.uint8) for i, q in enumerate(qu): o = damask.Orientation(q, crystal_structure).reduced() in_memory[i] = np.uint8(o.IPFcolor(np.array(d)) * 255) in_file = default.read_dataset(loc['color']) assert np.allclose(in_memory, in_file)
def test_IPF_cubic(self, color, lattice): cube = damask.Orientation(damask.Rotation(), lattice) for direction in set(permutations(np.array(color['direction']))): assert np.allclose(cube.IPFcolor(np.array(direction)), np.array(color['RGB']))
if errors != []: damask.util.croak(errors) table.close(dismiss = True) continue # ------------------------------------------ assemble header --------------------------------------- table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:])) table.labels_append(['{}_pole_{}{}{}'.format(i+1,*options.pole) for i in xrange(2)]) table.head_write() # ------------------------------------------ process data ------------------------------------------ outputAlive = True while outputAlive and table.data_read(): # read next data line of ASCII table if inputtype == 'eulers': o = damask.Orientation(Eulers = np.array(map(float,table.data[column:column+3]))*toRadians) elif inputtype == 'matrix': o = damask.Orientation(matrix = np.array(map(float,table.data[column:column+9])).reshape(3,3).transpose()) elif inputtype == 'frame': o = damask.Orientation(matrix = np.array(map(float,table.data[column[0]:column[0]+3] + \ table.data[column[1]:column[1]+3] + \ table.data[column[2]:column[2]+3])).reshape(3,3)) elif inputtype == 'quaternion': o = damask.Orientation(quaternion = np.array(map(float,table.data[column:column+4]))) rotatedPole = o.quaternion*pole # rotate pole according to crystal orientation (x,y) = rotatedPole[0:2]/(1.+abs(pole[2])) # stereographic projection table.data_append([np.sqrt(x*x+y*y),np.arctan2(y,x)] if options.polar else [x,y]) # cartesian coordinates outputAlive = table.data_write() # output processed line
]) if output == 'eulers': table.labels_append([ '{}_eulers({})'.format(i + 1, options.symmetry) for i in xrange(3) ]) table.head_write() # ------------------------------------------ process data ------------------------------------------ outputAlive = True while outputAlive and table.data_read( ): # read next data line of ASCII table if inputtype == 'eulers': o = damask.Orientation( Eulers=np.array(map(float, table.data[column:column + 3])) * toRadians, symmetry=options.symmetry).reduced() elif inputtype == 'matrix': o = damask.Orientation(matrix=np.array( map(float, table.data[column:column + 9])).reshape(3, 3).transpose(), symmetry=options.symmetry).reduced() elif inputtype == 'frame': o = damask.Orientation(matrix = np.array(map(float,table.data[column[0]:column[0]+3] + \ table.data[column[1]:column[1]+3] + \ table.data[column[2]:column[2]+3])).reshape(3,3), symmetry = options.symmetry).reduced() elif inputtype == 'quaternion': o = damask.Orientation(quaternion=np.array( map(float, table.data[column:column + 4])), symmetry=options.symmetry).reduced()
column = table.label_index(label) # ------------------------------------------ assemble header --------------------------------------- table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:])) table.labels_append(['{}_SphericalEulers'.format(1 + i) for i in range(3)]) table.head_write() # ------------------------------------------ process data ------------------------------------------ outputAlive = True while outputAlive and table.data_read( ): # read next data line of ASCII table if inputtype == 'eulers': o = damask.Orientation(Eulers=np.array( list(map(float, table.data[column:column + 3]))) * toRadians, symmetry=options.symmetry).reduced() elif inputtype == 'matrix': o = damask.Orientation(matrix=np.array( list(map(float, table.data[column:column + 9]))).reshape( 3, 3).transpose(), symmetry=options.symmetry).reduced() elif inputtype == 'frame': o = damask.Orientation(matrix = np.array(list(map(float,table.data[column[0]:column[0]+3] + \ table.data[column[1]:column[1]+3] + \ table.data[column[2]:column[2]+3]))).reshape(3,3), symmetry = options.symmetry).reduced() elif inputtype == 'quaternion': o = damask.Orientation(quaternion=np.array( list(map(float, table.data[column:column + 4]))), symmetry=options.symmetry).reduced()
# o = damask.Orientation(random=True, symmetry='tetragonal') # vector,sym_op = o.inversePole([0,0,1],SST=True) # q = o.equivalentQuaternions()[sym_op] # angles = np.array(q.asEulers(degrees=True)) # vector = vector/np.linalg.norm(vector) # X = vector[0]/(1 + abs(vector[2])) # Y = vector[1]/(1 + abs(vector[2])) # zeta = 0.0 if vector[0] == 0. and vector[1] == 0. else math.degrees(math.atan2(vector[1],vector[0])) # eta = math.degrees(math.acos(vector[2])) # o_convention = damask.Orientation(Eulers=np.radians(np.array([270. + zeta,eta,90.-zeta]))) # angle_conv = np.array([270. + zeta,eta,90.-zeta]) # angle_mis,axis = (o_convention.quaternion * q.conjugated()).asAngleAxis(degrees=True) # # print angle_mis,axis[2] # angle_mis = angle_mis * axis[2] o = damask.Orientation(random=True, symmetry='tetragonal') v, symOp = o.inversePole([0., 0., 1.]) print "vector", v, symOp, "\n" X = v[0] / (1. + abs(v[2])) Y = v[1] / (1. + abs(v[2])) p = o.equivalentOrientations()[symOp] eta = np.arccos(abs(v[2])) zeta = np.arctan2(v[1], v[0]) c = damask.Orientation(Eulers=np.array( [1.5 * np.pi + zeta, eta, 0.5 * np.pi - zeta]), symmetry='tetragonal') print "random", o.asEulers(degrees=True)
if options.verbose: bg.set_message('assigning grain IDs...') for z in xrange(grid[2]): for y in xrange(grid[1]): for x in xrange(grid[0]): if (myPos+1)%(N/500.) < 1: time_delta = (time.clock()-tick) * (N - myPos) / myPos if options.verbose: bg.set_message('(%02i:%02i:%02i) processing point %i of %i (grain count %i)...' %(time_delta//3600,time_delta%3600//60,time_delta%60,myPos,N,nGrains)) myData = table.data[index[myPos]] # read data for current grid point myPhase = int(myData[colPhase]) mySym = options.symmetry[min(myPhase,len(options.symmetry))-1] # take last specified option for all with higher index if inputtype == 'eulers': o = damask.Orientation(Eulers = myData[colOri:colOri+3]*toRadians, symmetry = mySym) elif inputtype == 'matrix': o = damask.Orientation(matrix = myData[colOri:colOri+9].reshape(3,3).transpose(), symmetry = mySym) elif inputtype == 'frame': o = damask.Orientation(matrix = np.hstack((myData[colOri[0]:colOri[0]+3], myData[colOri[1]:colOri[1]+3], myData[colOri[2]:colOri[2]+3], )).reshape(3,3), symmetry = mySym) elif inputtype == 'quaternion': o = damask.Orientation(quaternion = myData[colOri:colOri+4], symmetry = mySym) cos_disorientations = -np.ones(1,dtype='f') # largest possible disorientation closest_grain = -1 # invalid neighbor
# close table asciiTable.close(dismiss=True) # ----- count slip traces in each grain ----- # gids = set(texture_vctr) # get unique grain id gammas_gid = [] sfs_gid = [] qs_gid = [] # calculate grain average accumulated shear and Schmid factors for gid in gids: gid_idc = np.where(texture_vctr == gid)[0] gammas_gid.append(np.mean(gammas[gid_idc, :], axis=0)) sfs_gid.append(np.mean(sfs[gid_idc, :], axis=0)) # ----- get grain average orientation ----- # qs_tmp = qs[gid_idc, :] qs_tmp = [damask.Orientation(quaternion=damask.Quaternion(quatArray=q)) for q in qs_tmp] qs_gid.append(damask.Orientation.average(qs_tmp).asQuaternion()) gammaSum_gid = [sum(map(abs, gamma)) for gamma in gammas_gid] with open(fname.replace(".txt", ".grainSum.txt"), 'w') as f: outstr = '1 header\n gammaSum\n' outstr += "\n".join(map(str, gammaSum_gid)) f.write(outstr) # slip family ID sf_ids = [1]*3 + [2]*3 + [3]*6 + [4]*12 # write out the population file # --> all slip systems in all grains with open(fname.replace(".txt", ".population.txt"), 'w') as f:
action = 'store_true', help = 'angles are given in degrees [%default]') parser.add_option('-e', '--eulers', dest='eulers', type = 'float', nargs = 3, metavar = ' '.join(['float']*3), help = 'crystallographic orientation as euler angles') parser.set_defaults(eulers = (0.,0.,0.), # no rotation about 1,1,1 radians = False) (options, filenames) = parser.parse_args() eulers=np.array(options.eulers) if not options.radians: eulers*=(np.pi/180.) ori = damask.Orientation(matrix=np.dot(np.array([[0.0,-1.0,0.0],[-1.0,0.0,0.0],[0.0,0.0,-1.0]]), damask.Orientation(Eulers=eulers).asMatrix())) ori=damask.Orientation() coordinates=[] for x in np.linspace(-0.5,0.5,3): for y in np.linspace(-0.5,0.5,3): for z in np.linspace(-0.5,0.5,3): coordinates.append([x,y,z]) coordinates=np.array(coordinates) for i,c in enumerate(coordinates): coordinates[i,:] = np.dot(ori.asMatrix(),c) Miller110=np.array( [[ 0, 1, 1], [ 0,-1, 1], [ 1, 0, 1], [-1, 0, 1],