Changeset 1826 for trunk/python/interactivemask.py
- Timestamp:
- 08/03/10 11:41:13 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/interactivemask.py
r1819 r1826 1 from asap import rcParams2 from asap import _n_bools, mask_and, mask_or1 from asap.parameters import rcParams 2 from asap.utils import _n_bools, mask_and, mask_or 3 3 from asap.scantable import scantable 4 4 … … 15 15 my_mask.finish_selection(callback=func) 16 16 mask=my_mask.get_mask() 17 18 Modify mask region by selecting a region on a plot with mouse. 17 18 Modify mask region by selecting a region on a plot with mouse. 19 19 """ 20 20 … … 22 22 """ 23 23 Create a interactive masking object. 24 Either or both 'plotter' or/and 'scan' should be defined. 24 Either or both 'plotter' or/and 'scan' should be defined. 25 25 26 26 Parameters: … … 63 63 self.ydataold=None 64 64 self._polygons=[] 65 65 66 66 67 67 def set_basemask(self,masklist=[],invert=False): 68 68 """ 69 69 Set initial channel mask. 70 70 71 71 Parameters: 72 72 masklist: [[min, max], [min2, max2], ...] 73 A list of pairs of start/end points (inclusive) 73 A list of pairs of start/end points (inclusive) 74 74 specifying the regions to be masked 75 75 invert: optional argument. If specified as True, … … 77 77 specified are excluded 78 78 You can reset the mask selection by running this method with 79 the default parameters. 79 the default parameters. 80 80 """ 81 81 # Verify input parameters … … 97 97 """ 98 98 Inherit an event from the parent function. 99 99 100 100 Parameters: 101 101 event: 'button_press_event' object to be inherited to 102 start interactive region selection . 102 start interactive region selection . 103 103 """ 104 104 from matplotlib.backend_bases import MouseEvent 105 if isinstance(event,MouseEvent) and event.name=='button_press_event': 105 if isinstance(event,MouseEvent) and event.name=='button_press_event': 106 106 self.event=event 107 107 else: 108 108 msg="Invalid event." 109 raise TypeError(msg) 109 raise TypeError(msg) 110 110 111 111 def set_callback(self,callback): 112 112 """ 113 Set callback function to run when finish_selection() is executed. 113 Set callback function to run when finish_selection() is executed. 114 114 callback: The post processing function to run after 115 115 the mask selections are completed. … … 123 123 Do interactive mask selection. 124 124 Modify masks interactively by adding/deleting regions with 125 mouse drawing.(left-button: mask; right-button: UNmask) 126 Note that the interactive region selection is available only 127 when GUI plotter is active. 125 mouse drawing.(left-button: mask; right-button: UNmask) 126 Note that the interactive region selection is available only 127 when GUI plotter is active. 128 128 129 129 Parameters: 130 130 once: If specified as True, you can modify masks only 131 once. Else if False, you can modify them repeatedly. 131 once. Else if False, you can modify them repeatedly. 132 132 showmask: If specified as True, the masked regions are plotted 133 133 on the plotter. 134 134 Note this parameter is valid only when once=True. 135 Otherwise, maskes are forced to be plotted for reference. 135 Otherwise, maskes are forced to be plotted for reference. 136 136 """ 137 137 # Return if GUI is not active … … 181 181 if self.event != None: 182 182 self._region_start(self.event) 183 else: 183 else: 184 184 self.p._plotter.register('button_press',None) 185 185 self.p._plotter.register('button_press',self._region_start) … … 205 205 def _region_draw(self,event): 206 206 sameaxes=(event.inaxes == self.rect['axes']) 207 if sameaxes: 207 if sameaxes: 208 208 xnow=event.x 209 209 ynow=event.y … … 224 224 # Delete the rubber band 225 225 self.p._plotter.figmgr.toolbar.release(event) 226 227 if event.inaxes == self.rect['axes']: 226 227 if event.inaxes == self.rect['axes']: 228 228 xend=event.x 229 229 yend=event.y … … 235 235 xdataend=self.xdataold 236 236 ydataend=self.ydataold 237 237 238 238 self.rect['world'][2:4] = [xdataend, ydataend] 239 239 self.rect['pixel'][2:4] = [xend, yend] … … 300 300 if len(ifs) > 1: 301 301 for k in xrange(len(ifs)-1): 302 self._polygons.append(self.p._plotter.subplots[j]['axes'].axvspan(projs[k][i][0],projs[k][i][1],facecolor='#aaaaaa')) 302 self._polygons.append(self.p._plotter.subplots[j]['axes'].axvspan(projs[k][i][0],projs[k][i][1],facecolor='#aaaaaa')) 303 303 self._polygons.append(self.p._plotter.subplots[j]['axes'].axvspan(msks[i][0],msks[i][1],facecolor='yellow')) 304 304 self.p._plotter.canvas.draw() … … 314 314 Specifying the callback function here will overwrite 315 315 the one set by set_callback(func) 316 316 317 317 Note this function is automatically called at the end of 318 select_mask() if once=True. 318 select_mask() if once=True. 319 319 """ 320 320 if callback: self.callback=callback … … 324 324 if not self.newplot: 325 325 self.clear_polygon() 326 else: 326 else: 327 327 self.p._plotter.unmap() 328 328 self.p._plotter = None … … 334 334 def clear_polygon(self): 335 335 """ 336 Erase masks plots from the plotter. 336 Erase masks plots from the plotter. 337 337 """ 338 338 if len(self._polygons)>0: … … 347 347 Get the interactively selected channel mask. 348 348 Returns: 349 A list of channel mask. 349 A list of channel mask. 350 350 """ 351 351 return self.mask 352 353
Note: See TracChangeset
for help on using the changeset viewer.