Changeset 2108
- Timestamp:
- 04/06/11 15:49:45 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/interactivemask.py
r1826 r2108 2 2 from asap.utils import _n_bools, mask_and, mask_or 3 3 from asap.scantable import scantable 4 from asap.logging import asaplog, asaplog_post_dec 4 5 5 6 class interactivemask: … … 30 31 # Return if GUI is not active 31 32 if not rcParams['plotter.gui']: 32 print 'GUI plotter is disabled.\n' 33 print 'Exit interactive mode.' 33 msg = 'GUI plotter is disabled.\n' 34 msg += 'Exit interactive mode.' 35 asaplog.push(msg) 36 asaplog.post("ERROR") 34 37 return 35 38 # Verify input parameters … … 70 73 71 74 Parameters: 72 73 74 75 invert:optional argument. If specified as True,76 77 75 masklist: [[min, max], [min2, max2], ...] 76 A list of pairs of start/end points (inclusive) 77 specifying the regions to be masked 78 invert: optional argument. If specified as True, 79 return an inverted mask, i.e. the regions 80 specified are excluded 78 81 You can reset the mask selection by running this method with 79 82 the default parameters. … … 88 91 if ( len(masklist) > 0 ): 89 92 self.mask=self.scan.create_mask(masklist,invert=invert) 90 93 elif invert==True: 91 94 self.mask=_n_bools(self.scan.nchan(),False) 92 95 else: … … 99 102 100 103 Parameters: 101 102 104 event: 'button_press_event' object to be inherited to 105 start interactive region selection . 103 106 """ 104 107 from matplotlib.backend_bases import MouseEvent … … 112 115 """ 113 116 Set callback function to run when finish_selection() is executed. 114 115 116 117 117 callback: The post processing function to run after 118 the mask selections are completed. 119 This will be overwritten if callback is defined in 120 finish_selection(callback=func) 118 121 """ 119 122 self.callback=callback … … 128 131 129 132 Parameters: 130 once:If specified as True, you can modify masks only131 132 133 134 135 133 once: If specified as True, you can modify masks only 134 once. Else if False, you can modify them repeatedly. 135 showmask: If specified as True, the masked regions are plotted 136 on the plotter. 137 Note this parameter is valid only when once=True. 138 Otherwise, maskes are forced to be plotted for reference. 136 139 """ 137 140 # Return if GUI is not active 138 141 if not rcParams['plotter.gui']: 139 print 'GUI plotter is disabled.\n' 140 print 'Exit interactive mode.' 142 msg = 'GUI plotter is disabled.\n' 143 msg += 'Exit interactive mode.' 144 asaplog.push(msg) 145 asaplog.post("ERROR") 141 146 return 142 147 … … 145 150 self.showmask=showmask 146 151 else: 147 if not showmask: print 'Warning: showmask spcification is ignored. Mask regions are plotted anyway.' 152 if not showmask: 153 asaplog.post() 154 asaplog.push('showmask spcification is ignored. Mask regions are plotted anyway.') 155 asaplog.post("WARN") 148 156 self.showmask=True 149 157 150 158 #if not self.p._plotter or self.p._plotter.is_dead: 151 159 if not self.p or self.p._plotter.is_dead: 152 print 'A new ASAP plotter will be loaded' 160 asaplog.push('A new ASAP plotter will be loaded') 161 asaplog.post() 153 162 from asap.asapplotter import asapplotter 154 163 self.p=asapplotter() 155 164 self.newplot=True 156 165 157 166 # Plot selected spectra if needed 158 167 if self.scan != self.p._data: 168 if len(self.scan.getifnos()) > 16: 169 asaplog.post() 170 asaplog.push("Number of panels > 16. Plotting the first 16...") 171 asaplog.post("WARN") 159 172 # Need replot 173 self.p._plotter.legend(1) 160 174 self.p.plot(self.scan) 161 175 # disable casa toolbar 162 if self.p._plotter.figmgr.casabar: self.p._plotter.figmgr.casabar.disable_button() 176 if self.p._plotter.figmgr.casabar: 177 self.p._plotter.figmgr.casabar.disable_button() 178 self.p._plotter.figmgr.casabar.disable_prev() 179 self.p._plotter.figmgr.casabar.disable_next() 163 180 for panel in self.p._plotter.subplots: 164 181 xmin, xmax = panel['axes'].get_xlim() … … 195 212 # Select mask/unmask region with mask 196 213 self.rect = {'button': event.button, 'axes': event.inaxes, 197 198 199 200 201 214 'x': event.x, 'y': event.y, 215 'world': [event.xdata, event.ydata, 216 event.xdata, event.ydata], 217 'pixel': [event.x, event.y, 218 event.x, event.y]} 202 219 self.p._plotter.register('motion_notify', self._region_draw) 203 220 self.p._plotter.register('button_release', self._region_end) … … 261 278 invmask=True 262 279 mflg='UNmask' 263 print mflg+': ',newlist 280 asaplog.push(mflg+': '+str(newlist)) 281 asaplog.post() 264 282 newmask=self.scan.create_mask(newlist,invert=invmask) 265 283 # Logic operation to update mask … … 274 292 # Plot masked regions 275 293 def _plot_mask(self): 276 277 294 msks = [] 295 msks = self.scan.get_masklist(self.mask,row=0) 278 296 # Get projection masks for multi-IF 279 297 ifs=self.scan.getifnos() … … 287 305 projs.append(self.scan.get_masklist(self.mask,row=row)) 288 306 break 289 307 if len(self._polygons)>0: 290 308 # Remove old polygons 291 309 for polygon in self._polygons: polygon.remove() … … 310 328 311 329 Parameters: 312 313 314 315 330 callback: The post processing function to run after 331 the mask selections are completed. 332 Specifying the callback function here will overwrite 333 the one set by set_callback(func) 316 334 317 335 Note this function is automatically called at the end of … … 336 354 Erase masks plots from the plotter. 337 355 """ 338 356 if len(self._polygons)>0: 339 357 # Remove old polygons 340 358 for polygon in self._polygons: polygon.remove() … … 347 365 Get the interactively selected channel mask. 348 366 Returns: 349 367 A list of channel mask. 350 368 """ 351 369 return self.mask
Note:
See TracChangeset
for help on using the changeset viewer.