Changeset 2117 for trunk/python
- Timestamp:
- 04/07/11 17:37:27 (14 years ago)
- Location:
- trunk/python
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/flagplotter.py
r2115 r2117 25 25 """ 26 26 def __init__(self, visible=None, **kwargs): 27 self._scan =None27 self._scan = None 28 28 asapplotter.__init__(self,visible=visible, **kwargs) 29 29 self._plotter.window.title('Flag Plotter') … … 33 33 34 34 def _newcasabar(self): 35 backend =matplotlib.get_backend()35 backend = matplotlib.get_backend() 36 36 if self._visible and backend == "TkAgg": 37 37 #from asap.casatoolbar import CustomToolbarTkAgg … … 64 64 """ This function is not available for the class flagplotter """ 65 65 self._invalid_func(name='plotpointing') 66 66 67 67 def plottp(self,*args,**kwargs): 68 68 """ This function is not available for the class flagplotter """ -
trunk/python/flagtoolbar.py
r2115 r2117 19 19 self._thisregion = None 20 20 self.xdataold=None 21 21 22 22 ### select the nearest spectrum in pick radius 23 23 ### and display spectral value on the toolbar. … … 34 34 return 35 35 36 xclick =event.xdata37 yclick =event.ydata38 dist2 =1000.39 pickline =None36 xclick = event.xdata 37 yclick = event.ydata 38 dist2 = 1000. 39 pickline = None 40 40 # If the pannel has picable objects 41 pflag =False41 pflag = False 42 42 for lin in event.inaxes.lines: 43 43 if not lin.pickable(): 44 44 continue 45 pflag =True45 pflag = True 46 46 flag,pind = lin.contains(event) 47 47 if not flag: … … 61 61 # Pickable but too far from mouse position 62 62 elif pickline is None: 63 picked ='No line selected.'63 picked = 'No line selected.' 64 64 self.figmgr.toolbar.set_message(picked) 65 65 return … … 75 75 xdata = pickline.get_xdata() 76 76 ydata = pickline.get_ydata() 77 titl =pickline.get_label()78 titp =event.inaxes.title.get_text()79 panel0 =event.inaxes80 picked ="Selected: '"+titl+"' in panel '"+titp+"'."77 titl = pickline.get_label() 78 titp = event.inaxes.title.get_text() 79 panel0 = event.inaxes 80 picked = "Selected: '"+titl+"' in panel '"+titp+"'." 81 81 thetoolbar.set_message(picked) 82 82 # Generate a navigation window … … 86 86 def spec_data(event): 87 87 # Getting spectrum data of neiboring point 88 xclick =event.xdata88 xclick = event.xdata 89 89 if event.inaxes != panel0: 90 90 return 91 ipoint =len(xdata)-191 ipoint = len(xdata)-1 92 92 for i in range(len(xdata)-1): 93 xl =xclick-xdata[i]94 xr =xclick-xdata[i+1]93 xl = xclick-xdata[i] 94 xr = xclick-xdata[i+1] 95 95 if xl*xr <= 0.: 96 96 ipoint = i 97 97 break 98 98 # Output spectral value on the navigation window 99 posi ='[ %s, %s ]: x = %.2f value = %.2f'\99 posi = '[ %s, %s ]: x = %.2f value = %.2f'\ 100 100 %(titl,titp,xdata[ipoint],ydata[ipoint]) 101 101 #naviwin.posi.set(posi) … … 123 123 if not self.figmgr.toolbar.mode == '': 124 124 return 125 if event.button == 1:125 if event.button == 1: 126 126 self.notewin.load_textwindow(event) 127 127 elif event.button == 3 and self._note_picked(event): … … 195 195 if event.button != 1: 196 196 return 197 197 198 198 try: self.lastspan 199 199 except AttributeError: pass … … 417 417 asaplog.post("ERROR") 418 418 mathobj = stmath( rcParams['insitu'] ) 419 statval ={}419 statval = {} 420 420 statstr = ['max', 'min', 'mean', 'median', 'sum', 'stddev', 'rms'] 421 421 if isinstance(rows,list) and len(rows) > 0: … … 506 506 asaplog.post('WARN') 507 507 goback = False 508 508 509 509 self.plotter._plotter.hold() 510 510 self.plotter._plotter.legend(1) … … 538 538 # the number of current subplots 539 539 currpnum = len(self.plotter._plotter.subplots) 540 540 541 541 # the nuber of previous subplots 542 542 start_ipanel = None … … 573 573 def show_pagenum(self,pagenum,formatstr): 574 574 # passed to backend dependent class 575 pass 575 pass 576 576 577 577 def _get_pagenum(self): … … 616 616 def _add_custom_toolbar(self): 617 617 Tk.Frame.__init__(self,master=self.figmgr.window) 618 #self.bSpec =self._NewButton(master=self,619 # text='spec value',620 # command=self.spec_show)621 622 self.bRegion =self._NewButton(master=self,623 text='region',624 command=self.select_region)625 self.bPanel =self._NewButton(master=self,626 text='panel',627 command=self.select_panel)628 self.bClear =self._NewButton(master=self,629 text='clear',630 command=self.cancel_select)631 self.bFlag =self._NewButton(master=self,632 text='flag',633 command=self.flag)634 self.bUnflag =self._NewButton(master=self,635 text='unflag',636 command=self.unflag)618 #self.bSpec = self._NewButton(master=self, 619 # text='spec value', 620 # command=self.spec_show) 621 622 self.bRegion = self._NewButton(master=self, 623 text='region', 624 command=self.select_region) 625 self.bPanel = self._NewButton(master=self, 626 text='panel', 627 command=self.select_panel) 628 self.bClear = self._NewButton(master=self, 629 text='clear', 630 command=self.cancel_select) 631 self.bFlag = self._NewButton(master=self, 632 text='flag', 633 command=self.flag) 634 self.bUnflag = self._NewButton(master=self, 635 text='unflag', 636 command=self.unflag) 637 637 638 self.bStat =self._NewButton(master=self,639 text='statistics',640 command=self.stat_cal)641 642 self.bNote =self._NewButton(master=self,643 text='notation',644 command=self.modify_note)645 646 self.bQuit =self._NewButton(master=self,647 text='Quit',648 #file="stock_close.ppm",649 command=self.quit,650 side=Tk.RIGHT)651 638 self.bStat = self._NewButton(master=self, 639 text='statistics', 640 command=self.stat_cal) 641 642 self.bNote = self._NewButton(master=self, 643 text='notation', 644 command=self.modify_note) 645 646 self.bQuit = self._NewButton(master=self, 647 text='Quit', 648 #file="stock_close.ppm", 649 command=self.quit, 650 side=Tk.RIGHT) 651 652 652 # page change oparations 653 653 frPage = Tk.Frame(master=self,borderwidth=2,relief=Tk.GROOVE) … … 661 661 padx=5,bg='white') 662 662 self.lPagecount.pack(side=Tk.LEFT,padx=3) 663 663 664 664 self.bNext=self._NewButton(master=frPage, 665 665 text=' + ', … … 685 685 file = os.path.join(matplotlib.rcParams['datapath'], 'images', file) 686 686 img = Tk.PhotoImage(master=master, file=file) 687 687 688 688 if os.uname()[0] == 'Darwin': 689 689 b = Tk.Button(master=master, text=text, image=img, … … 704 704 self.figmgr.toolbar.set_message('spec value: drag on a spec') 705 705 if self.mode == 'spec': return 706 self.mode ='spec'706 self.mode = 'spec' 707 707 self.notewin.close_widgets() 708 708 self.__disconnect_event() … … 714 714 if self.mode == 'note': 715 715 self.bNote.config(relief='raised') 716 self.mode ='none'716 self.mode = 'none' 717 717 self.spec_show() 718 718 return … … 720 720 self.bRegion.config(relief='raised') 721 721 self.bPanel.config(relief='raised') 722 self.mode ='note'722 self.mode = 'note' 723 723 self.__disconnect_event() 724 724 self._p.register('button_press',self._mod_note) … … 729 729 if self.mode == 'region': 730 730 self.bRegion.config(relief='raised') 731 self.mode ='none'731 self.mode = 'none' 732 732 self.spec_show() 733 733 return … … 735 735 self.bRegion.config(relief='sunken') 736 736 self.bPanel.config(relief='raised') 737 self.mode ='region'737 self.mode = 'region' 738 738 self.notewin.close_widgets() 739 739 self.__disconnect_event() … … 745 745 if self.mode == 'panel': 746 746 self.bPanel.config(relief='raised') 747 self.mode ='none'747 self.mode = 'none' 748 748 self.spec_show() 749 749 return … … 751 751 self.bRegion.config(relief='raised') 752 752 self.bPanel.config(relief='sunken') 753 self.mode ='panel'753 self.mode = 'panel' 754 754 self.notewin.close_widgets() 755 755 self.__disconnect_event() … … 770 770 self.bUnflag.config(state=Tk.NORMAL) 771 771 self.bStat.config(state=Tk.NORMAL) 772 self.button =True772 self.button = True 773 773 self.spec_show() 774 774 … … 786 786 self.bNext.config(state=Tk.DISABLED) 787 787 self.bPrev.config(state=Tk.DISABLED) 788 self.button =False789 self.mode =''788 self.button = False 789 self.mode = '' 790 790 self.notewin.close_widgets() 791 791 self.__disconnect_event() … … 814 814 getattr(self,btn).config(state=state) 815 815 self.figmgr.toolbar.set_message(msg) 816 817 816 818 817 def delete_bar(self): 819 818 self.__disconnect_event() -
trunk/python/interactivemask.py
r2109 r2117 41 41 raise TypeError(msg) 42 42 43 self.scan =None44 self.p =None45 self.newplot =False43 self.scan = None 44 self.p = None 45 self.newplot = False 46 46 if scan and isinstance(scan, scantable): 47 self.scan =scan47 self.scan = scan 48 48 from asap.asapplotter import asapplotter 49 49 if plotter and isinstance(plotter,asapplotter): 50 50 self.p = plotter 51 51 if self.scan is None and isinstance(self.p._data,scantable): 52 self.scan =self.p._data52 self.scan = self.p._data 53 53 if self.scan is None: 54 54 msg = "Invalid scantable." 55 55 raise TypeError(msg) 56 56 57 self.mask =_n_bools(self.scan.nchan(),True)58 self.callback =None59 self.event =None60 self.once =False61 self.showmask =True62 self.rect ={}63 self.xold =None64 self.yold =None65 self.xdataold =None66 self.ydataold =None67 self._polygons =[]57 self.mask = _n_bools(self.scan.nchan(),True) 58 self.callback = None 59 self.event = None 60 self.once = False 61 self.showmask = True 62 self.rect = {} 63 self.xold = None 64 self.yold = None 65 self.xdataold = None 66 self.ydataold = None 67 self._polygons = [] 68 68 69 69 … … 90 90 # Create base mask 91 91 if ( len(masklist) > 0 ): 92 self.mask =self.scan.create_mask(masklist,invert=invert)93 elif invert ==True:94 self.mask =_n_bools(self.scan.nchan(),False)95 else: 96 self.mask =_n_bools(self.scan.nchan(),True)92 self.mask = self.scan.create_mask(masklist,invert=invert) 93 elif invert == True: 94 self.mask = _n_bools(self.scan.nchan(),False) 95 else: 96 self.mask = _n_bools(self.scan.nchan(),True) 97 97 98 98 … … 106 106 """ 107 107 from matplotlib.backend_bases import MouseEvent 108 if isinstance(event,MouseEvent) and event.name =='button_press_event':109 self.event =event110 else: 111 msg ="Invalid event."108 if isinstance(event,MouseEvent) and event.name == 'button_press_event': 109 self.event = event 110 else: 111 msg = "Invalid event." 112 112 raise TypeError(msg) 113 113 … … 120 120 finish_selection(callback=func) 121 121 """ 122 self.callback =callback122 self.callback = callback 123 123 124 124 def select_mask(self,once=False,showmask=True): … … 148 148 self.once = once 149 149 if self.once: 150 self.showmask =showmask150 self.showmask = showmask 151 151 else: 152 152 if not showmask: … … 154 154 asaplog.push('showmask spcification is ignored. Mask regions are plotted anyway.') 155 155 asaplog.post("WARN") 156 self.showmask =True156 self.showmask = True 157 157 158 158 #if not self.p._plotter or self.p._plotter.is_dead: … … 161 161 asaplog.post() 162 162 from asap.asapplotter import asapplotter 163 self.p =asapplotter()164 self.newplot =True163 self.p = asapplotter() 164 self.newplot = True 165 165 166 166 # Plot selected spectra if needed … … 206 206 # Do not fire event when in zooming/panning mode 207 207 mode = self.p._plotter.figmgr.toolbar.mode 208 if not mode == '':208 if not mode == '': 209 209 return 210 210 # Return if selected point is out of panel … … 223 223 sameaxes=(event.inaxes == self.rect['axes']) 224 224 if sameaxes: 225 xnow =event.x226 ynow =event.y227 self.xold =xnow228 self.yold =ynow229 self.xdataold =event.xdata230 self.ydataold =event.ydata231 else: 232 xnow =self.xold233 ynow =self.yold225 xnow = event.x 226 ynow = event.y 227 self.xold = xnow 228 self.yold = ynow 229 self.xdataold = event.xdata 230 self.ydataold = event.ydata 231 else: 232 xnow = self.xold 233 ynow = self.yold 234 234 235 235 self.p._plotter.figmgr.toolbar.draw_rubberband(event, xnow, ynow, self.rect['x'], self.rect['y']) … … 243 243 244 244 if event.inaxes == self.rect['axes']: 245 xend =event.x246 yend =event.y247 xdataend =event.xdata248 ydataend =event.ydata249 else: 250 xend =self.xold251 yend =self.yold252 xdataend =self.xdataold253 ydataend =self.ydataold245 xend = event.x 246 yend = event.y 247 xdataend = event.xdata 248 ydataend = event.ydata 249 else: 250 xend = self.xold 251 yend = self.yold 252 xdataend = self.xdataold 253 ydataend = self.ydataold 254 254 255 255 self.rect['world'][2:4] = [xdataend, ydataend] … … 257 257 self._update_mask() 258 258 # Clear up region selection 259 self.rect ={}260 self.xold =None261 self.yold =None262 self.xdataold =None263 self.ydataold =None259 self.rect = {} 260 self.xold = None 261 self.yold = None 262 self.xdataold = None 263 self.ydataold = None 264 264 if self.once: self.finish_selection(callback=self.callback) 265 265 266 266 def _update_mask(self): 267 267 # Min and Max for new mask 268 xstart =self.rect['world'][0]269 xend =self.rect['world'][2]268 xstart = self.rect['world'][0] 269 xend = self.rect['world'][2] 270 270 if xstart <= xend: newlist=[xstart,xend] 271 else: newlist =[xend,xstart]271 else: newlist = [xend,xstart] 272 272 # Mask or unmask 273 invmask =None273 invmask = None 274 274 if self.rect['button'] == 1: 275 invmask =False276 mflg ='Mask'275 invmask = False 276 mflg = 'Mask' 277 277 elif self.rect['button'] == 3: 278 invmask =True279 mflg ='UNmask'278 invmask = True 279 mflg = 'UNmask' 280 280 asaplog.push(mflg+': '+str(newlist)) 281 281 asaplog.post() 282 newmask =self.scan.create_mask(newlist,invert=invmask)282 newmask = self.scan.create_mask(newlist,invert=invmask) 283 283 # Logic operation to update mask 284 284 if invmask: 285 self.mask =mask_and(self.mask,newmask)286 else: 287 self.mask =mask_or(self.mask,newmask)285 self.mask = mask_and(self.mask,newmask) 286 else: 287 self.mask = mask_or(self.mask,newmask) 288 288 # Plot masked regions 289 289 #if self.showmask or not self.once: self._plot_mask() … … 295 295 msks = self.scan.get_masklist(self.mask,row=0) 296 296 # Get projection masks for multi-IF 297 ifs =self.scan.getifnos()297 ifs = self.scan.getifnos() 298 298 projs = [] 299 299 if len(ifs) > 1: 300 row0if =self.scan.getif(0)300 row0if = self.scan.getif(0) 301 301 for ifno in ifs: 302 302 if ifno == row0if: continue … … 308 308 # Remove old polygons 309 309 for polygon in self._polygons: polygon.remove() 310 self._polygons =[]310 self._polygons = [] 311 311 # Plot new polygons 312 312 if len(msks) > 0: 313 npanel =len(self.p._plotter.subplots)314 j =-1313 npanel = len(self.p._plotter.subplots) 314 j = -1 315 315 for iloop in range(len(msks)*npanel): 316 316 i = iloop % len(msks) … … 346 346 self.p._plotter = None 347 347 del self.p 348 self.p =None349 self._polygons =[]348 self.p = None 349 self._polygons = [] 350 350 351 351 … … 354 354 Erase masks plots from the plotter. 355 355 """ 356 if len(self._polygons) >0:356 if len(self._polygons) > 0: 357 357 # Remove old polygons 358 358 for polygon in self._polygons: polygon.remove() 359 359 self.p._plotter.show() 360 self._polygons =[]360 self._polygons = [] 361 361 362 362
Note:
See TracChangeset
for help on using the changeset viewer.