Ignore:
Timestamp:
Mar 5, 2015 2:49:03 PM (10 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
7d56795
Parents:
824e488
Message:

pylint fixes

File:
1 edited

Legend:

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

    r79492222 rb5de88e  
    1  
    2  
    31import wx 
    4 #import copy 
    5 #from copy import deepcopy 
    62import math 
    73import numpy 
     
    128from BaseInteractor import _BaseInteractor 
    139from sas.guiframe.dataFitting import Data1D 
    14 #import SlicerParameters 
    1510 
    1611 
     
    2217    def __init__(self, base, axes, color='black', zorder=3): 
    2318        _BaseInteractor.__init__(self, base, axes, color=color) 
    24         ## Class initialization 
     19        # # Class initialization 
    2520        self.markers = [] 
    2621        self.axes = axes 
    27         ##connecting artist 
     22        # #connecting artist 
    2823        self.connect = self.base.connect 
    29         ## which direction is the preferred interaction direction 
     24        # # which direction is the preferred interaction direction 
    3025        self.direction = None 
    31         ## determine x y  values 
     26        # # determine x y  values 
    3227        self.x = 0.5 * min(math.fabs(self.base.data2D.xmax), 
    3328                           math.fabs(self.base.data2D.xmin)) 
    3429        self.y = 0.5 * min(math.fabs(self.base.data2D.xmax), 
    35                            math.fabs(self.base.data2D.xmin))         
    36         ## when reach qmax reset the graph 
     30                           math.fabs(self.base.data2D.xmin)) 
     31        # # when reach qmax reset the graph 
    3732        self.qmax = max(self.base.data2D.xmax, self.base.data2D.xmin, 
    38                         self.base.data2D.ymax, self.base.data2D.ymin)    
    39         ## Number of points on the plot 
     33                        self.base.data2D.ymax, self.base.data2D.ymin) 
     34        # # Number of points on the plot 
    4035        self.nbins = 30 
    41         ## If True, I(|Q|) will be return, otherwise, 
    42         #negative q-values are allowed 
    43         self.fold = True         
    44         ## reference of the current  Slab averaging 
     36        # # If True, I(|Q|) will be return, otherwise, 
     37        # negative q-values are allowed 
     38        self.fold = True 
     39        # # reference of the current  Slab averaging 
    4540        self.averager = None 
    46         ## Create vertical and horizaontal lines for the rectangle 
     41        # # Create vertical and horizaontal lines for the rectangle 
    4742        self.vertical_lines = VerticalLines(self, 
    48                                             self.base.subplot,  
    49                                             color='blue',  
     43                                            self.base.subplot, 
     44                                            color='blue', 
    5045                                            zorder=zorder, 
    51                                             y=self.y , 
     46                                            y=self.y, 
    5247                                            x=self.x) 
    5348        self.vertical_lines.qmax = self.qmax 
    54         
     49 
    5550        self.horizontal_lines = HorizontalLines(self, 
    56                                                self.base.subplot, 
    57                                                color='green',  
    58                                                zorder=zorder, 
    59                                                x=self.x, 
    60                                                y=self.y) 
     51                                                self.base.subplot, 
     52                                                color='green', 
     53                                                zorder=zorder, 
     54                                                x=self.x, 
     55                                                y=self.y) 
    6156        self.horizontal_lines.qmax = self.qmax 
    62         ## draw the rectangle and plost the data 1D resulting 
    63         ## of averaging data2D 
     57        # # draw the rectangle and plost the data 1D resulting 
     58        # # of averaging data2D 
    6459        self.update() 
    6560        self._post_data() 
    66         ## Bind to slice parameter events 
     61        # # Bind to slice parameter events 
    6762        self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 
    6863 
     
    7065        """ 
    7166        receive an event containing parameters values to reset the slicer 
    72          
    73         :param event: event of type SlicerParameterEvent with params as  
     67 
     68        :param event: event of type SlicerParameterEvent with params as 
    7469            attribute 
    7570        """ 
     
    8075            self.set_params(event.params) 
    8176            self.base.update() 
    82              
     77 
    8378    def update_and_post(self): 
    8479        """ 
     
    8782        self.update() 
    8883        self._post_data() 
    89          
     84 
    9085    def set_layer(self, n): 
    9186        """ 
    9287        Allow adding plot to the same panel 
    93          
     88 
    9489        :param n: the number of layer 
    95          
     90 
    9691        """ 
    9792        self.layernum = n 
    9893        self.update() 
    99          
     94 
    10095    def clear(self): 
    10196        """ 
     
    108103        self.base.connect.clearall() 
    109104        self.base.Unbind(EVT_SLICER_PARS) 
    110          
     105 
    111106    def update(self): 
    112107        """ 
     
    114109        resetting the widgets. 
    115110        """ 
    116         ##Update the slicer if an horizontal line is dragged    
     111        # #Update the slicer if an horizontal line is dragged 
    117112        if self.horizontal_lines.has_move: 
    118113            self.horizontal_lines.update() 
    119114            self.vertical_lines.update(y=self.horizontal_lines.y) 
    120         ##Update the slicer if a vertical line is dragged     
     115        # #Update the slicer if a vertical line is dragged 
    121116        if self.vertical_lines.has_move: 
    122117            self.vertical_lines.update() 
    123118            self.horizontal_lines.update(x=self.vertical_lines.x) 
    124                   
     119 
    125120    def save(self, ev): 
    126121        """ 
     
    131126        self.vertical_lines.save(ev) 
    132127        self.horizontal_lines.save(ev) 
    133      
     128 
    134129    def _post_data(self): 
    135130        pass 
    136          
     131 
    137132    def post_data(self, new_slab=None, nbins=None, direction=None): 
    138133        """ 
    139134        post data averaging in Qx or Qy given new_slab type 
    140          
     135 
    141136        :param new_slab: slicer that determine with direction to average 
    142137        :param nbins: the number of points plotted when averaging 
    143138        :param direction: the direction of averaging 
    144          
     139 
    145140        """ 
    146141        if self.direction == None: 
    147142            self.direction = direction 
    148              
     143 
    149144        x_min = -1 * math.fabs(self.vertical_lines.x) 
    150145        x_max = math.fabs(self.vertical_lines.x) 
    151146        y_min = -1 * math.fabs(self.horizontal_lines.y) 
    152147        y_max = math.fabs(self.horizontal_lines.y) 
    153          
     148 
    154149        if nbins != None: 
    155150            self.nbins = nbins 
     
    164159            else: 
    165160                x_low = math.fabs(x_min) 
    166             bin_width = (x_max + x_low)/self.nbins 
     161            bin_width = (x_max + x_low) / self.nbins 
    167162        elif self.direction == "Y": 
    168163            if self.fold: 
     
    170165            else: 
    171166                y_low = math.fabs(y_min) 
    172             bin_width = (y_max + y_low)/self.nbins 
     167            bin_width = (y_max + y_low) / self.nbins 
    173168        else: 
    174169            msg = "post data:no Box Average direction was supplied" 
    175170            raise ValueError, msg 
    176         ## Average data2D given Qx or Qy 
     171        # # Average data2D given Qx or Qy 
    177172        box = self.averager(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max, 
    178                          bin_width=bin_width) 
     173                            bin_width=bin_width) 
    179174        box.fold = self.fold 
    180175        boxavg = box(self.base.data2D) 
    181         #3 Create Data1D to plot 
     176        # 3 Create Data1D to plot 
    182177        if hasattr(boxavg, "dxl"): 
    183178            dxl = boxavg.dxl 
     
    189184            dxw = None 
    190185        new_plot = Data1D(x=boxavg.x, y=boxavg.y, dy=boxavg.dy) 
    191         new_plot.dxl  = dxl 
    192         new_plot.dxw  = dxw 
     186        new_plot.dxl = dxl 
     187        new_plot.dxw = dxw 
    193188        new_plot.name = str(self.averager.__name__) + \ 
    194189                        "(" + self.base.data2D.name + ")" 
     
    196191        new_plot.interactive = True 
    197192        new_plot.detector = self.base.data2D.detector 
    198         ## If the data file does not tell us what the axes are, just assume... 
     193        # # If the data file does not tell us what the axes are, just assume... 
    199194        new_plot.xaxis("\\rm{Q}", "A^{-1}") 
    200195        new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 
     
    205200            new_plot.ytransform = 'y' 
    206201            new_plot.yaxis("\\rm{Residuals} ", "/") 
    207              
     202 
    208203        new_plot.group_id = "2daverage" + self.base.data2D.name 
    209204        new_plot.id = (self.averager.__name__) + self.base.data2D.name 
    210         new_plot.is_data= True 
     205        new_plot.is_data = True 
    211206        self.base.parent.update_theory(data_id=self.base.data2D.id, \ 
    212207                                       theory=new_plot) 
    213         wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, 
    214                                title=str(self.averager.__name__))) 
    215            
     208        wx.PostEvent(self.base.parent, 
     209                     NewPlotEvent(plot=new_plot, title=str(self.averager.__name__))) 
     210 
    216211    def moveend(self, ev): 
    217212        """ 
    218213        Called after a dragging event. 
    219         Post the slicer new parameters and creates a new Data1D  
     214        Post the slicer new parameters and creates a new Data1D 
    220215        corresponding to the new average 
    221216        """ 
     
    228223        # create the new data1D 
    229224        self._post_data() 
    230              
     225 
    231226    def restore(self): 
    232227        """ 
     
    235230        self.horizontal_lines.restore() 
    236231        self.vertical_lines.restore() 
    237         
     232 
    238233    def move(self, x, y, ev): 
    239234        """ 
     
    241236        """ 
    242237        pass 
    243          
     238 
    244239    def set_cursor(self, x, y): 
    245240        pass 
    246          
     241 
    247242    def get_params(self): 
    248243        """ 
    249244        Store a copy of values of parameters of the slicer into a dictionary. 
    250          
     245 
    251246        :return params: the dictionary created 
    252          
     247 
    253248        """ 
    254249        params = {} 
     
    257252        params["nbins"] = self.nbins 
    258253        return params 
    259      
     254 
    260255    def set_params(self, params): 
    261256        """ 
    262         Receive a dictionary and reset the slicer with values contained  
     257        Receive a dictionary and reset the slicer with values contained 
    263258        in the values of the dictionary. 
    264          
    265         :param params: a dictionary containing name of slicer parameters and  
     259 
     260        :param params: a dictionary containing name of slicer parameters and 
    266261            values the user assigned to the slicer. 
    267262        """ 
    268263        self.x = float(math.fabs(params["x_max"])) 
    269         self.y = float(math.fabs(params["y_max"] )) 
     264        self.y = float(math.fabs(params["y_max"])) 
    270265        self.nbins = params["nbins"] 
    271          
     266 
    272267        self.horizontal_lines.update(x=self.x, y=self.y) 
    273268        self.vertical_lines.update(x=self.x, y=self.y) 
    274269        self.post_data(nbins=None) 
    275          
     270 
    276271    def freeze_axes(self): 
    277272        """ 
    278273        """ 
    279274        self.base.freeze_axes() 
    280          
     275 
    281276    def thaw_axes(self): 
    282277        """ 
     
    292287class HorizontalLines(_BaseInteractor): 
    293288    """ 
    294     Draw 2 Horizontal lines centered on (0,0) that can move  
     289    Draw 2 Horizontal lines centered on (0,0) that can move 
    295290    on the x- direction and in opposite direction 
    296291    """ 
     
    299294        """ 
    300295        _BaseInteractor.__init__(self, base, axes, color=color) 
    301         ##Class initialization 
     296        # #Class initialization 
    302297        self.markers = [] 
    303298        self.axes = axes 
    304         ## Saving the end points of two lines 
     299        # # Saving the end points of two lines 
    305300        self.x = x 
    306301        self.save_x = x 
    307          
     302 
    308303        self.y = y 
    309304        self.save_y = y 
    310         ## Creating a marker 
    311         try: 
    312             # Inner circle marker 
    313             self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 
    314                                           marker='s', markersize=10, 
    315                                           color=self.color, alpha=0.6, 
    316                                           pickradius=5, label="pick",  
    317                                           # Prefer this to other lines 
    318                                           zorder=zorder,  
    319                                           visible=True)[0] 
    320         except: 
    321             self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 
    322                                           marker='s', markersize=10, 
    323                                           color=self.color, alpha=0.6, 
    324                                           label="pick", visible=True)[0] 
    325             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION " 
    326             message += "OF MATPLOTLIB\n Get the SVN version that" 
    327             message += " is at least as recent as June 1, 2007" 
    328             owner = self.base.base.parent 
    329             wx.PostEvent(owner, 
    330                          StatusEvent(status="AnnulusSlicer: %s" % message)) 
    331         ## Define 2 horizontal lines 
     305        # # Creating a marker 
     306        # Inner circle marker 
     307        self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 
     308                                           marker='s', markersize=10, 
     309                                           color=self.color, alpha=0.6, 
     310                                           pickradius=5, label="pick", 
     311                                           zorder=zorder, 
     312                                           visible=True)[0] 
     313        # # Define 2 horizontal lines 
    332314        self.top_line = self.axes.plot([self.x, -self.x], [self.y, self.y], 
    333                                       linestyle='-', marker='', 
    334                                       color=self.color, visible=True)[0] 
     315                                       linestyle='-', marker='', 
     316                                       color=self.color, visible=True)[0] 
    335317        self.bottom_line = self.axes.plot([self.x, -self.x], [-self.y, -self.y], 
    336                                       linestyle='-', marker='', 
    337                                       color=self.color, visible=True)[0] 
    338         ## Flag to check the motion of the lines 
     318                                          linestyle='-', marker='', 
     319                                          color=self.color, visible=True)[0] 
     320        # # Flag to check the motion of the lines 
    339321        self.has_move = False 
    340         ## Connecting markers to mouse events and draw 
     322        # # Connecting markers to mouse events and draw 
    341323        self.connect_markers([self.top_line, self.inner_marker]) 
    342324        self.update() 
     
    345327        """ 
    346328        Allow adding plot to the same panel 
    347          
     329 
    348330        :param n: the number of layer 
    349          
     331 
    350332        """ 
    351333        self.layernum = n 
    352334        self.update() 
    353          
     335 
    354336    def clear(self): 
    355337        """ 
     
    359341        try: 
    360342            self.inner_marker.remove() 
    361             self.top_line.remove()  
     343            self.top_line.remove() 
    362344            self.bottom_line.remove() 
    363345        except: 
     
    365347            for item in range(len(self.axes.lines)): 
    366348                del self.axes.lines[0] 
    367     
     349 
    368350    def update(self, x=None, y=None): 
    369351        """ 
    370352        Draw the new roughness on the graph. 
    371          
     353 
    372354        :param x: x-coordinates to reset current class x 
    373355        :param y: y-coordinates to reset current class y 
    374          
    375         """ 
    376         ## Reset x, y- coordinates if send as parameters 
     356 
     357        """ 
     358        # # Reset x, y- coordinates if send as parameters 
    377359        if x != None: 
    378360            self.x = numpy.sign(self.x) * math.fabs(x) 
    379361        if y != None: 
    380362            self.y = numpy.sign(self.y) * math.fabs(y) 
    381         ## Draw lines and markers 
     363        # # Draw lines and markers 
    382364        self.inner_marker.set(xdata=[0], ydata=[self.y]) 
    383365        self.top_line.set(xdata=[self.x, -self.x], ydata=[self.y, self.y]) 
    384         self.bottom_line.set(xdata=[self.x,-self.x], ydata=[-self.y, -self.y]) 
    385          
     366        self.bottom_line.set(xdata=[self.x, -self.x], ydata=[-self.y, -self.y]) 
     367 
    386368    def save(self, ev): 
    387369        """ 
     
    400382        self.has_move = False 
    401383        self.base.moveend(ev) 
    402               
     384 
    403385    def restore(self): 
    404386        """ 
     
    407389        self.x = self.save_x 
    408390        self.y = self.save_y 
    409          
     391 
    410392    def move(self, x, y, ev): 
    411393        """ 
     
    415397        self.has_move = True 
    416398        self.base.base.update() 
    417          
    418    
     399 
     400 
    419401class VerticalLines(_BaseInteractor): 
    420402    """ 
     
    431413        self.y = math.fabs(y) 
    432414        self.save_y = y 
    433         try: 
    434             # Inner circle marker 
    435             self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 
    436                                           marker='s', markersize=10, 
    437                                           color=self.color, alpha=0.6, 
    438                                           pickradius=5, label="pick",  
    439                                           # Prefer this to other lines 
    440                                           zorder=zorder, visible=True)[0] 
    441         except: 
    442             self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 
    443                                           marker='s', markersize=10, 
    444                                           color=self.color, alpha=0.6, 
    445                                           label="pick", visible=True)[0] 
    446             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION" 
    447             message += " OF MATPLOTLIB\n Get the SVN version that is" 
    448             message += " at least as recent as June 1, 2007" 
    449              
     415        # Inner circle marker 
     416        self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 
     417                                           marker='s', markersize=10, 
     418                                           color=self.color, alpha=0.6, 
     419                                           pickradius=5, label="pick", 
     420                                           zorder=zorder, visible=True)[0] 
    450421        self.right_line = self.axes.plot([self.x, self.x], 
    451                                          [self.y , -self.y], 
    452                                       linestyle='-', marker='', 
    453                                       color=self.color, visible=True)[0] 
     422                                         [self.y, -self.y], 
     423                                         linestyle='-', marker='', 
     424                                         color=self.color, visible=True)[0] 
    454425        self.left_line = self.axes.plot([-self.x, -self.x], 
    455426                                        [self.y, -self.y], 
    456                                       linestyle='-', marker='', 
    457                                       color=self.color, visible=True)[0] 
     427                                        linestyle='-', marker='', 
     428                                        color=self.color, visible=True)[0] 
    458429        self.has_move = False 
    459430        self.connect_markers([self.right_line, self.inner_marker]) 
     
    463434        """ 
    464435        Allow adding plot to the same panel 
    465          
     436 
    466437        :param n: the number of layer 
    467          
     438 
    468439        """ 
    469440        self.layernum = n 
    470441        self.update() 
    471          
     442 
    472443    def clear(self): 
    473444        """ 
     
    487458        """ 
    488459        Draw the new roughness on the graph. 
    489          
     460 
    490461        :param x: x-coordinates to reset current class x 
    491462        :param y: y-coordinates to reset current class y 
    492          
    493         """ 
    494         ## reset x, y -coordinates if given as parameters 
     463 
     464        """ 
     465        # # reset x, y -coordinates if given as parameters 
    495466        if x != None: 
    496467            self.x = numpy.sign(self.x) * math.fabs(x) 
    497468        if y != None: 
    498469            self.y = numpy.sign(self.y) * math.fabs(y) 
    499         ## draw lines and markers   
    500         self.inner_marker.set(xdata=[self.x], ydata=[0])  
    501         self.left_line.set(xdata=[-self.x, -self.x], ydata=[self.y, -self.y])  
    502         self.right_line.set(xdata=[self.x, self.x], ydata=[self.y, -self.y])  
    503      
     470        # # draw lines and markers 
     471        self.inner_marker.set(xdata=[self.x], ydata=[0]) 
     472        self.left_line.set(xdata=[-self.x, -self.x], ydata=[self.y, -self.y]) 
     473        self.right_line.set(xdata=[self.x, self.x], ydata=[self.y, -self.y]) 
     474 
    504475    def save(self, ev): 
    505476        """ 
     
    510481        self.save_y = self.y 
    511482        self.base.freeze_axes() 
    512          
     483 
    513484    def moveend(self, ev): 
    514485        """ 
     
    518489        self.has_move = False 
    519490        self.base.moveend(ev) 
    520                 
     491 
    521492    def restore(self): 
    522493        """ 
     
    525496        self.x = self.save_x 
    526497        self.y = self.save_y 
    527        
     498 
    528499    def move(self, x, y, ev): 
    529500        """ 
     
    533504        self.x = x 
    534505        self.base.base.update() 
    535          
    536     
     506 
     507 
    537508class BoxInteractorX(BoxInteractor): 
    538509    """ 
     
    543514        self.base = base 
    544515        self._post_data() 
    545          
     516 
    546517    def _post_data(self): 
    547518        """ 
     
    549520        """ 
    550521        from sas.dataloader.manipulations import SlabX 
    551         self.post_data(SlabX, direction="X")    
    552          
     522        self.post_data(SlabX, direction="X") 
     523 
    553524 
    554525class BoxInteractorY(BoxInteractor): 
     
    560531        self.base = base 
    561532        self._post_data() 
    562          
     533 
    563534    def _post_data(self): 
    564535        """ 
     
    566537        """ 
    567538        from sas.dataloader.manipulations import SlabY 
    568         self.post_data(SlabY, direction="Y")    
    569          
    570          
     539        self.post_data(SlabY, direction="Y") 
     540 
Note: See TracChangeset for help on using the changeset viewer.