def MC_make_angles(R,U, gIs, sigmas,wmin,wmax): assert len(gIs) == len(sigmas) rIs = [] F = dot(R,U) FinvT = inv(F).T angles = [] for i in range(len(gIs)): gI = gIs[i] rI = dot(FinvT,gI) rI_angle_sol = Get_LLNL_Angles(rI, wavelength) ct = 0 s_tth, s_eta,s_w = sigmas[i] r_tth = numpy.random.normal(0, s_tth, 1) r_eta = numpy.random.normal(0, s_eta, 1) r_w = numpy.random.normal(0, s_w, 1) for key in rI_angle_sol.keys(): ct+=1 tth,eta,w = rI_angle_sol[key] w = mapOme(w,wmin,wmax) eta = mapOme(eta,-num.pi,num.pi) if w is not None: hit = [tth+r_tth,eta+r_eta,w + r_w] angles.append(hit) if ct==2: print 'double hit', gI, i, rI return angles
def MC_make_angles_(R,U,pVec,detectorGeom,planeData,omeMin,omeMax,tweak = False, stdev = rad(.1)): tmpDG = detector.DetectorGeomGE(detectorGeom, pVec=pVec) recips = planeData.makeRecipVectors(R = R, U = U) wavelength = planeData.wavelength nvecs = recips.shape[1] from data_class import inv_dict allangs = inv_dict() for i in range(nvecs): rI = recips[:,i] angle_sols = Get_LLNL_Angles(rI,wavelength) for key in angle_sols.keys(): tth,eta,w = angle_sols[key] w = mapOme(w,-num.pi,num.pi) if eta!=num.pi and eta!=-num.pi: eta = mapOme(eta,-num.pi,num.pi) if w<omeMin.getVal('radians') or w>omeMax.getVal('radians'): continue if w is not None: #pred_angle_vector = num.array(detectorGeom.xyoToAng(*(px,py,w))) tmpX, tmpY, tmpO = tmpDG.angToXYO([tth,tth],[eta,eta],[w,w]) tmpX = tmpX[0] tmpY = tmpY[0] tmpO = tmpO[0] if tweak: tmpX = tmpX + num.random.normal(0,stdev) tmpY = tmpY + num.random.normal(0,stdev) tmpO = tmpO + num.random.normal(0,stdev) tmpTTh, tmpEta, tmpOme = detectorGeom.xyoToAng(tmpX, tmpY, tmpO) tmpAngs = num.vstack([tmpTTh, tmpEta, tmpOme]) allangs.Add((i,key),(num.array((tmpTTh,tmpEta,tmpOme)),(stdev,stdev,stdev))) #fangs.append([tmpTTh,tmpEta,tmpOme]) return allangs
def MC_make_angles_nrb(R,U,pVec,detectorGeom,planeData,omeMin,omeMax,tweak = False, stdev = rad(.1)): angl,axxx = Rotations.angleAxisOfRotMat(R) Rparams0 = (angl*axxx).flatten() #import uncertainty_analysis tmpDG = detector.DetectorGeomGE(detectorGeom, pVec=pVec) #print 'recip vects...', recips = planeData.makeRecipVectors(R = R, U = U) #print 'made' wavelength = planeData.wavelength nvecs = recips.shape[1] from data_class import inv_dict #allangs = inv_dict() allangs = [] #import sys #print "nvecs",nvecs for j in range(10): print j, #print "done" for i in range(nvecs): #print i #sys.stdout.write(str(i)+ " ") rI = recips[:,i] #print "rI",rI,tweak if tweak: Rparams_tweak = numpy.random.normal([0,0,0],[stdev,stdev,stdev]) #Rparams = Rparams0 + Rparams_tweak Rtweak = Rotations.rotMatOfExpMap(Rparams_tweak) #print Rparams0, Rparams rI = num.dot(Rtweak,rI) angle_sols = Get_LLNL_Angles(rI,wavelength) #print rI, angle_sols for key in angle_sols.keys(): tth,eta,w = angle_sols[key] w = mapOme(w,-num.pi,num.pi) if eta!=num.pi and eta!=-num.pi: eta = mapOme(eta,-num.pi,num.pi) if w<omeMin.getVal('radians') or w>omeMax.getVal('radians'): continue if w is not None: #pred_angle_vector = num.array(detectorGeom.xyoToAng(*(px,py,w))) tmpX, tmpY, tmpO = tmpDG.angToXYO([tth,tth],[eta,eta],[w,w]) tmpX = tmpX[0] tmpY = tmpY[0] tmpO = tmpO[0] tmpTTh, tmpEta, tmpOme = detectorGeom.xyoToAng(tmpX, tmpY, tmpO) tmpAngs = num.vstack([tmpTTh, tmpEta, tmpOme]) #allangs.Add((i,key),(num.array((tmpTTh,tmpEta,tmpOme)),(stdev,stdev,stdev))) allangs.append([tmpTTh,tmpEta,tmpOme]) return num.array(allangs)
def MC_make_angles_grain(R,U, grainInstance, sigmas,wmin,wmax): #assert len(gIs) == len(sigmas) F = dot(R,U) FinvT = inv(F).T masterReflInfo = grainInstance.grainSpots hitRelfId = num.where(masterReflInfo['iRefl'] >= 0)[0] measHKLs = masterReflInfo['hkl'][hitRelfId, :] pred_rIs = num.dot( FinvT, num.dot(grainInstance.bMat, measHKLs.T) ) pred_rIs = UnMatlab(pred_rIs) rIs = [] wavelength = grainInstance.planeData.wavelength angles = [] for i in range(len(pred_rIs)): rI = pred_rIs[i] rI_angle_sol = Get_LLNL_Angles(rI, wavelength) ct = 0 (s_tth), (s_eta),(s_w) = sigmas[i] r_tth = float(numpy.random.normal(0, abs(s_tth), 1)) r_eta = float(numpy.random.normal(0, abs(s_eta), 1)) r_w = float(numpy.random.normal(0, abs(s_w), 1)) for key in rI_angle_sol.keys(): tth,eta,w = rI_angle_sol[key] w = mapOme(w,wmin,wmax) eta = mapOme(eta,-num.pi,num.pi) if eta==num.pi: print 'etapi' if w is not None and eta is not None: ct+=1 hit = [tth+r_tth,eta+r_eta,w + r_w] angles.append(hit) if ct==2: print 'double hit', i, rI if ct==0: print 'no solution',i,rI,rI_angle_sol return angles