Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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