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_vectors_from_spots_grain(R,U,gwInstance,pVec,wmin,wmax, tweak = False): angles = MC_make_angles_from_spots_grain(R,U,gwInstance,pVec,wmin,wmax,tweak) wavelength = gwInstance.planeData.wavelength from data_class import inv_dict vecs = inv_dict() for key in angles.keys(): if angles.triggerdict[key]==1: for sol in angles[key]: (tth,eta,w), mu_uncs = sol rI = makeARecipVector((tth,eta,w), wavelength) vecs.Add(key,[rI,mu_rI]) else: (tth,eta,w), mu_uncs = sol rI = makeARecipVector((tth,eta,w), wavelength) vecs.Add(key,[rI,mu_rI]) return vecs
def MC_make_angles_from_spots_grain(R,U,gwInstance,pVec,wmin,wmax,tweak = False): pxmin,pxmax = 0,2048 pymin,pymax = 0,2048 tmpDG = gwInstance.detectorGeom.__class__(gwInstance.detectorGeom) tmpDG.pVec = pVec wavelength = gwInstance.planeData.wavelength F = num.dot(R,U) FinvT = inv(F).T masterReflInfo = gwInstance.grainSpots hitRelfId = num.where(masterReflInfo['iRefl'] >= 0)[0] measHKLs = masterReflInfo['hkl'][hitRelfId, :] gIs = num.dot(gwInstance.bMat, measHKLs.T) pred_rIs = num.dot(FinvT, gIs) import data_class angles = data_class.inv_dict() hits =0 for i in range(len(hitRelfId)): try: Id = hitRelfId[i] spotId = masterReflInfo['iRefl'][Id] rI = pred_rIs[:,i] 'measured angles and uncertainties' spot = gwInstance.spots._Spots__spots[spotId] angCOM, angCOM_unc = spot.angCOM(useFit=True, getUncertainties=True) xyoCOM = num.array(spot.detectorGeom.angToXYO(*angCOM)).flatten() new_angCOM = tmpDG.xyoToAng(*xyoCOM) #print 'newang old',new_angCOM,angCOM mus = num.hstack(new_angCOM).flatten() mu_uncs = num.hstack(angCOM_unc).flatten() meas_tth, meas_eta, meas_ome = mus meas_angle_vector = mus 'predicted angles computation' rI_xyosol = Get_LLNL_Pixel_Sols_From_Recip_Vector(rI,tmpDG,pVec,wavelength) # rI_xyosol = Get_LLNL_Angles(rI,wavelength) hits =0 for key in rI_xyosol.keys(): w,px,py= rI_xyosol[key] if px<pxmin or px>pxmax: continue if py<pymin or py>pymax: continue #if eta==num.pi or w ==num.pi: # continue 'here, eta, w are defined in the range [0,2pi] constrained to be counterclockwise, to match' w = mapOme(w,-num.pi,num.pi) #eta = mapOme(eta,-num.pi,num.pi) if w<wmin or w>wmax: continue #print 'meas sol', xyoCOM, (px,py,w) if w is not None: pred_angle_vector = num.array(tmpDG.xyoToAng(*(px,py,w))) #pred_angle_vector = num.array([tth,eta,w]) 'found predicted solution matching measured' print 'pred',pred_angle_vector, mus pred_sol = pred_angle_vector if tweak: m1,m2,m3 = pred_angle_vector u1,u2,u3 = mu_uncs #m1 = m1+num.random.normal(0,abs(u1)*tweak) #m2 = m2+num.random.normal(0,abs(u2)*tweak) #m3 = m3+num.random.normal(0,abs(u3)*tweak) m1 = m1+num.random.normal(0,tweak) m2 = m2+num.random.normal(0,tweak) m3 = m3+num.random.normal(0,tweak) pred_angle_vector = num.array([m1,m2,m3]) angles.Add(Id, [pred_angle_vector,mu_uncs]) hits=1 except RuntimeError: # print 'runtimeerror' continue if hits==0: print 'missing hit',Id,spotId return angles