Changeset 2020


Ignore:
Timestamp:
Oct 20, 2015 6:34:38 PM (6 years ago)
Author:
toby
Message:

after work w/Andrey

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoint.py

    r2019 r2020  
    11import os
    22import wx
     3import copy
     4import glob
    35import GSASIIpath
    46import GSASIIIO as G2IO
    57import GSASIIctrls as G2G
     8import GSASIIgrid as G2gd
    69#('xye','fxye','xy','chi')
    710'''
     
    2124      processing loop. (Default is 3.0 seconds.)
    2225    '''
    23     def OnTimer(self,event):
     26    def OnTimerLoop(self,event):
    2427        '''A method that is called every :meth:`PollTime` seconds that is
    2528        used to check for new files and process them. This is called only
    2629        after the "Start" button is pressed (when its label reads "Pause").
    2730        '''
     31        try:
     32            self.currImageList = sorted(
     33                glob.glob(os.path.join(self.imagedir,self.params['filter'])))
     34        except IndexError:
     35            self.currImageList = []
     36            return
     37
     38        createdImageIdList = []
     39        for newImage in self.currImageList:
     40            if newImage in self.IntegratedList: continue
     41            # need to read in this file
     42            Comments,Data,Npix,Image = G2IO.GetImageData(self.G2frame,newImage)
     43            if not Npix:
     44                print('problem reading '+newImage)
     45                continue
     46            G2IO.LoadImage(newImage,self.G2frame,Comments,Data,Npix,Image)
     47            controlsDict = self.G2frame.PatternTree.GetItemPyData(
     48                G2gd.GetPatternTreeItemId(self.G2frame,self.G2frame.Image, 'Image Controls'))
     49            controlsDict.update(self.ImageControls)
     50            ImageMasks = self.G2frame.PatternTree.GetItemPyData(
     51                G2gd.GetPatternTreeItemId(self.G2frame,self.G2frame.Image, 'Masks'))
     52            createdImageIdList.append(self.G2frame.Image)
     53            self.IntegratedList.append(newImage)
     54            print('debug: read '+newImage)
     55
     56        for newImagId in createdImageIdList:
     57            print('debug: process '+str(newImagId))
     58            pass
     59            # need to integrate in this entry
    2860        import datetime
    2961        print ("Timer tick at {:%d %b %Y %H:%M:%S}\n".format(datetime.datetime.now()))
    3062        #GSASIIpath.IPyBreak_base()
     63
     64    def StartLoop(self):
     65        '''Save current Image params for use in future integrations
     66        also label the window so users understand whatis being used
     67        '''
     68        print '\nStarting new autointegration\n'
     69        # show current IMG base
     70        self.ControlBaseLbl.SetLabel(self.G2frame.PatternTree.GetItemText(self.G2frame.Image))
     71        if self.params['Mode'] == 'file':
     72            'get file info'
     73            #GSASIIpath.IPyBreak()
     74        else:
     75            # load copy of Image Controls from current image and clean up
     76            # items that should not be copied
     77            self.ImageControls = copy.deepcopy(
     78                self.G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(
     79                    self.G2frame,self.G2frame.Image, 'Image Controls')))
     80            self.ImageControls['showLines'] = True
     81            self.ImageControls['ring'] = []
     82            self.ImageControls['rings'] = []
     83            self.ImageControls['ellipses'] = []
     84            self.ImageControls['setDefault'] = False
     85            del self.ImageControls['range']
     86            del self.ImageControls['size']
     87            del self.ImageControls['GonioAngles']
     88            # load copy of Image Masks, keep thresholds
     89            self.ImageMasks = copy.deepcopy(
     90                self.G2frame.PatternTree.GetItemPyData(
     91                    G2gd.GetPatternTreeItemId(self.G2frame,self.G2frame.Image, 'Masks')))
     92            self.Thresholds = self.ImageMasks['Thresholds'][:]
    3193       
    3294    def __init__(self,G2frame,PollTime=3.0):
     
    57119                btnstart.SetLabel('Pause')
    58120                if self.timer.IsRunning(): self.timer.Stop()
    59                 self.OnTimer(None) # run once immediately and again after delay
     121                self.StartLoop()
     122                self.OnTimerLoop(None) # run once immediately and again after delay
    60123                self.timer.Start(int(1000*PollTime),oneShot=False)
    61124            else:
    62125                btnstart.SetLabel('Resume')
    63126                if self.timer.IsRunning(): self.timer.Stop()
     127                print('\nPausing autointegration\n')
    64128
    65129        def OnStop(event):
     
    138202        # beginning of __init__ processing
    139203        ##################################################
     204        self.G2frame = G2frame
    140205        self.params = {}
    141         self.params['filter'] = '*.tif'
    142206        self.params['IMGfile'] = ''
    143207        self.params['MaskFile'] = ''
    144208        self.params['IgnoreMask'] = True
     209        self.IntegratedList = []
    145210        fmtlist = G2IO.ExportPowderList(G2frame)
    146211        self.timer = wx.Timer()
    147         self.timer.Bind(wx.EVT_TIMER,self.OnTimer)
    148 
     212        self.timer.Bind(wx.EVT_TIMER,self.OnTimerLoop)
     213
     214        controlsId = G2frame.PatternTree.GetSelection()
     215        size,imagefile = G2frame.PatternTree.GetItemPyData(G2frame.Image)
     216        self.imagedir,fileroot = os.path.split(imagefile)
     217        self.params['filter'] = '*'+os.path.splitext(fileroot)[1]
     218        os.chdir(self.imagedir)
     219       
    149220        wx.Frame.__init__(self, G2frame)
    150221        mnpnl = wx.Panel(self)
    151222        mnsizer = wx.BoxSizer(wx.VERTICAL)
     223        sizer = wx.BoxSizer(wx.HORIZONTAL)
     224        sizer.Add(wx.StaticText(mnpnl, wx.ID_ANY,'Integration based on: '))
     225        self.ControlBaseLbl = wx.StaticText(mnpnl, wx.ID_ANY,'?')
     226        self.ControlBaseLbl.SetLabel(G2frame.PatternTree.GetItemText(G2frame.Image))
     227        sizer.Add(self.ControlBaseLbl)
     228        mnsizer.Add(sizer,1,wx.ALIGN_LEFT,1)
    152229        mnpnl.SetSizer(mnsizer)
     230        #GSASIIpath.IPyBreak()
    153231        # file filter stuff
    154232        sizer = wx.BoxSizer(wx.HORIZONTAL)
Note: See TracChangeset for help on using the changeset viewer.