Changeset 4582


Ignore:
Timestamp:
Oct 4, 2020 2:51:27 PM (13 months ago)
Author:
vondreele
Message:

New image calibration/integration routines for 2-theta stepped detectors. Integration now faster
removed unused variables from peneCorr

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIimage.py

    r4572 r4582  
    7373    return Inside
    7474   
    75 def peneCorr(tth,dep,dist,tilt=0.,azm=0.):
     75def peneCorr(tth,dep,dist):
    7676    'Needs a doc string'
    77 #    return dep*(1.-npcosd(abs(tilt*npsind(azm))-tth*npcosd(azm)))  #something wrong here
    7877    return dep*(1.-npcosd(tth))*dist**2/1000.         #best one
    79 #    return dep*npsind(tth)             #not as good as 1-cos2Q
    8078       
    8179def makeMat(Angle,Axis):
     
    182180        tth = 2.0*npasind(parms['wave']/(2.*dsp))
    183181        phi0 = npatan2d(y-parms['det-Y'],x-parms['det-X'])
    184         dxy = peneCorr(tth,parms['dep'],parms['dist'],parms['tilt'],phi0)
     182        dxy = peneCorr(tth,parms['dep'],parms['dist'])
    185183        stth = npsind(tth)
    186184        cosb = npcosd(parms['tilt'])
     
    323321        tth = 2.0*npasind(parms['wavelength']/(2.*dsp))
    324322        phi0 = npatan2d(y-detY,x-detX)
    325         dxy = peneCorr(tth,parms['dep'],dist-deltaDist,parms['tilt'],phi0)
     323        dxy = peneCorr(tth,parms['dep'],dist-deltaDist)
    326324        stth = npsind(tth)
    327325        cosb = npcosd(parms['tilt'])
     
    469467    tth = 2.0*asind(data['wavelength']/(2.*dsp))
    470468    dist = data['distance']
    471     dxy = peneCorr(tth,dep,dist,tilt)
     469    dxy = peneCorr(tth,dep,dist)
    472470    return GetEllipse2(tth,dxy,dist,cent,tilt,phi)
    473471       
     
    546544    Z = np.dot(X,makeMat(tilt,0)).T[2]
    547545    tth = npatand(np.sqrt(dx**2+dy**2-Z**2)/(dist-Z))
    548     dxy = peneCorr(tth,dep,dist,tilt,npatan2d(dy,dx))
     546    dxy = peneCorr(tth,dep,dist)
    549547    DX = dist-Z+dxy
    550548    DY = np.sqrt(dx**2+dy**2-Z**2)
     
    565563def GetTthAzmG(x,y,data):
    566564    '''Give 2-theta, azimuth & geometric corr. values for detector x,y position;
    567      calibration info in data - only used in integration
     565     calibration info in data - only used in integration - old version
    568566    '''
    569567    'Needs a doc string - checked OK for ellipses & hyperbola'
    570568    tilt = data['tilt']
    571569    dist = data['distance']/npcosd(tilt)
     570    MN = -np.inner(makeMat(data['rotation'],2),makeMat(tilt,0))
     571    dx = x-data['center'][0]
     572    dy = y-data['center'][1]
     573    dz = np.dot(np.dstack([dx.T,dy.T,np.zeros_like(dx.T)]),MN).T[2]   
     574    xyZ = dx**2+dy**2-dz**2   
     575    tth0 = npatand(np.sqrt(xyZ)/(dist-dz))
     576    dzp = peneCorr(tth0,data['DetDepth'],dist)
     577    tth = npatan2d(np.sqrt(xyZ),dist-dz+dzp)
     578    azm = (npatan2d(dy,dx)+data['azmthOff']+720.)%360.
     579   
     580    distsq = data['distance']**2
    572581    x0 = data['distance']*nptand(tilt)
    573582    x0x = x0*npcosd(data['rotation'])
    574583    x0y = x0*npsind(data['rotation'])
    575     MN = -np.inner(makeMat(data['rotation'],2),makeMat(tilt,0))
    576     distsq = data['distance']**2
     584    G = ((dx-x0x)**2+(dy-x0y)**2+distsq)/distsq       #for geometric correction = 1/cos(2theta)^2 if tilt=0.
     585    return tth,azm,G
     586
     587def GetTthAzmG2(x,y,data):
     588    '''Give 2-theta, azimuth & geometric corr. values for detector x,y position;
     589     calibration info in data - only used in integration
     590     checked OK for ellipses & hyperbola
     591     '''
     592     
     593    def costth(xyz):
     594        u = xyz/nl.norm(xyz,axis=-1)[:,:,nxs]
     595        return np.dot(u,np.array([0.,0.,1.]))
     596       
     597#zero detector 2-theta: tested with tilted images - perfect integrations
    577598    dx = x-data['center'][0]
    578599    dy = y-data['center'][1]
     600    tilt = data['tilt']
     601    dist = data['distance']/npcosd(tilt)    #sample-beam intersection point
     602    T = makeMat(tilt,0)
     603    R = makeMat(data['rotation'],2)
     604    MN = np.inner(R,np.inner(R,T))
     605    dxyz0 = np.inner(np.dstack([dx,dy,np.zeros_like(dx)]),MN)    #correct for 45 deg tilt
     606    dxyz0 += np.array([0.,0.,dist])
     607    if data['DetDepth']:
     608        ctth0 = costth(dxyz0)
     609        tth0 = npacosd(ctth0)
     610        dzp = peneCorr(tth0,data['DetDepth'],dist,tilt)
     611        dxyz0[:,:,2] += dzp
     612#non zero detector 2-theta:   
     613    tthMat = makeMat(data['det2theta'],1)
     614    dxyz = np.inner(dxyz0,tthMat.T)
     615    ctth = costth(dxyz)
     616    tth = npacosd(ctth)
     617    azm = (npatan2d(dxyz[:,:,1],dxyz[:,:,0])+data['azmthOff']+720.)%360.
     618# G-calculation       
     619    x0 = data['distance']*nptand(tilt)
     620    x0x = x0*npcosd(data['rotation'])
     621    x0y = x0*npsind(data['rotation'])
     622    distsq = data['distance']**2
    579623    G = ((dx-x0x)**2+(dy-x0y)**2+distsq)/distsq       #for geometric correction = 1/cos(2theta)^2 if tilt=0.
    580     Z = np.dot(np.dstack([dx.T,dy.T,np.zeros_like(dx.T)]),MN).T[2]
    581     xyZ = dx**2+dy**2-Z**2   
    582     tth = npatand(np.sqrt(xyZ)/(dist-Z))
    583     dxy = peneCorr(tth,data['DetDepth'],dist,tilt,npatan2d(dy,dx))
    584     tth = npatan2d(np.sqrt(xyZ),dist-Z+dxy)
    585     azm = (npatan2d(dy,dx)+data['azmthOff']+720.)%360.
    586624    return tth,azm,G
    587625
     
    12421280    if 'SASD' not in data['type']:
    12431281        H0 *= np.array(G2pwd.Polarization(data['PolaVal'][0],H2[:-1],0.)[0])
    1244     H0 /= npcosd(H2[:-1])           #**2? I don't think so, **1 is right for powders
     1282    H0 /= np.abs(npcosd(H2[:-1]-np.abs(data['det2theta'])))           #parallax correction
    12451283    if 'SASD' in data['type']:
    12461284        H0 /= npcosd(H2[:-1])           #one more for small angle scattering data?
  • trunk/GSASIIimgGUI.py

    r4571 r4582  
    183183    distSizer.Add(polaCalib,0,WACV)
    184184    mainSizer.Add(distSizer,0)
     185#patch
    185186    if 'samplechangerpos' not in data or data['samplechangerpos'] is None:
    186187        data['samplechangerpos'] = 0.0
    187     mainSizer.Add(wx.StaticText(G2frame.dataWindow,label='Sample changer position %.2f mm'%data['samplechangerpos']),0,WACV)
     188    if 'det2theta' not in data:
     189        data['det2theta'] = 0.0
     190#end patch
     191    tthSizer = wx.BoxSizer(wx.HORIZONTAL)
     192    tthSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Detector 2-theta: '),0,WACV)
     193    tthSizer.Add(G2G.ValidatedTxtCtrl(G2frame.dataWindow,data,'det2theta',xmin=-180.,xmax=180.,nDig=(10,2)),0,WACV)
     194    tthSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Sample changer position %.2f mm '%data['samplechangerpos']),0,WACV)
     195    mainSizer.Add(tthSizer,0)
    188196    G2frame.dataWindow.SetDataSize()
    189197
     
    191199##### Image Controls
    192200################################################################################                   
    193 blkSize = 128   #128 seems to be optimal; will break in polymask if >1024
     201blkSize = 128 #128 seems to be optimal; will break in polymask if >1024
    194202def UpdateImageControls(G2frame,data,masks,useTA=None,useMask=None,IntegrateOnly=False):
    195203    '''Shows and handles the controls on the "Image Controls"
     
    221229    if 'linescan' not in data:
    222230        data['linescan'] = [False,0.0]      #includes azimuth to draw line scan
     231    if 'det2theta' not in data:
     232        data['det2theta'] = 0.0
    223233#end patch
    224234
     
    489499                try:
    490500                    pId = 0
    491                     oldData = {'tilt':0.,'distance':0.,'rotation':0.,'center':[0.,0.],'DetDepth':0.,'azmthOff':0.}
     501                    oldData = {'tilt':0.,'distance':0.,'rotation':0.,'center':[0.,0.],'DetDepth':0.,'azmthOff':0.,'det2theta':0.}
    492502                    oldMhash = 0
    493503                    for icnt,item in enumerate(items):
     
    501511                        Data = G2frame.GPXtree.GetItemPyData(CId)
    502512                        same = True
    503                         for item in ['tilt','distance','rotation','DetDepth','azmthOff']:
     513                        for item in ['tilt','distance','rotation','DetDepth','azmthOff','det2theta']:
    504514                            if Data[item] != oldData[item]:
    505515                                same = False
     
    551561                items = dlg.GetSelections()
    552562                G2frame.EnablePlot = False
    553                 for item in items:
     563                for item in items:      #preserve some values
    554564                    name = Names[item]
    555565                    Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,name)
     
    561571                    Data['GonioAngles'] = oldData.get('GonioAngles', [0.,0.,0.])
    562572                    Data['samplechangerpos'] = oldData.get('samplechangerpos',0.0)
     573                    Data['det2theta'] = oldData.get('det2theta',0.0)
    563574                    Data['ring'] = []
    564575                    Data['rings'] = []
  • trunk/GSASIIlattice.py

    r4531 r4582  
    744744    cosP = np.inner(u,np.inner(G,v))
    745745    return cosP
    746    
     746
    747747def CosSinAngle(U,V,G):
    748748    """ calculate sin & cos of angle between U & V in generalized coordinates
  • trunk/imports/G2img_CBF.py

    r4213 r4582  
    5757    cent = [0,0]
    5858    wave = 1.54187  #default <CuKa>
     59    det2theta = 0.0
    5960    dist = 1000.
    6061    byteOrd = '<'
     
    9192        elif 'Number-of-Elements' in line:
    9293            Npix = int(fields[1])
     94        elif 'Detector_2theta' in line:
     95            det2theta = float(fields[2])
    9396    nxy = sizexy[0]*sizexy[1]
    9497    cent = [cent[0]*pixSize[0]/1000.,cent[1]*pixSize[1]/1000.]
     
    105108    image = np.reshape(image,(sizexy[1],sizexy[0]))
    106109    print ('import time: %.3f'%(time.time()-time0))
    107     data = {'pixelSize':pixSize,'wavelength':wave,'distance':dist,'center':cent,'size':sizexy}
     110    data = {'pixelSize':pixSize,'wavelength':wave,'distance':dist,'center':cent,'size':sizexy,'det2theta':det2theta}
    108111    Npix = sizexy[0]*sizexy[1]
    109112   
Note: See TracChangeset for help on using the changeset viewer.