Changeset 3173


Ignore:
Timestamp:
Dec 5, 2017 3:23:50 PM (4 years ago)
Author:
vondreele
Message:

ensure limits on multiple powder patterns from integration are independent
Integrate All & Auto integrate now reuse x,y --> 2th,azm maps if image controls unchanged - much faster multiple integrations

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r3161 r3173  
    745745        G2frame.IntgOutList.append(Id)
    746746        G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Comments'),Comments)                   
    747         G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Limits'),[tuple(Xminmax),Xminmax])
     747        G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Limits'),copy.deepcopy([tuple(Xminmax),Xminmax]))
    748748        if 'PWDR' in Aname:
    749749            G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Background'),[['chebyschev',1,3,1.0,0.0,0.0],
  • trunk/GSASIIimage.py

    r3154 r3173  
    815815    return True
    816816   
    817 def Make2ThetaAzimuthMap(data,masks,iLim,jLim,tamp,times): #most expensive part of integration!
     817def Make2ThetaAzimuthMap(data,iLim,jLim,times): #most expensive part of integration!
    818818    'Needs a doc string'
    819819    #transforms 2D image from x,y space to 2-theta,azimuth space based on detector orientation
     820    pixelSize = data['pixelSize']
     821    scalex = pixelSize[0]/1000.
     822    scaley = pixelSize[1]/1000.
     823   
     824    tay,tax = np.mgrid[iLim[0]+0.5:iLim[1]+.5,jLim[0]+.5:jLim[1]+.5]         #bin centers not corners
     825    tax = np.asfarray(tax*scalex,dtype=np.float32).flatten()
     826    tay = np.asfarray(tay*scaley,dtype=np.float32).flatten()
     827    nI = iLim[1]-iLim[0]
     828    nJ = jLim[1]-jLim[0]
     829    t0 = time.time()
     830    TA = np.array(GetTthAzmG(np.reshape(tax,(nI,nJ)),np.reshape(tay,(nI,nJ)),data))     #includes geom. corr. as dist**2/d0**2 - most expensive step
     831    times[1] += time.time()-t0
     832    TA[1] = np.where(TA[1]<0,TA[1]+360,TA[1])
     833    return TA           #2-theta, azimuth & geom. corr. arrays
     834
     835def MakeMaskMap(data,masks,iLim,jLim,tamp,times):
    820836    pixelSize = data['pixelSize']
    821837    scalex = pixelSize[0]/1000.
     
    840856                tay,len(polygon),polygon,tamp)[:nI*nJ]))
    841857    if True:
    842 #    try:
    843 #        import spotmask as sm
    844 #        spots = masks['Points'].T
    845 #        if len(spots):
    846 #            tam = ma.mask_or(tam,ma.getmask(sm.spotmask(nI*nJ,tax,
    847 #                    tay,len(spots),spots,tamp)[:nI*nJ]))
    848 #    except:
    849858        for X,Y,rsq in masks['Points'].T:
    850859            tam = ma.mask_or(tam,ma.getmask(ma.masked_less((tax-X)**2+(tay-Y)**2,rsq)))
    851860    if tam.shape: tam = np.reshape(tam,(nI,nJ))
    852861    times[0] += time.time()-t0
    853     t0 = time.time()
    854     TA = np.array(GetTthAzmG(np.reshape(tax,(nI,nJ)),np.reshape(tay,(nI,nJ)),data))     #includes geom. corr. as dist**2/d0**2 - most expensive step
    855     times[1] += time.time()-t0
    856     TA[1] = np.where(TA[1]<0,TA[1]+360,TA[1])
    857     return np.array(TA),tam           #2-theta, azimuth & geom. corr. arrays & position mask
     862    return tam           #position mask
    858863
    859864def Fill2ThetaAzimuthMap(masks,TA,tam,image):
     
    880885    return tax,tay,taz,tad,tabs
    881886
    882 def ImageIntegrate(image,data,masks,blkSize=128,returnN=False):
     887def MakeUseTA(data,blkSize=128):
     888    times = [0,0,0,0,0]
     889    Nx,Ny = data['size']
     890    nXBlks = (Nx-1)//blkSize+1
     891    nYBlks = (Ny-1)//blkSize+1
     892    useTA = []
     893    for iBlk in range(nYBlks):
     894        iBeg = iBlk*blkSize
     895        iFin = min(iBeg+blkSize,Ny)
     896        useTAj = []
     897        for jBlk in range(nXBlks):
     898            jBeg = jBlk*blkSize
     899            jFin = min(jBeg+blkSize,Nx)
     900            TA = Make2ThetaAzimuthMap(data,(iBeg,iFin),(jBeg,jFin),times)          #2-theta & azimuth arrays & create position mask
     901            useTAj.append(TA)
     902        useTA.append(useTAj)
     903    return useTA
     904
     905def ImageIntegrate(image,data,masks,blkSize=128,returnN=False,useTA=None):
    883906    'Integrate an image; called from OnIntegrateAll and OnIntegrate in G2imgGUI'    #for q, log(q) bins need data['binType']
    884907    import histogram2d as h2d
     
    921944            jFin = min(jBeg+blkSize,Nx)
    922945            # next is most expensive step!
    923             TA,tam = Make2ThetaAzimuthMap(data,Masks,(iBeg,iFin),(jBeg,jFin),tamp,times)           #2-theta & azimuth arrays & create position mask
     946            if useTA:
     947                TA = useTA[iBlk][jBlk]
     948            else:
     949                TA = Make2ThetaAzimuthMap(data,(iBeg,iFin),(jBeg,jFin),times)           #2-theta & azimuth arrays & create position mask
     950            tam = MakeMaskMap(data,Masks,(iBeg,iFin),(jBeg,jFin),tamp,times)
    924951            Block = image[iBeg:iFin,jBeg:jFin]
    925952            t0 = time.time()
    926953            tax,tay,taz,tad,tabs = Fill2ThetaAzimuthMap(Masks,TA,tam,Block)    #and apply masks
    927             del TA; del tam
    928954            times[2] += time.time()-t0
    929955            tax = np.where(tax > LRazm[1],tax-360.,tax)                 #put azm inside limits if possible
  • trunk/GSASIIimgGUI.py

    r3172 r3173  
    143143##### Image Controls
    144144################################################################################                   
    145 def UpdateImageControls(G2frame,data,masks,IntegrateOnly=False):
     145blkSize = 1024   #this seems to be optimal; will break in polymask if >1024
     146def UpdateImageControls(G2frame,data,masks,useTA=None,IntegrateOnly=False):
    146147    '''Shows and handles the controls on the "Image Controls"
    147148    data tree entry
     
    237238        MaxSizer.GetChildren()[5].Window.SetValue(Imin)   #tricky
    238239         
    239     def OnIntegrate(event):
     240    def OnIntegrate(event,useTA=None):
    240241        '''Integrate image in response to a menu event or from the AutoIntegrate
    241242        dialog. In the latter case, event=None.
     
    243244        '''
    244245        CleanupMasks(masks)
    245         blkSize = 1024   #this seems to be optimal; will break in polymask if >1024
    246 #        blkSize = 128   #this seems to be optimal; will break in polymask if >1024
    247246        sumImg = GetImageZ(G2frame,data)
    248247        wx.BeginBusyCursor()
    249248        try:
    250             G2frame.Integrate = G2img.ImageIntegrate(sumImg,data,masks,blkSize)           
     249            G2frame.Integrate = G2img.ImageIntegrate(sumImg,data,masks,blkSize,useTA=useTA)           
    251250        finally:
    252251            wx.EndBusyCursor()   
     
    269268                    style = wx.PD_ELAPSED_TIME|wx.PD_CAN_ABORT)
    270269                try:
     270                    pId = 0
     271                    oldData = {'tilt':0.,'distance':0.,'rotation':0.,'center':[0.,0.],'DetDepth':0.,'azmthOff':0.}
    271272                    for icnt,item in enumerate(items):
    272273                        GoOn = dlgp.Update(icnt)
     
    277278                        CId = G2gd.GetGPXtreeItemId(G2frame,G2frame.Image,'Image Controls')
    278279                        Data = G2frame.GPXtree.GetItemPyData(CId)
     280                        same = True
     281                        for item in ['tilt','distance','rotation','center','DetDepth','azmthOff']:
     282                            if Data[item] != oldData[item]:
     283                                same = False
     284                        if not same:
     285                            print('Use new image controls')
     286                            useTA = G2img.MakeUseTA(Data,blkSize)
    279287                        Masks = G2frame.GPXtree.GetItemPyData(
    280288                            G2gd.GetGPXtreeItemId(G2frame,G2frame.Image,'Masks'))
    281289                        image = GetImageZ(G2frame,Data)
    282                         blkSize = 128   #this seems to be optimal; will break in polymask if >1024
    283                         G2frame.Integrate = G2img.ImageIntegrate(image,Data,Masks,blkSize)
     290                        G2frame.Integrate = G2img.ImageIntegrate(image,Data,Masks,blkSize,useTA=useTA)
    284291                        del image   #force cleanup
    285292                        pId = G2IO.SaveIntegration(G2frame,CId,Data)
     293                        oldData = Data
    286294                finally:   
    287295                    dlgp.Destroy()
    288296                    G2frame.EnablePlot = True
    289                     G2frame.GPXtree.SelectItem(pId)
    290                     G2frame.GPXtree.Expand(pId)
    291                     G2frame.PatternId = pId
     297                    if pId:
     298                        G2frame.GPXtree.SelectItem(pId)
     299                        G2frame.GPXtree.Expand(pId)
     300                        G2frame.PatternId = pId
    292301        finally:
    293302            dlg.Destroy()
     
    11841193   
    11851194    if IntegrateOnly:
    1186         OnIntegrate(None)
     1195        OnIntegrate(None,useTA=useTA)
    11871196        return
    11881197   
     
    27152724        self.Pause = True
    27162725           
    2717     def IntegrateImage(self,img):
     2726    def IntegrateImage(self,img,useTA=None):
    27182727        '''Integrates a single image. Ids for created PWDR entries (more than one is possible)
    27192728        are placed in G2frame.IntgOutList
     
    27412750        # simulate a Image Controls press, since that is where the
    27422751        # integration is hidden
    2743         UpdateImageControls(G2frame,data,masks,IntegrateOnly=True)
     2752        UpdateImageControls(G2frame,data,masks,useTA=useTA,IntegrateOnly=True)
    27442753        G2frame.IntegratedList.append(img) # note this as integrated
    27452754        # split name and control number
     
    29192928        This is called only after the "Start" button is pressed (then its label reads "Pause").
    29202929        '''
    2921         def AutoIntegrateImage(imgId):
     2930        def AutoIntegrateImage(imgId,useTA=None):
    29222931            '''Integrates an image that has been read into the data tree and updates the
    29232932            AutoInt window.
     
    29362945            self.EnableButtons(False)
    29372946            try:
    2938                 self.IntegrateImage(img)
     2947                self.IntegrateImage(img,useTA=useTA)
    29392948            finally:
    29402949                self.EnableButtons(True)
     
    30223031        # integrate the images that have already been read in, but
    30233032        # have not yet been processed           
     3033        oldData = {'tilt':0.,'distance':0.,'rotation':0.,'center':[0.,0.],'DetDepth':0.,'azmthOff':0.}
    30243034        for img in G2gd.GetGPXtreeDataNames(G2frame,['IMG ']):
    30253035            imgId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,img)
     
    30293039            # skip if already integrated
    30303040            if img in G2frame.IntegratedList: continue
    3031             AutoIntegrateImage(imgId)
    3032             #self.Pause |= G2frame.PauseIntegration
    3033             #if self.Pause:
    3034             #    self.OnPause()
    3035             #    self.PreventReEntryTimer = False
    3036             #    return
     3041            Data = G2frame.GPXtree.GetItemPyData(
     3042                G2gd.GetGPXtreeItemId(G2frame,imgId, 'Image Controls'))
     3043            same = True
     3044            for item in ['tilt','distance','rotation','center','DetDepth','azmthOff']:
     3045                if Data[item] != oldData[item]:
     3046                    same = False
     3047            if not same:
     3048                print('Use new image controls')
     3049                self.useTA = G2img.MakeUseTA(Data,blkSize)
     3050            AutoIntegrateImage(imgId,self.useTA)
     3051            oldData = Data
    30373052            if self.pdfControls: AutoComputePDF(imgId)
    30383053            self.Pause |= G2frame.PauseIntegration
     
    30463061            if newImage in imageFileList or self.Pause: continue # already read?
    30473062            for imgId in G2IO.ReadImages(G2frame,newImage):
    3048                 AutoIntegrateImage(imgId)           
    3049                 #self.Pause |= G2frame.PauseIntegration
    3050                 #if self.Pause:
    3051                 #    self.OnPause()
    3052                 #    self.PreventReEntryTimer = False
    3053                 #    return
     3063                AutoIntegrateImage(imgId,self.useTA)
    30543064                if self.pdfControls: AutoComputePDF(imgId)
    30553065                self.Pause |= G2frame.PauseIntegration
  • trunk/GSASIIpwdGUI.py

    r3171 r3173  
    13751375                    Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item)
    13761376                    G2frame.GPXtree.SetItemPyData(
    1377                         G2gd.GetGPXtreeItemId(G2frame,Id,'Limits'),copy.copy(data))
     1377                        G2gd.GetGPXtreeItemId(G2frame,Id,'Limits'),copy.deepcopy(data))
    13781378        finally:
    13791379            dlg.Destroy()
Note: See TracChangeset for help on using the changeset viewer.