Changeset 4589


Ignore:
Timestamp:
Oct 12, 2020 9:35:16 AM (13 months ago)
Author:
vondreele
Message:

new GetDetectorXY routine to return correct xy positions for arcs, rings, etc. on 2D image plots; needed for detectors rotated by 2-theta.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIimage.py

    r4587 r4589  
    469469    dxy = peneCorr(tth,dep,dist)
    470470    return GetEllipse2(tth,dxy,dist,cent,tilt,phi)
     471
     472def GetDetectorXY(dsp,azm,data):
     473    '''Get detector x,y position from d-spacing (dsp), azimuth (azm,deg)
     474    & image controls dictionary (data) - new version
     475    it seems to be only used in plotting
     476    '''
     477    def LinePlaneCollision(planeNormal, planePoint, rayDirection, rayPoint, epsilon=1e-6):
     478     
     479        ndotu = planeNormal.dot(rayDirection)
     480        if ndotu < epsilon:   
     481                return None
     482     
     483        w = rayPoint - planePoint
     484        si = -planeNormal.dot(w) / ndotu
     485        Psi = w + si * rayDirection + planePoint
     486        return Psi
     487   
     488   
     489    dist = data['distance']
     490    cent = data['center']
     491    T = makeMat(data['tilt'],0)
     492    R = makeMat(data['rotation'],2)
     493    MN = np.inner(R,np.inner(R,T))
     494    iMN= nl.inv(MN)
     495    tth = 2.0*npasind(data['wavelength']/(2.*dsp))
     496    vect = np.array([npsind(tth)*npcosd(azm),npsind(tth)*npsind(azm),npcosd(tth)])
     497    dxyz0 = np.inner(np.array([0.,0.,1.0]),MN)    #tilt detector normal
     498    dxyz0 += np.array([0.,0.,dist])                 #translate to distance
     499    dxyz0 = np.inner(dxyz0,makeMat(data['det2theta'],1).T)   #rotate on 2-theta
     500    dxyz1 = np.inner(np.array([cent[0],cent[1],0.]),MN)    #tilt detector cent
     501    dxyz1 += np.array([0.,0.,dist])                 #translate to distance
     502    dxyz1 = np.inner(dxyz1,makeMat(data['det2theta'],1).T)   #rotate on 2-theta
     503    xyz = LinePlaneCollision(dxyz0,dxyz1,vect,2.*dist*vect)
     504    if xyz is None:
     505        return None
     506    xyz = np.inner(xyz,makeMat(-data['det2theta'],1).T)
     507    xyz -= np.array([0.,0.,dist])                 #translate back
     508    xyz = np.inner(xyz,iMN)
     509    return xyz[:2]+cent
    471510       
    472 def GetDetectorXY(dsp,azm,data):
     511def GetDetectorXY2(dsp,azm,data):
    473512    '''Get detector x,y position from d-spacing (dsp), azimuth (azm,deg)
    474513    & image controls dictionary (data)
     
    513552        xy = -np.array([xy[0]*cosd(phi)+xy[1]*sind(phi),xy[0]*sind(phi)-xy[1]*cosd(phi)])
    514553        xy += cent
     554    if data['det2theta']:
     555        xy[0] += dist*nptand(data['det2theta']+data['tilt']*npsind(data['rotation']))
    515556    return xy
    516557   
  • trunk/GSASIIimgGUI.py

    r4582 r4589  
    16921692    def OnFindSpotMask(event):
    16931693        'Do auto search for spot masks'
    1694         if wx.MessageDialog(G2frame.dataWindow,'NB: This is slow (5-10min)',
    1695             'Spot mask search', wx.OK|wx.CANCEL).ShowModal() == wx.ID_OK:
    1696             Controls = G2frame.GPXtree.GetItemPyData(
    1697                 G2gd.GetGPXtreeItemId(G2frame,G2frame.Image,'Image Controls'))
    1698             wave = Controls['wavelength']
    1699             LUtth = np.array(Controls['IOtth'])
    1700             dsp0 = wave/(2.0*sind(LUtth[0]/2.0))
    1701             dsp1 = wave/(2.0*sind(LUtth[1]/2.0))
    1702             x0 = G2img.GetDetectorXY(dsp0,0.0,Controls)[0]
    1703             x1 = G2img.GetDetectorXY(dsp1,0.0,Controls)[0]   
    1704             nChans = int(1000*(x1-x0)/Controls['pixelSize'][0])//2
    1705             dlg = wx.ProgressDialog("Auto spot masking for %d bins"%nChans,"Processed 2-theta rings = ",nChans+3,
    1706                 style = wx.PD_ELAPSED_TIME|wx.PD_CAN_ABORT)
    1707             time0 = time.time()
    1708             data['SpotMask']['spotMask'] = G2img.AutoSpotMask(G2frame.ImageZ,data,Controls,nChans,dlg)
    1709             print(' Spot masksearch time: %.2f m'%((time.time()-time0)/60.))
    1710             wx.CallAfter(UpdateMasks,G2frame,data)
    1711             wx.CallAfter(G2plt.PlotExposedImage,G2frame,event=event)
    1712         else:
    1713             print(' Spot mask search not done')
     1694        try:
     1695            if wx.MessageDialog(G2frame.dataWindow,'NB: This is slow (5-10min)',
     1696                'Spot mask search', wx.OK|wx.CANCEL).ShowModal() == wx.ID_OK:
     1697                Controls = G2frame.GPXtree.GetItemPyData(
     1698                    G2gd.GetGPXtreeItemId(G2frame,G2frame.Image,'Image Controls'))
     1699                wave = Controls['wavelength']
     1700                LUtth = np.array(Controls['IOtth'])
     1701                dsp0 = wave/(2.0*sind(LUtth[0]/2.0))
     1702                dsp1 = wave/(2.0*sind(LUtth[1]/2.0))
     1703                x0 = G2img.GetDetectorXY(dsp0,0.0,Controls)[0]
     1704                x1 = G2img.GetDetectorXY(dsp1,0.0,Controls)[0]
     1705                if x0 is None or x1 is None:
     1706                    raise Exception
     1707                nChans = int(1000*(x1-x0)/Controls['pixelSize'][0])//2
     1708                dlg = wx.ProgressDialog("Auto spot masking for %d bins"%nChans,"Processed 2-theta rings = ",nChans+3,
     1709                    style = wx.PD_ELAPSED_TIME|wx.PD_CAN_ABORT)
     1710                time0 = time.time()
     1711                data['SpotMask']['spotMask'] = G2img.AutoSpotMask(G2frame.ImageZ,data,Controls,nChans,dlg)
     1712                print(' Spot masksearch time: %.2f m'%((time.time()-time0)/60.))
     1713                wx.CallAfter(UpdateMasks,G2frame,data)
     1714                wx.CallAfter(G2plt.PlotExposedImage,G2frame,event=event)
     1715            else:
     1716                print(' Spot mask search not done')
     1717        except:
     1718            print('Invalid limits - spot mask search not done')
    17141719           
    17151720    def OnAutoFindSpotMask(event):
     
    17321737                    dsp1 = wave/(2.0*sind(LUtth[1]/2.0))
    17331738                    x0 = G2img.GetDetectorXY(dsp0,0.0,Controls)[0]
    1734                     x1 = G2img.GetDetectorXY(dsp1,0.0,Controls)[0]   
     1739                    x1 = G2img.GetDetectorXY(dsp1,0.0,Controls)[0]
     1740                    if x0 is None or x1 is None:
     1741                        raise Exception
    17351742                    nChans = int(1000*(x1-x0)/Controls['pixelSize'][0])//2
    17361743                    dlg = wx.ProgressDialog("Spot mask search for %d bins"%nChans,"Processed 2-theta rings = ",nChans+3,
     
    17391746                    Mask['SpotMask']['spotMask'] = G2img.AutoSpotMask(G2frame.ImageZ,Mask,Controls,nChans,dlg)
    17401747                    print(' Spot mask search time: %.2f m'%((time.time()-time0)/60.))
     1748        except:
     1749            print('Invalid limits - spot mask search not done')
    17411750        finally:
    17421751            dlg.Destroy()
  • trunk/GSASIIplot.py

    r4583 r4589  
    68226822    Azm = np.linspace(*aR)
    68236823    for azm in Azm:
    6824         xy1.append(G2img.GetDetectorXY(Dsp(angI,wave),azm,Data))      #what about hyperbola
    6825         xy2.append(G2img.GetDetectorXY(Dsp(angO,wave),azm,Data))      #what about hyperbola
     6824        XY = G2img.GetDetectorXY(Dsp(angI,wave),azm,Data)
     6825        if XY is not None:
     6826            xy1.append(XY)      #what about hyperbola
     6827        XY = G2img.GetDetectorXY(Dsp(angO,wave),azm,Data)
     6828        if XY is not None:
     6829            xy2.append(XY)      #what about hyperbola
    68266830    return np.array(xy1).T,np.array(xy2).T
    68276831
     
    69006904                else:
    69016905                    xcent,ycent = Data['center']
     6906                    if Data['det2theta']:
     6907                        xcent += Data['distance']*nptand(-Data['tilt']*npsind(Data['rotation'])+Data['det2theta'])
    69026908                    xpos = event.xdata-xcent
    69036909                    ypos = event.ydata-ycent
     
    69136919            else:
    69146920                xcent,ycent = Data['center']
     6921                if Data['det2theta']:
     6922                    xcent += Data['distance']*nptand(-Data['tilt']*npsind(Data['rotation'])+Data['det2theta'])
    69156923                xpos = event.xdata
    69166924                ypos = event.ydata
     
    76527660    acolor = mpl.cm.get_cmap(Data['color'])
    76537661    xcent,ycent = Data['center']
     7662    if Data['det2theta']:
     7663        xcent += Data['distance']*nptand(Data['tilt']*npsind(Data['rotation'])+Data['det2theta'])
    76547664    Plot.set_xlabel('Image x-axis, mm',fontsize=12)
    76557665    Plot.set_ylabel('Image y-axis, mm',fontsize=12)
     
    77067716            if ellO:
    77077717                xyO = []
     7718                arcxO = []
     7719                arcxI = []
    77087720                for azm in Azm:
    77097721                    xy = G2img.GetDetectorXY(dspO,azm,Data)
     
    77147726                    arcxO,arcyO = xyO.T               
    77157727                    Plot.plot(arcxO,arcyO,picker=3,label='Otth')
    7716             if ellO and ellI:
     7728            if ellO and ellI and len(arcxO) and len(arcxI):
    77177729                Plot.plot([arcxI[0],arcxO[0]],[arcyI[0],arcyO[0]],picker=3,label='Lazm')
    77187730                Plot.plot([arcxI[-1],arcxO[-1]],[arcyI[-1],arcyO[-1]],picker=3,label='Uazm')
     
    77227734                    cake += delAzm/2.
    77237735                ind = np.searchsorted(Azm,cake)
    7724                 Plot.plot([arcxI[ind],arcxO[ind]],[arcyI[ind],arcyO[ind]],color='k',dashes=(5,5))
     7736                if len(arcxO) and len(arcxI):
     7737                    Plot.plot([arcxI[ind],arcxO[ind]],[arcyI[ind],arcyO[ind]],color='k',dashes=(5,5))
    77257738        if 'linescan' in Data and Data['linescan'][0] and G2frame.GPXtree.GetItemText(G2frame.PickId) in ['Image Controls',]:
    77267739            azm = Data['linescan'][1]-Data['azmthOff']
Note: See TracChangeset for help on using the changeset viewer.