Ignore:
Timestamp:
Feb 24, 2009 11:46:12 AM (15 years ago)
Author:
Gervaise Alina <gervyh@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
cce33b3
Parents:
2a8fac1
Message:

small bugs fixed: clearing slicer improved

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guiframe/local_perspectives/plotting/boxSlicer.py

    r3b909b7 r18eba35  
    1111from BaseInteractor import _BaseInteractor 
    1212from copy import deepcopy 
    13 import math 
     13import math, numpy 
    1414 
    1515from sans.guicomm.events import NewPlotEvent, StatusEvent,SlicerParameterEvent,EVT_SLICER_PARS 
     
    2222         Select an annulus through a 2D plot 
    2323    """ 
    24     def __init__(self,base,axes,color='black', zorder=3, 
    25                   x_min=0.0025, x_max=0.0025, y_min=0.0025, y_max=0.0025): 
    26          
     24    def __init__(self,base,axes,color='black', zorder=3): 
    2725        _BaseInteractor.__init__(self, base, axes, color=color) 
     26         
    2827        self.markers = [] 
    2928        self.axes = axes 
    30         self.qmax = self.base.data2D.xmax 
     29         
    3130        self.connect = self.base.connect 
     31         
    3232        self.x= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 
    3333        self.y= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin))         
    34           
    35         self.theta2= math.pi/3 
     34         
     35        self.qmax = max(self.base.data2D.xmax,self.base.data2D.xmin, 
     36                        self.base.data2D.ymax,self.base.data2D.ymin )    
     37         
    3638        ## Number of points on the plot 
    3739        self.nbins = 30 
     
    3941        self.error=0 
    4042        self.averager=None 
    41         self.left_line = VerticalLine(self, self.base.subplot,color='blue',  
     43         
     44        self.vertical_lines = VerticalLines(self, self.base.subplot,color='blue',  
    4245                                      zorder=zorder, 
    43                                         ymin= -self.y ,  
    44                                         ymax= self.y , 
    45                                         xmin= -self.x, 
    46                                         xmax= -self.x) 
    47         self.left_line.qmax = self.qmax 
    48          
    49         self.right_line= VerticalLine(self, self.base.subplot,color='black',  
     46                                        y= self.y , 
     47                                        x= self.x) 
     48        self.vertical_lines.qmax = self.qmax 
     49        
     50        self.horizontal_lines= HorizontalLines(self, self.base.subplot,color='green',  
    5051                                      zorder=zorder, 
    51                                      ymin= -self.y ,  
    52                                      ymax= self.y, 
    53                                      xmin= self.x, 
    54                                      xmax= self.x) 
    55         self.right_line.qmax = self.qmax 
    56          
    57         self.top_line= HorizontalLine(self, self.base.subplot,color='green',  
    58                                       zorder=zorder, 
    59                                       xmin= -self.x, 
    60                                       xmax= self.x, 
    61                                       ymin= self.y, 
    62                                       ymax= self.y) 
    63         self.top_line.qmax= self.qmax 
    64          
    65         self.bottom_line= HorizontalLine(self, self.base.subplot,color='gray',  
    66                                       zorder=zorder, 
    67                                       xmin= -self.x, 
    68                                       xmax= self.x, 
    69                                       ymin= -self.y, 
    70                                       ymax= -self.y) 
    71         self.bottom_line.qmax= self.qmax 
     52                                      x= self.x, 
     53                                      y= self.y) 
     54        self.horizontal_lines.qmax= self.qmax 
     55         
     56       
    7257         
    7358        self.update() 
     
    7560         
    7661        # Bind to slice parameter events 
    77         self.base.parent.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 
     62        self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 
    7863 
    7964 
    8065    def _onEVT_SLICER_PARS(self, event): 
    81         #printEVT("AnnulusSlicer._onEVT_SLICER_PARS") 
     66        wx.PostEvent(self.base.parent, StatusEvent(status="BoxSlicer._onEVT_SLICER_PARS")) 
    8267        event.Skip() 
    8368        if event.type == self.__class__.__name__: 
     
    10691        self.averager=None 
    10792        self.clear_markers() 
    108         self.left_line.clear() 
    109         self.right_line.clear() 
    110         self.top_line.clear() 
    111         self.bottom_line.clear() 
    112         #self.base.connect.disconnect() 
    113         self.base.parent.Unbind(EVT_SLICER_PARS) 
     93        self.horizontal_lines.clear() 
     94        self.vertical_lines.clear() 
     95        self.base.connect.clearall() 
     96         
     97        self.base.Unbind(EVT_SLICER_PARS) 
    11498         
    11599    def update(self): 
     
    118102        resetting the widgets. 
    119103        """ 
    120          
    121         if self.top_line.has_move: 
    122             #print"top has moved" 
    123             self.top_line.update() 
    124             self.bottom_line.update(ymin= -self.top_line.y1, 
    125                                     ymax= -self.top_line.y2) 
    126             self.left_line.update(ymin= -self.top_line.y1, 
    127                                     ymax= -self.top_line.y2) 
    128             self.right_line.update(ymin= -self.top_line.y1, 
    129                                     ymax= -self.top_line.y2) 
    130             
    131         if self.bottom_line.has_move: 
    132             #print "bottom has move" 
    133             self.bottom_line.update() 
    134             self.top_line.update(ymin= -self.bottom_line.y1, 
    135                                     ymax= -self.bottom_line.y2) 
    136             self.left_line.update(ymin= self.bottom_line.y1, 
    137                                     ymax= self.top_line.y1) 
    138             self.right_line.update(ymin= self.bottom_line.y1, 
    139                                     ymax=self.top_line.y1) 
    140             
    141         if self.left_line.has_move: 
    142             
    143             self.left_line.update() 
    144             self.right_line.update(xmin = - self.left_line.x1, 
    145                                    xmax = - self.left_line.x1) 
    146             self.bottom_line.update(xmin=  self.left_line.x1, 
    147                                      xmax= self.right_line.x1) 
    148             self.top_line.update(xmin= self.left_line.x1, 
    149                                     xmax= self.right_line.x1) 
    150             
    151         if self.right_line.has_move: 
    152             
    153             self.right_line.update() 
    154             self.left_line.update(xmin = -self.right_line.x1, 
    155                                    xmax = -self.right_line.x1) 
    156              
    157             self.bottom_line.update(xmin= self.left_line.x1, 
    158                                  xmax= self.right_line.x1) 
    159              
    160             self.top_line.update(xmin= self.left_line.x1, 
    161                                     xmax= self.right_line.x1) 
     104        if self.horizontal_lines.has_move: 
     105            #print "top has moved" 
     106            self.horizontal_lines.update() 
     107            self.vertical_lines.update(y=self.horizontal_lines.y) 
     108        if self.vertical_lines.has_move: 
     109            #print "right has moved" 
     110            self.vertical_lines.update() 
     111            self.horizontal_lines.update(x=self.vertical_lines.x) 
     112             
    162113                
    163114             
     
    168119        """ 
    169120        self.base.freeze_axes() 
    170         self.left_line.save(ev) 
    171         self.right_line.save(ev) 
    172         self.top_line.save(ev) 
    173         self.bottom_line.save(ev) 
     121        self.vertical_lines.save(ev) 
     122        self.horizontal_lines.save(ev) 
     123     
    174124    def _post_data(self): 
    175125        pass 
     
    178128    def post_data(self,new_slab=None , nbins=None): 
    179129        """ post data averaging in Q""" 
    180         x_min= min(self.left_line.x1, self.right_line.x1) 
    181         x_max= max(self.left_line.x1, self.right_line.x1) 
    182          
    183         y_min= min(self.top_line.y1, self.bottom_line.y1) 
    184         y_max= max(self.top_line.y1, self.bottom_line.y1)   
     130        x_min= -1*math.fabs(self.vertical_lines.x) 
     131        x_max= math.fabs(self.vertical_lines.x) 
     132         
     133        y_min= -1*math.fabs(self.horizontal_lines.y) 
     134        y_max= math.fabs(self.horizontal_lines.y) 
    185135         
    186136        if nbins !=None: 
     
    223173        wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, 
    224174                                                 title=str(self.averager.__name__) )) 
    225          
    226          
    227     def _post_data(self): 
    228         # Compute data 
    229         data = self.base.data2D 
    230         from DataLoader.manipulations import  Boxavg 
    231         radius = math.sqrt(math.pow(self.qmax,2)+math.pow(self.qmax,2)) 
    232         self.x= math.fabs(self.right_line.x1) 
    233         self.y= math.fabs(self.top_line.y1 ) 
    234         
    235         box =  Boxavg (x_min=-self.x, x_max=self.x, y_min=-self.y, y_max=self.y) 
    236         
    237         self.count, self.error= box(self.base.data2D) 
    238          
    239         #print "post data" 
     175     
    240176               
    241177                                        
     
    255191        Restore the roughness for this layer. 
    256192        """ 
    257         self.left_line.restore() 
    258         self.right_line.restore() 
    259         self.top_line.restore() 
    260         self.bottom_line.restore() 
     193        self.horizontal_lines.restore() 
     194        self.vertical_lines.restore() 
     195        
    261196 
    262197    def move(self, x, y, ev): 
     
    271206    def get_params(self): 
    272207        params = {} 
    273         params["x_max"]= math.fabs(self.right_line.x1) 
    274         params["y_max"]= math.fabs(self.top_line.y1) 
     208        params["x_max"]= math.fabs(self.vertical_lines.x) 
     209        params["y_max"]= math.fabs(self.horizontal_lines.y) 
    275210        params["nbins"]= self.nbins 
    276         params["errors"] = self.error 
    277         params["count"]= self.count 
     211       
    278212        return params 
    279213     
     
    283217        self.y = float(math.fabs(params["y_max"] )) 
    284218        self.nbins=params["nbins"] 
    285         self.left_line.update(xmin= -1*self.x, 
    286                               xmax = -1*self.x, 
    287                               ymin= -self.y, 
    288                               ymax=  self.y,  
    289                               ) 
    290         self.right_line.update(xmin= self.x, 
    291                               xmax = self.x, 
    292                               ymin= -self.y, 
    293                               ymax=  self.y,  
    294                               ) 
    295         self.top_line.update(xmin= -1*self.x, 
    296                              xmax= self.x, 
    297                              ymin= self.y, 
    298                              ymax= self.y) 
    299         self.bottom_line.update(xmin= -1*self.x, 
    300                                  xmax= self.x, 
    301                                  ymin= -1*self.y, 
    302                                  ymax= -1*self.y) 
    303         
     219         
     220        self.horizontal_lines.update(x= self.x, y=  self.y) 
     221        self.vertical_lines.update(x= self.x, y=  self.y) 
    304222        self.post_data( nbins=None) 
     223         
     224         
    305225    def freeze_axes(self): 
    306226        self.base.freeze_axes() 
     
    312232        self.base.draw() 
    313233 
    314 class HorizontalLine(_BaseInteractor): 
     234class HorizontalLines(_BaseInteractor): 
    315235    """ 
    316236         Select an annulus through a 2D plot 
    317237    """ 
    318     def __init__(self,base,axes,color='black', zorder=5,mline=None,ymin=None, ymax=None, y=0.5, 
    319                  xmin=0.0,xmax=0.5): 
     238    def __init__(self,base,axes,color='black', zorder=5,x=0.5, y=0.5): 
    320239         
    321240        _BaseInteractor.__init__(self, base, axes, color=color) 
    322241        self.markers = [] 
    323242        self.axes = axes 
    324         self.x1= xmax 
    325         self.save_x1= xmax 
    326          
    327         self.x2= xmin 
    328         self.save_x2= xmin 
    329          
    330         self.y1= ymax 
    331         self.save_y1= ymax 
    332          
    333         self.y2= ymin 
    334         self.save_y2= ymin 
    335         self.mline= mline 
    336         self.line = self.axes.plot([self.x1,-self.x1], 
    337                                    [self.y1,self.y2], 
     243        self.x= x 
     244        self.save_x= x 
     245         
     246        self.y= y 
     247        self.save_y= y 
     248        
     249        try: 
     250            # Inner circle marker 
     251            self.inner_marker = self.axes.plot([0],[self.y], linestyle='', 
     252                                          marker='s', markersize=10, 
     253                                          color=self.color, alpha=0.6, 
     254                                          pickradius=5, label="pick",  
     255                                          zorder=zorder, # Prefer this to other lines 
     256                                          visible=True)[0] 
     257        except: 
     258            self.inner_marker = self.axes.plot([0],[self.y], linestyle='', 
     259                                          marker='s', markersize=10, 
     260                                          color=self.color, alpha=0.6, 
     261                                          label="pick",  
     262                                          visible=True)[0] 
     263            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
     264            message += "Get the SVN version that is at least as recent as June 1, 2007" 
     265             
     266        self.top_line = self.axes.plot([self.x,-self.x], 
     267                                   [self.y,self.y], 
    338268                                      linestyle='-', marker='', 
    339269                                      color=self.color, 
    340270                                      visible=True)[0] 
    341          
    342         self.npts = 20 
     271        self.bottom_line = self.axes.plot([self.x,-self.x], 
     272                                   [-self.y,-self.y], 
     273                                      linestyle='-', marker='', 
     274                                      color=self.color, 
     275                                      visible=True)[0] 
     276         
    343277        self.has_move=False 
    344         self.connect_markers([self.line]) 
     278        self.connect_markers([self.top_line, self.inner_marker]) 
    345279        self.update() 
    346280 
     
    352286        self.clear_markers() 
    353287        try: 
    354              
    355             self.line.remove() 
     288            self.inner_marker.remove() 
     289            self.top_line.remove()  
     290            self.bottom_line.remove() 
    356291        except: 
    357292            # Old version of matplotlib 
     
    359294                del self.axes.lines[0] 
    360295    
    361     def get_radius(self): 
    362          
    363         return 0 
    364296    
    365     def update(self,xmin=None, xmax=None,ymin=None,ymax=None, mline=None,translation=False): 
     297    def update(self,x=None,y=None): 
    366298        """ 
    367299        Draw the new roughness on the graph. 
    368300        """ 
    369         if xmin !=None: 
    370             self.x1 = xmin 
    371         if ymin !=None: 
    372             self.y1 = ymin 
    373         self.line.set(xdata=[self.x1,-self.x1], 
    374                        ydata=[self.y1,self.y1]) 
    375      
     301        if x!=None: 
     302            self.x = numpy.sign(self.x)*math.fabs(x) 
     303        if y !=None: 
     304            self.y = numpy.sign(self.y)*math.fabs(y) 
     305        self.inner_marker.set(xdata=[0],ydata=[self.y]) 
     306         
     307        self.top_line.set(xdata=[self.x,-self.x], 
     308                       ydata=[self.y,self.y]) 
     309        self.bottom_line.set(xdata=[self.x,-self.x], 
     310                       ydata=[-self.y, -self.y]) 
    376311         
    377312         
     
    381316        can restore on Esc. 
    382317        """ 
    383         self.save_x1= self.x1 
    384         self.save_x2= self.x2 
    385         
    386         self.save_y1= self.y1 
    387         self.save_y2= self.y2 
    388      
     318        self.save_x= self.x 
     319        self.save_y= self.y 
    389320         
    390321        self.base.freeze_axes() 
     
    399330        Restore the roughness for this layer. 
    400331        """ 
    401         self.x1 = self.save_x1 
    402         self.x2 = self.save_x2 
    403         self.y1 = self.save_y1 
    404         self.y2 = self.save_y2 
     332        self.x = self.save_x 
     333        self.y = self.save_y 
    405334         
    406335 
     
    410339        """ 
    411340        #print "horizontal move x y " 
    412         self.y1= y 
     341        self.y= y 
    413342        self.has_move=True 
    414343        self.base.base.update() 
    415344         
    416     def set_cursor(self, x, y): 
    417         self.move(x, y, None) 
    418         self.update() 
    419          
    420          
    421     def get_params(self): 
    422         params = {} 
    423         params["radius"] = self.x1 
    424         #params["theta"] = self.xmax 
    425         return params 
    426      
    427     def set_params(self, params): 
    428  
    429         x = params["radius"]  
    430         self.set_cursor(x, self._inner_mouse_y) 
    431          
    432  
    433  
    434  
    435 class VerticalLine(_BaseInteractor): 
     345   
     346         
     347   
     348     
     349class VerticalLines(_BaseInteractor): 
    436350    """ 
    437351         Select an annulus through a 2D plot 
    438352    """ 
    439     def __init__(self,base,axes,color='black', zorder=5, mline=None, ymin=0.0,  
    440                  ymax=0.5,xmin=-0.5,xmax=0.5 
    441                  ): 
     353    def __init__(self,base,axes,color='black',zorder=5,x=0.5, y=0.5): 
    442354         
    443355        _BaseInteractor.__init__(self, base, axes, color=color) 
     
    445357        self.axes = axes 
    446358         
    447         self.x1= xmax 
    448         self.x2= xmin 
    449         self.y1= ymax 
    450         self.y2= ymin 
    451         self.line = self.axes.plot([self.x1,self.x2],[self.y1,self.y2], 
     359        self.x= math.fabs(x) 
     360        self.save_x= self.x 
     361        self.y= math.fabs(y) 
     362        self.save_y= y 
     363         
     364        try: 
     365            # Inner circle marker 
     366            self.inner_marker = self.axes.plot([self.x],[0], linestyle='', 
     367                                          marker='s', markersize=10, 
     368                                          color=self.color, alpha=0.6, 
     369                                          pickradius=5, label="pick",  
     370                                          zorder=zorder, # Prefer this to other lines 
     371                                          visible=True)[0] 
     372        except: 
     373            self.inner_marker = self.axes.plot([self.x],[0], linestyle='', 
     374                                          marker='s', markersize=10, 
     375                                          color=self.color, alpha=0.6, 
     376                                          label="pick",  
     377                                          visible=True)[0] 
     378            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
     379            message += "Get the SVN version that is at least as recent as June 1, 2007" 
     380             
     381        self.right_line = self.axes.plot([self.x,self.x],[self.y,-self.y], 
     382                                      linestyle='-', marker='', 
     383                                      color=self.color, 
     384                                      visible=True)[0] 
     385        self.left_line = self.axes.plot([-self.x,-self.x],[self.y,-self.y], 
    452386                                      linestyle='-', marker='', 
    453387                                      color=self.color, 
     
    455389       
    456390        self.has_move=False 
    457         self.connect_markers([self.line]) 
     391        self.connect_markers([self.right_line, self.inner_marker]) 
    458392        self.update() 
    459393 
     
    465399        self.clear_markers() 
    466400        try: 
    467              
    468             self.line.remove() 
     401            self.inner_marker.remove() 
     402            self.left_line.remove() 
     403            self.right_line.remove() 
    469404        except: 
    470405            # Old version of matplotlib 
    471406            for item in range(len(self.axes.lines)): 
    472407                del self.axes.lines[0] 
    473     
    474      
    475     def get_radius(self): 
    476         return 0 
    477      
    478     def update(self,xmin=None,xmax=None,ymin=None, ymax=None, opline=None,translation=False): 
     408 
     409    def update(self,x=None,y=None): 
    479410        """ 
    480411        Draw the new roughness on the graph. 
    481412        """ 
    482413 
    483     
    484         if xmin!=None: 
    485             self.x1=xmin 
    486         if ymin!=None: 
    487             self.y1=ymin 
    488         self.line.set(xdata=[self.x1,self.x1], 
    489                        ydata=[self.y1,-self.y1])  
    490          
     414        if x!=None: 
     415            self.x = numpy.sign(self.x)*math.fabs(x) 
     416        if y !=None: 
     417            self.y = numpy.sign(self.y)*math.fabs(y) 
     418             
     419        self.inner_marker.set(xdata=[self.x],ydata=[0])  
     420        self.left_line.set(xdata=[-self.x,-self.x], 
     421                       ydata=[self.y,-self.y])  
     422        self.right_line.set(xdata=[self.x,self.x], 
     423                       ydata=[self.y,-self.y])  
    491424     
    492425         
     
    496429        can restore on Esc. 
    497430        """ 
    498         self.save_x1= self.x1 
    499         self.save_x2= self.x2 
    500         self.save_y1= self.y1 
    501         self.save_y2= self.y2 
     431        self.save_x= self.x 
     432        self.save_y= self.y 
    502433         
    503434        self.base.freeze_axes() 
     
    512443        Restore the roughness for this layer. 
    513444        """ 
    514         self.x1 = self.save_x1 
    515         self.x2 = self.save_x2 
    516         self.y1 = self.save_y1 
    517         self.y2= self.save_y2 
     445        self.x = self.save_x 
     446        self.y = self.save_y 
    518447       
    519448         
     
    523452        """ 
    524453        self.has_move=True 
    525          
    526         # compute the b intercept of the vertical line 
    527         self.x1= x 
    528          
    529          
     454        self.x= x 
    530455        self.base.base.update() 
    531456         
    532          
    533     def set_cursor(self, x, y): 
    534         self.move(x, y, None) 
    535         self.update() 
    536          
    537          
    538     def get_params(self): 
    539         params = {} 
    540         params["x"] = self.xmin 
    541         params["ymin"] = self.ymin 
    542         params["ymax"] = self.ymax 
    543         return params 
    544      
    545     def set_params(self, params): 
    546         """ 
    547             Draw a vertical line given some value of params 
    548             @param params: a dictionary containing value for x, ymin , ymax to draw  
    549             a vertical line 
    550         """ 
    551         x = params["x"]  
    552         ymin = params["ymin"]  
    553         ymax = params["ymax"]  
    554         #self.set_cursor(x, self._inner_mouse_y) 
    555         self.update(self,x =x,ymin =ymin, ymax =ymax) 
     457    
    556458         
    557459 
Note: See TracChangeset for help on using the changeset viewer.