Changeset 2047


Ignore:
Timestamp:
Nov 12, 2015 4:55:14 PM (6 years ago)
Author:
toby
Message:

revise autoint to implement Reset -- redoes integration; warn on old image read

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r2043 r2047  
    22532253        self.IntgOutList = [] # list of integration tree item Ids created in G2IO.SaveIntegration
    22542254        self.autoIntFrame = None
     2255        self.IntegratedList = [] # list of integrated image files
    22552256        self.Sngl = False
    22562257        self.ifGetRing = False
     
    24202421    def OnImageRead(self,event):
    24212422        'Called to read in an image in any known format'
     2423        G2G.G2MessageBox(self,'Please use the Import/Image/... menu item rather than this','depreciating menu item')
    24222424        self.CheckNotebook()
    24232425        dlg = wx.FileDialog(
  • trunk/autoint.py

    r2026 r2047  
    3838            return
    3939
     40        # index of image tree items by file name:
     41        imageDict = {G2frame.PatternTree.GetItemPyData(
     42            G2gd.GetPatternTreeItemId(G2frame,G2frame.root,img))[1]:
     43            G2gd.GetPatternTreeItemId(G2frame,G2frame.root,img)
     44                     for img in G2gd.GetPatternTreeDataNames(G2frame,['IMG '])}
    4045        createdImageIdList = []
    4146        # loop over files that are found, reading in new ones
    4247        for newImage in self.currImageList:
    43             if newImage in self.IntegratedList: continue # already processed
    44             Comments,Data,Npix,Image = G2IO.GetImageData(G2frame,newImage)
    45             if not Npix:
    46                 print('problem reading '+newImage)
    47                 continue
    48             G2IO.LoadImage2Tree(newImage,G2frame,Comments,Data,Npix,Image)
     48            if newImage in self.G2frame.IntegratedList: continue # already integrated
     49            # has this image already been loaded?
     50            if newImage not in imageDict:
     51                Comments,Data,Npix,Image = G2IO.GetImageData(G2frame,newImage)
     52                if not Npix:
     53                    print('problem reading '+newImage)
     54                    continue
     55                G2IO.LoadImage2Tree(newImage,G2frame,Comments,Data,Npix,Image)
     56            else:
     57                G2frame.Image = imageDict[newImage]
    4958            # update controls from master
    5059            controlsDict = G2frame.PatternTree.GetItemPyData(
     
    5564                G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Masks'))
    5665            createdImageIdList.append(G2frame.Image) # save IMG Id
    57             self.IntegratedList.append(newImage) # save name of image so we don't process it again
     66            self.G2frame.IntegratedList.append(newImage) # save name of image so we don't process it again
    5867            #print('debug: read '+newImage)
    5968
     
    6978            G2frame.ImageZ = G2IO.GetImageData(G2frame,imagefile,True)
    7079            self.oldImagefile = '' # mark image as changed; reread as needed
     80            # simulate a Image Controls press, since that is where the
     81            # integration is hidden
    7182            G2imG.UpdateImageControls(G2frame,data,masks,IntegrateOnly=True)
    7283            # split name and control number
     
    7788            else:
    7889                namenum = ''
    79             # write out the images in the selected formats
     90            # write out the images in the selected formats and save the names,
     91            # reset will delete them
    8092            for Id in G2frame.IntgOutList:
    8193                treename = G2frame.PatternTree.GetItemText(Id)
     94                self.CreatedPWDRnames.append(treename)
    8295                Sdata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id, 'Sample Parameters'))
    8396                # determine the name for the current file
     
    142155            if not os.path.exists(self.params['outdir']):
    143156                os.makedirs(self.params['outdir'])
     157        if self.Reset: # after Reset has been pressed, delete all PWDR items
     158            # created after last Start was pressed
     159            G2frame = self.G2frame
     160            idlist = []
     161            item, cookie = G2frame.PatternTree.GetFirstChild(G2frame.root)
     162            while item:
     163                itemName = G2frame.PatternTree.GetItemText(item)
     164                if itemName in self.CreatedPWDRnames:
     165                    idlist.append(item)
     166                item, cookie = G2frame.PatternTree.GetNextChild(G2frame.root, cookie)
     167            for item in idlist:
     168                G2frame.PatternTree.Delete(item)
     169        self.Reset = False
     170        self.CreatedPWDRnames = [] # list of created PWDR tree item names
     171
    144172    def __init__(self,G2frame,PollTime=60.0):
    145173        def OnStart(event):
     
    172200                self.OnTimerLoop(None) # run once immediately and again after delay
    173201                self.timer.Start(int(1000*PollTime),oneShot=False)
     202                self.Status.SetStatusText('Press Pause to delay integration or Reset to prepare to reintegrate all images')
    174203            else:
    175204                btnstart.SetLabel('Resume')
    176205                if self.timer.IsRunning(): self.timer.Stop()
    177206                print('\nPausing autointegration\n')
    178 
    179         def OnStop(event):
    180             '''Called when Stop button is pressed. At present this only
    181             stops the processing loop (same as pressing Pause except the
    182             label is reset to "Start".)
     207                self.Status.SetStatusText('Press Resume to continue integration or Reset to prepare to reintegrate all images')
     208
     209        def OnReset(event):
     210            '''Called when Reset button is pressed. This stops the
     211            processing loop and resets the list of integrated files so
     212            all images can be reintegrated.
    183213            '''
    184             btnstart.SetLabel('Start')
     214            btnstart.SetLabel('Restart')
     215            self.Status.SetStatusText('Press Restart to reload and re-integrate images matching filter')
    185216            if self.timer.IsRunning(): self.timer.Stop()
     217            self.Reset = True
     218            self.G2frame.IntegratedList = []
    186219           
    187220        def OnQuit(event):
    188221            '''Stop the processing loop and close the Frame
    189222            '''
    190             # make sure we stop first
    191             OnStop(event)
    192             self.Destroy()
     223            if self.timer.IsRunning(): self.timer.Stop() # make sure we stop first
     224            wx.CallAfter(self.Destroy)
    193225           
    194226        def OnBrowse(event):
     
    265297        self.G2frame = G2frame
    266298        self.params = {}
     299        self.Reset = False
    267300        self.params['IMGfile'] = ''
    268301        self.params['MaskFile'] = ''
     
    277310        self.params['filter'] = '*'+os.path.splitext(fileroot)[1]
    278311        self.params['outdir'] = os.path.abspath(self.imagedir)
    279         # get image names that have already been read
    280         self.IntegratedList = []
    281         for img in G2gd.GetPatternTreeDataNames(G2frame,['IMG ']):
    282             self.IntegratedList.append(G2frame.PatternTree.GetItemPyData(
    283                 G2gd.GetPatternTreeItemId(G2frame,G2frame.root,img)
    284                 )[1])
    285            
     312        self.CreatedPWDRnames = [] # list of created PWDR tree item names
    286313        wx.Frame.__init__(self, G2frame,title='Automatic Integration')
     314        self.Status = self.CreateStatusBar()
     315        self.Status.SetStatusText('Press Start to load and integrate images matching filter')
    287316        mnpnl = wx.Panel(self)
    288317        mnsizer = wx.BoxSizer(wx.VERTICAL)
     
    375404        btnstart.Bind(wx.EVT_BUTTON, OnStart)
    376405        sizer.Add(btnstart)
    377         btnstop = wx.Button(mnpnl,  wx.ID_ANY, "Stop")
    378         btnstop.Bind(wx.EVT_BUTTON, OnStop)
     406        btnstop = wx.Button(mnpnl,  wx.ID_ANY, "Reset")
     407        btnstop.Bind(wx.EVT_BUTTON, OnReset)
    379408        sizer.Add(btnstop)
    380409        sizer.Add((20,-1),wx.EXPAND,1)
Note: See TracChangeset for help on using the changeset viewer.