Changeset 2339


Ignore:
Timestamp:
Jun 22, 2016 5:51:56 PM (7 years ago)
Author:
toby
Message:

fixup autoint bugs; change labels on autoint window during integrations

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIimage.py

    r2322 r2339  
    863863   
    864864def ImageIntegrate(image,data,masks,blkSize=128,dlg=None,returnN=False):
    865     'Needs a doc string'    #for q, log(q) bins need data['binType']
     865    'Integrate an image; called from OnIntegrateAll and OnIntegrate in G2imgGUI'    #for q, log(q) bins need data['binType']
    866866    import histogram2d as h2d
    867867    print 'Begin image integration'
     868    CancelPressed = False
    868869    LUtth = np.array(data['IOtth'])
    869870    LRazm = np.array(data['LRazimuth'],dtype=np.float64)
     
    905906            if dlg:
    906907                pause = dlg.Update(Nup)
     908                if not pause[0]: CancelPressed = True
    907909            Block = image[iBeg:iFin,jBeg:jFin]
    908910            t0 = time.time()
     
    913915            if dlg:
    914916                pause = dlg.Update(Nup)
     917                if not pause[0]: CancelPressed = True
    915918            tax = np.where(tax > LRazm[1],tax-360.,tax)                 #put azm inside limits if possible
    916919            tax = np.where(tax < LRazm[0],tax+360.,tax)
     
    935938            if dlg:
    936939                pause = dlg.Update(Nup)
     940                if not pause[0]: CancelPressed = True
    937941    t0 = time.time()
    938942    NST = np.array(NST,dtype=np.float)
     
    959963    if dlg:
    960964        pause = dlg.Update(Nup)
     965        if not pause[0]: CancelPressed = True
    961966    times[4] += time.time()-t0
    962967    print 'Step times: \n apply masks  %8.3fs xy->th,azm   %8.3fs fill map     %8.3fs \
     
    965970    print 'Integration complete'
    966971    if returnN:     #As requested by Steven Weigand
    967         return H0,H1,H2,NST,not pause[0]
     972        return H0,H1,H2,NST,CancelPressed
    968973    else:
    969         return H0,H1,H2,not pause[0]
     974        return H0,H1,H2,CancelPressed
    970975   
    971976def MakeStrStaRing(ring,Image,Controls):
  • trunk/GSASIIimgGUI.py

    r2338 r2339  
    228228        Nup = nXBlks*nYBlks*3+1     #exact count expected so AUTO_HIDE works!
    229229        if IntegrateOnly:
    230             pdlg = wx.ProgressDialog("Elapsed time","2D image integration\nCancel to pause",
     230            pdlg = wx.ProgressDialog("Elapsed time","2D image integration\nPress Cancel to pause after current image",
    231231                Nup,style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_CAN_ABORT)           
    232232        else:
     
    236236            sumImg = GetImageZ(G2frame,data)
    237237            G2frame.Integrate = G2img.ImageIntegrate(sumImg,data,masks,blkSize,pdlg)
     238            G2frame.PauseIntegration = G2frame.Integrate[-1]
    238239            del sumImg  #force cleanup
    239240            Id = G2IO.SaveIntegration(G2frame,G2frame.PickId,data,(event is None))
     
    245246                pdlg.Destroy()
    246247        for item in G2frame.MakePDF: item.Enable(True)
    247         G2frame.PauseIntegration = G2frame.Integrate[-1]
    248248       
    249249    def OnIntegrateAll(event):
     
    404404                        S = File.readline()
    405405                        continue
    406                     [key,val] = S[:-1].split(':',1)
     406                    [key,val] = S.strip().split(':',1)
    407407                    if key in ['type','calibrant','binType','SampleShape',]:    #strings
    408408                        save[key] = val
     
    13241324                        S = File.readline()
    13251325                        continue
    1326                     [key,val] = S[:-1].split(':')
     1326                    [key,val] = S.strip().split(':',1)
    13271327                    if key in ['Points','Rings','Arcs','Polygons','Frames','Thresholds']:
    13281328                        if ignoreThreshold and key == 'Thresholds':
     
    19831983            S = File.readline()
    19841984            continue
    1985         [key,val] = S[:-1].split(':')
     1985        [key,val] = S.strip().split(':',1)
    19861986        if key in ['Points','Rings','Arcs','Polygons','Frames','Thresholds']:
    19871987            save[key] = eval(val)
     
    20042004            S = File.readline()
    20052005            continue
    2006         [key,val] = S[:-1].split(':')
     2006        [key,val] = S.strip().split(':',1)
    20072007        if key in ['type','calibrant','binType','SampleShape',]:    #strings
    20082008            save[key] = val
     
    21052105            if self.btnstart.GetLabel() != 'Pause':
    21062106                self.btnstart.SetLabel('Pause')
     2107                self.Status.SetStatusText('Press Pause to delay integration or Reset to prepare to reintegrate all images')
    21072108                if self.timer.IsRunning(): self.timer.Stop()
    21082109                self.PreventReEntryTimer = False
    21092110                self.StartLoop()
    2110                 self.OnTimerLoop(None) # run once immediately and again after delay
    2111                 self.timer.Start(int(1000*PollTime),oneShot=False)
    2112                 self.Status.SetStatusText('Press Pause to delay integration or Reset to prepare to reintegrate all images')
    2113             else:
    2114                 self.btnstart.SetLabel('Resume')
    2115                 if self.timer.IsRunning(): self.timer.Stop()
    2116                 print('\nPausing autointegration\n')
    2117                 self.Status.SetStatusText('Press Resume to continue integration or Reset to prepare to reintegrate all images')
    2118                 self.Pause = True
    2119 
     2111                self.OnTimerLoop(None) # run once immediately
     2112                if not self.Pause:
     2113                    # no pause, so start timer to check for new files
     2114                    self.timer.Start(int(1000*PollTime),oneShot=False)
     2115                    return
     2116            # we will get to this point if Paused
     2117            self.OnPause()
     2118           
    21202119        def OnReset(event):
    21212120            '''Called when Reset button is pressed. This stops the
     
    23022301        self.btnstart.Bind(wx.EVT_BUTTON, OnStart)
    23032302        sizer.Add(self.btnstart)
    2304         btnstop = wx.Button(mnpnl,  wx.ID_ANY, "Reset")
    2305         btnstop.Bind(wx.EVT_BUTTON, OnReset)
    2306         sizer.Add(btnstop)
     2303        self.btnreset = wx.Button(mnpnl,  wx.ID_ANY, "Reset")
     2304        self.btnreset.Bind(wx.EVT_BUTTON, OnReset)
     2305        sizer.Add(self.btnreset)
    23072306        sizer.Add((20,-1),wx.EXPAND,1)
    2308         btnquit = wx.Button(mnpnl,  wx.ID_ANY, "Close")
    2309         btnquit.Bind(wx.EVT_BUTTON, OnQuit)
    2310         sizer.Add(btnquit)
     2307        self.btnclose = wx.Button(mnpnl,  wx.ID_ANY, "Close")
     2308        self.btnclose.Bind(wx.EVT_BUTTON, OnQuit)
     2309        sizer.Add(self.btnclose)
    23112310        sizer.Add((20,-1))
    23122311        mnsizer.Add(sizer,0,wx.EXPAND|wx.BOTTOM|wx.TOP,5)
     
    23542353        return
    23552354       
     2355    def OnPause(self):
     2356        '''Respond to Pause, changes text on button/Status line, if needed
     2357        Stops timer
     2358        self.Pause should already be True
     2359        '''
     2360        if self.timer.IsRunning(): self.timer.Stop()
     2361        if self.btnstart.GetLabel() == 'Restart':
     2362            return
     2363        if self.btnstart.GetLabel() != 'Resume':
     2364            print('\nPausing autointegration\n')
     2365            self.btnstart.SetLabel('Resume')
     2366            self.Status.SetStatusText(
     2367                    'Press Resume to continue integration or Reset to prepare to reintegrate all images')
     2368        self.Pause = True
     2369           
    23562370    def IntegrateImage(self,img):
    23572371        '''Integrates a single image'''
     
    24012415                print('writing file '+fil+dfmt)
    24022416                G2IO.ExportPowder(G2frame,treename,fil,dfmt)
     2417               
     2418    def EnableButtons(self,flag):
     2419        '''Turns the buttons at window bottom "off" when integration is running
     2420        '''
     2421        for item in (self.btnstart,self.btnreset,self.btnclose):
     2422            item.Enable(flag)
     2423        if flag:
     2424            self.btnstart.SetLabel('Pause')
     2425        else:
     2426            self.btnstart.SetLabel('(running)')
     2427        wx.Yield()
    24032428               
    24042429    def ResetFromTable(self,dist):
     
    25312556            # update masks from master w/o Thresholds
    25322557            ImageMasks.update(self.ImageMasks)
    2533             self.IntegrateImage(img)
    2534             self.Pause = G2frame.PauseIntegration
     2558            self.EnableButtons(False)
     2559            try:
     2560                self.IntegrateImage(img)
     2561            finally:
     2562                self.EnableButtons(True)
     2563            self.Pause |= G2frame.PauseIntegration
    25352564            self.G2frame.oldImagefile = '' # mark image as changed; reread as needed
    25362565            wx.Yield()
     
    25382567            wx.Yield()
    25392568            if self.Pause:
    2540                 self.btnstart.SetLabel('Resume')
    2541                 if self.timer.IsRunning(): self.timer.Stop()
    2542                 print('\nPausing autointegration\n')
    2543                 self.Status.SetStatusText('Press Resume to continue integration or Reset to prepare to reintegrate all images')
     2569                self.OnPause()
     2570                self.PreventReEntryTimer = False
    25442571                return
    25452572
     
    25612588                # now integrate the image
    25622589                img = G2frame.PatternTree.GetItemText(imgId)
    2563                 self.IntegrateImage(img)
     2590                self.EnableButtons(False)
     2591                try:
     2592                    self.IntegrateImage(img)
     2593                finally:
     2594                    self.EnableButtons(True)
     2595                self.Pause |= G2frame.PauseIntegration
    25642596                self.G2frame.oldImagefile = '' # mark image as changed; reread as needed
    25652597                wx.Yield()
    25662598                self.ShowMatchingFiles(self.params['filter'])
    25672599                wx.Yield()
    2568                 self.Pause = G2frame.PauseIntegration
    2569                 print 'pause',self.Pause
    25702600            if self.Pause:
    2571                 self.btnstart.SetLabel('Resume')
    2572                 if self.timer.IsRunning(): self.timer.Stop()
    2573                 print('\nPausing autointegration\n')
    2574                 self.Status.SetStatusText('Press Resume to continue integration or Reset to prepare to reintegrate all images')
     2601                self.OnPause()
    25752602                break
    25762603       
Note: See TracChangeset for help on using the changeset viewer.