Changeset 3186 for trunk/GSASIIimgGUI.py


Ignore:
Timestamp:
Dec 9, 2017 8:54:59 AM (5 years ago)
Author:
vondreele
Message:

revisions to integrate images so that masks are reused if not changed in integrate all & auto integrate

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIimgGUI.py

    r3184 r3186  
    1919import copy
    2020import glob
     21import time
    2122import re
    2223import math
     
    144145################################################################################                   
    145146blkSize = 1024   #this seems to be optimal; will break in polymask if >1024
    146 def UpdateImageControls(G2frame,data,masks,useTA=None,IntegrateOnly=False):
     147def UpdateImageControls(G2frame,data,masks,useTA=None,useMask=None,IntegrateOnly=False):
    147148    '''Shows and handles the controls on the "Image Controls"
    148149    data tree entry
     
    238239        G2frame.slideSizer.GetChildren()[4].Window.SetValue(Imin)   #tricky
    239240         
    240     def OnIntegrate(event,useTA=None):
     241    def OnIntegrate(event,useTA=None,useMask=None):
    241242        '''Integrate image in response to a menu event or from the AutoIntegrate
    242243        dialog. In the latter case, event=None.
     
    247248        wx.BeginBusyCursor()
    248249        try:
    249             G2frame.Integrate = G2img.ImageIntegrate(sumImg,data,masks,blkSize,useTA=useTA)           
     250            G2frame.Integrate = G2img.ImageIntegrate(sumImg,data,masks,blkSize,useTA=useTA,useMask=useMask)           
    250251        finally:
    251252            wx.EndBusyCursor()   
     
    270271                    pId = 0
    271272                    oldData = {'tilt':0.,'distance':0.,'rotation':0.,'center':[0.,0.],'DetDepth':0.,'azmthOff':0.}
     273                    oldMhash = 0
    272274                    for icnt,item in enumerate(items):
    273275                        GoOn = dlgp.Update(icnt)
     
    283285                                same = False
    284286                        if not same:
    285                             print('Use new image controls')
     287                            t0 = time.time()
    286288                            useTA = G2img.MakeUseTA(Data,blkSize)
     289                            print(' Use new image controls; new xy -> th,azm time %.3f'%(time.time()-t0))
    287290                        Masks = G2frame.GPXtree.GetItemPyData(
    288291                            G2gd.GetGPXtreeItemId(G2frame,G2frame.Image,'Masks'))
     292                        Mhash = hash(str(Masks))
     293                        if  Mhash != oldMhash:
     294                            t0 = time.time()
     295                            useMask = G2img.MakeUseMask(Data,Masks,blkSize)
     296                            print(' Use new mask; make mask time: %.3f'%(time.time()-t0))
     297                            oldMhash = Mhash
    289298                        image = GetImageZ(G2frame,Data)
    290                         G2frame.Integrate = G2img.ImageIntegrate(image,Data,Masks,blkSize,useTA=useTA)
     299                        G2frame.Integrate = G2img.ImageIntegrate(image,Data,Masks,blkSize,useTA=useTA,useMask=useMask)
    291300                        del image   #force cleanup
    292301                        pId = G2IO.SaveIntegration(G2frame,CId,Data)
     
    11931202   
    11941203    if IntegrateOnly:
    1195         OnIntegrate(None,useTA=useTA)
     1204        OnIntegrate(None,useTA=useTA,useMask=useMask)
    11961205        return
    11971206   
     
    27712780        self.Pause = True
    27722781           
    2773     def IntegrateImage(self,img,useTA=None):
     2782    def IntegrateImage(self,img,useTA=None,useMask=None):
    27742783        '''Integrates a single image. Ids for created PWDR entries (more than one is possible)
    27752784        are placed in G2frame.IntgOutList
     
    27972806        # simulate a Image Controls press, since that is where the
    27982807        # integration is hidden
    2799         UpdateImageControls(G2frame,data,masks,useTA=useTA,IntegrateOnly=True)
     2808        UpdateImageControls(G2frame,data,masks,useTA=useTA,useMask=useMask,IntegrateOnly=True)
    28002809        G2frame.IntegratedList.append(img) # note this as integrated
    28012810        # split name and control number
     
    29742983        This is called only after the "Start" button is pressed (then its label reads "Pause").
    29752984        '''
    2976         def AutoIntegrateImage(imgId,useTA=None):
     2985        def AutoIntegrateImage(imgId,useTA=None,useMask=None):
    29772986            '''Integrates an image that has been read into the data tree and updates the
    29782987            AutoInt window.
     
    29923001            self.EnableButtons(False)
    29933002            try:
    2994                 self.IntegrateImage(img,useTA=useTA)
     3003                self.IntegrateImage(img,useTA=useTA,useMask=useMask)
    29953004            finally:
    29963005                self.EnableButtons(True)
     
    30793088        # have not yet been processed           
    30803089        oldData = {'tilt':0.,'distance':0.,'rotation':0.,'center':[0.,0.],'DetDepth':0.,'azmthOff':0.}
    3081         self.useTA = None
     3090        oldMhash = 0
     3091        if 'useTA' not in dir(self):    #initial definition; reuse if after Resume
     3092            self.useTA = None
     3093            self.useMask = None
    30823094        for img in G2gd.GetGPXtreeDataNames(G2frame,['IMG ']):
    30833095            imgId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,img)
     
    30893101            Data = G2frame.GPXtree.GetItemPyData(
    30903102                G2gd.GetGPXtreeItemId(G2frame,imgId, 'Image Controls'))
    3091             same = True
     3103            sameTA = True
    30923104            for item in ['tilt','distance','rotation','center','DetDepth','azmthOff']:
    30933105                if Data[item] != oldData[item]:
    3094                     same = False
    3095             if not same:
    3096                 print('Use new image controls')
     3106                    sameTA = False
     3107            if not sameTA:
     3108                t0 = time.time()
    30973109                self.useTA = G2img.MakeUseTA(Data,blkSize)
    3098             AutoIntegrateImage(imgId,self.useTA)
     3110                print(' Use new image controls; xy->th,azm mtime: %.3f'%(time.time()-t0))
     3111            Mask = G2frame.GPXtree.GetItemPyData(
     3112                G2gd.GetGPXtreeItemId(G2frame,imgId, 'Masks'))
     3113            Mhash = hash(str(Mask))
     3114            if  Mhash != oldMhash:
     3115                t0 = time.time()
     3116                self.useMask = G2img.MakeUseMask(Data,Mask,blkSize)
     3117                print(' Use new mask; make mask time: %.3f'%(time.time()-t0))
     3118                oldMhash = Mhash
     3119            AutoIntegrateImage(imgId,self.useTA,self.useMask)
    30993120            oldData = Data
    31003121            if self.pdfControls: AutoComputePDF(imgId)
     
    31073128
    31083129        # loop over image files matching glob, reading in any new ones
     3130        if self.useTA is None or self.useMask is None:
     3131            print('Integration will not be fast; there is no beginning image controls')     #TODO: work this out??
    31093132        for newImage in self.currImageList:
    31103133            if newImage in imageFileList or self.Pause: continue # already read?
    31113134            for imgId in G2IO.ReadImages(G2frame,newImage):
    3112                 AutoIntegrateImage(imgId,self.useTA)
     3135                AutoIntegrateImage(imgId,self.useTA,self.useMask)
    31133136                if self.pdfControls: AutoComputePDF(imgId)
    31143137                self.Pause |= G2frame.PauseIntegration
Note: See TracChangeset for help on using the changeset viewer.