Changeset 2118


Ignore:
Timestamp:
04/07/11 17:54:23 (13 years ago)
Author:
Kana Sugimoto
Message:

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s):

Description: minor improvement in statistic calculation code + tidy up


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/casatoolbar.py

    r2053 r2118  
    88class CustomToolbarCommon:
    99    def __init__(self,parent):
    10         self.plotter=parent
     10        self.plotter = parent
    1111        #self.figmgr=self.plotter._plotter.figmgr
    1212
     
    2525            return
    2626
    27         xclick=event.xdata
    28         yclick=event.ydata
    29         dist2=1000.
    30         pickline=None
     27        xclick = event.xdata
     28        yclick = event.ydata
     29        dist2 = 1000.
     30        pickline = None
    3131        # If the pannel has picable objects
    32         pflag=False
     32        pflag = False
    3333        for lin in event.inaxes.lines:
    3434            if not lin.pickable():
    3535                continue
    36             pflag=True
     36            pflag = True
    3737            flag,pind = lin.contains(event)
    3838            if not flag:
     
    5252        # Pickable but too far from mouse position
    5353        elif pickline is None:
    54             picked='No line selected.'
     54            picked = 'No line selected.'
    5555            self.figmgr.toolbar.set_message(picked)
    5656            return
     
    6666        xdata = pickline.get_xdata()
    6767        ydata = pickline.get_ydata()
    68         titl=pickline.get_label()
    69         titp=event.inaxes.title.get_text()
    70         panel0=event.inaxes
    71         picked="Selected: '"+titl+"' in panel '"+titp+"'."
     68        titl = pickline.get_label()
     69        titp = event.inaxes.title.get_text()
     70        panel0 = event.inaxes
     71        picked = "Selected: '"+titl+"' in panel '"+titp+"'."
    7272        thetoolbar.set_message(picked)
    7373        # Generate a navigation window
     
    7777        def spec_data(event):
    7878            # Getting spectrum data of neiboring point
    79             xclick=event.xdata
     79            xclick = event.xdata
    8080            if event.inaxes != panel0:
    8181                return
    82             ipoint=len(xdata)-1
     82            ipoint = len(xdata)-1
    8383            for i in range(len(xdata)-1):
    84                 xl=xclick-xdata[i]
    85                 xr=xclick-xdata[i+1]
     84                xl = xclick - xdata[i]
     85                xr = xclick - xdata[i+1]
    8686                if xl*xr <= 0.:
    8787                    ipoint = i
    8888                    break
    8989            # Output spectral value on the navigation window
    90             posi='[ %s, %s ]:  x = %.2f   value = %.2f'\
    91                   %(titl,titp,xdata[ipoint],ydata[ipoint])
     90            posi = '[ %s, %s ]:  x = %.2f   value = %.2f'\
     91                   %(titl,titp,xdata[ipoint],ydata[ipoint])
    9292            #naviwin.posi.set(posi)
    9393            thetoolbar.set_message(posi)
     
    9898            theplot.register('motion_notify',None)
    9999            # Re-activate the default motion_notify_event
    100             thetoolbar._idDrag=thecanvas.mpl_connect('motion_notify_event',
    101                                                      thetoolbar.mouse_move)
     100            thetoolbar._idDrag = thecanvas.mpl_connect('motion_notify_event',
     101                                                       thetoolbar.mouse_move)
    102102            theplot.register('button_release',None)
    103103            return
     
    117117        if event.inaxes == None:
    118118            return
    119         if event.button ==1:
     119        if event.button == 1:
    120120            baseinv=True
    121121        elif event.button == 3:
     
    126126        def _calc_stats():
    127127            msk=mymask.get_mask()
    128             mymask.scan.stats(stat='max',mask=msk)
    129             mymask.scan.stats(stat='min',mask=msk)
    130             mymask.scan.stats(stat='sum',mask=msk)
    131             mymask.scan.stats(stat='mean',mask=msk)
    132             mymask.scan.stats(stat='median',mask=msk)
    133             mymask.scan.stats(stat='rms',mask=msk)
    134             mymask.scan.stats(stat='stddev',mask=msk)
     128            statstr = ['max', 'min', 'mean', 'median', 'sum', 'stddev', 'rms']
     129            for stat in statstr:
     130                mymask.scan.stats(stat=stat,mask=msk)
    135131
    136132        # Interactive mask definition
    137133        from asap.interactivemask import interactivemask
    138         mymask=interactivemask(plotter=self.plotter,scan=self.plotter._data)
     134        mymask = interactivemask(plotter=self.plotter,scan=self.plotter._data)
    139135        # Create initial mask
    140136        mymask.set_basemask(invert=baseinv)
     
    150146        if not self.figmgr.toolbar.mode == '':
    151147            return
    152         if event.button ==1:
     148        if event.button == 1:
    153149            self.notewin.load_textwindow(event)
    154150        elif event.button == 3 and self._note_picked(event):
     
    172168    def prev_page(self):
    173169        self.figmgr.toolbar.set_message('plotting the previous page')
     170        #self._pause_buttons(operation="start",msg='plotting the previous page')
    174171        self._new_page(goback=True)
     172        #self._pause_buttons(operation="end")
    175173
    176174    ### go to the next page
    177175    def next_page(self):
    178176        self.figmgr.toolbar.set_message('plotting the next page')
     177        #self._pause_buttons(operation="start",msg='plotting the next page')
    179178        self._new_page(goback=False)
     179        #self._pause_buttons(operation="end")
    180180
    181181    ### actual plotting of the new page
     
    240240            # no user specification
    241241            prevpnum = maxpanel
    242            
     242
    243243        start_ipanel = max(lastpanel-currpnum-prevpnum+1, 0)
    244244        # set the pannel ID of the last panel of prev-prev page
     
    272272            ppp = maxpanel
    273273        return int(idlastpanel/ppp)+1
     274
     275    # pause buttons for slow operations. implemented at a backend dependent class
     276    def _pause_buttons(self,operation="end",msg=""):
     277        pass
     278
    274279
    275280#####################################
     
    295300        self.pagecount = None
    296301        CustomToolbarCommon.__init__(self,parent)
    297         self.notewin=NotationWindowTkAgg(master=self.canvas)
     302        self.notewin = NotationWindowTkAgg(master=self.canvas)
    298303        self._add_custom_toolbar()
    299304
    300305    def _add_custom_toolbar(self):
    301306        Tk.Frame.__init__(self,master=self.figmgr.window)
    302         #self.bSpec=self._NewButton(master=self,
    303         #                           text='spec value',
    304         #                           command=self.spec_show)
    305         self.bNote=self._NewButton(master=self,
    306                                    text='notation',
    307                                    command=self.modify_note)
    308 
    309         self.bStat=self._NewButton(master=self,
    310                                    text='statistics',
    311                                    command=self.stat_cal)
    312         self.bQuit=self._NewButton(master=self,
    313                                    text='Quit',
    314                                    command=self.quit,
    315                                    side=Tk.RIGHT)
     307        #self.bSpec = self._NewButton(master=self,
     308        #                             text='spec value',
     309        #                             command=self.spec_show)
     310        self.bNote = self._NewButton(master=self,
     311                                     text='notation',
     312                                     command=self.modify_note)
     313
     314        self.bStat = self._NewButton(master=self,
     315                                     text='statistics',
     316                                     command=self.stat_cal)
     317        self.bQuit = self._NewButton(master=self,
     318                                     text='Quit',
     319                                     command=self.quit,
     320                                     side=Tk.RIGHT)
    316321
    317322        # page change oparations
     
    326331        self.lPagecount.pack(side=Tk.LEFT,padx=3)
    327332       
    328         self.bNext=self._NewButton(master=frPage,
    329                                    text=' + ',
    330                                    command=self.next_page)
    331         self.bPrev=self._NewButton(master=frPage,
    332                                    text=' - ',
    333                                    command=self.prev_page)
     333        self.bNext = self._NewButton(master=frPage,
     334                                     text=' + ',
     335                                     command=self.next_page)
     336        self.bPrev = self._NewButton(master=frPage,
     337                                     text=' - ',
     338                                     command=self.prev_page)
    334339
    335340        if os.uname()[0] != 'Darwin':
     
    362367        #self.bSpec.config(relief='sunken')
    363368        #self.bNote.config(relief='raised')
    364         self.mode='spec'
     369        self.mode = 'spec'
    365370        self.notewin.close_widgets()
    366371        self.__disconnect_event()
     
    378383        self.bStat.config(relief='sunken')
    379384        self.bNote.config(relief='raised')
    380         self.mode='stat'
     385        self.mode = 'stat'
    381386        self.notewin.close_widgets()
    382387        self.__disconnect_event()
     
    388393        if self.mode == 'note':
    389394            self.bNote.config(relief='raised')
    390             self.mode='none'
     395            self.mode = 'none'
    391396            self.spec_show()
    392397            return
     
    394399        self.bStat.config(relief='raised')
    395400        self.bNote.config(relief='sunken')
    396         self.mode='note'
     401        self.mode = 'note'
    397402        self.__disconnect_event()
    398403        self._p.register('button_press',self._mod_note)
     
    408413        #self.bSpec.config(state=Tk.NORMAL)
    409414        self.bStat.config(state=Tk.NORMAL)
    410         self.button=True
     415        self.button = True
    411416        self.spec_show()
    412417
     
    417422        #self.bNext.config(state=Tk.DISABLED)
    418423        #self.bPrev.config(state=Tk.DISABLED)
    419         self.button=False
    420         self.mode=''
     424        self.button = False
     425        self.mode = ''
    421426        self.__disconnect_event()
    422427
     
    432437    def disable_prev(self):
    433438        self.bPrev.config(state=Tk.DISABLED)
     439
     440    # pause buttons for slow operations
     441    def _pause_buttons(self,operation="end",msg=""):
     442        buttons = ["bStat","bNote","bQuit"]
     443        if operation == "start":
     444            state = Tk.DISABLED
     445        else:
     446            state = Tk.NORMAL
     447        for btn in buttons:
     448            getattr(self,btn).config(state=state)
     449        self.figmgr.toolbar.set_message(msg)
    434450
    435451    def delete_bar(self):
Note: See TracChangeset for help on using the changeset viewer.