Changeset 2df0b74 in sasview


Ignore:
Timestamp:
Mar 5, 2015 11:17:05 AM (9 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:
3477478
Parents:
dca6188
Message:

pylint fixes

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • build_tools/pylint.rc

    rdca6188 r2df0b74  
    9898 
    9999# Good variable names which should always be accepted, separated by a comma 
    100 good-names=i,j,k,ex,Run,_,x,y,z,qx,qy,qz,n,q,dx,dy,dz,id,Iq,dIq,Qx,Qy,Qz,ix,iy,iz 
     100good-names=i,j,k,ex,Run,_,x,y,z,qx,qy,qz,n,q,dx,dy,dz,id,Iq,dIq,Qx,Qy,Qz,ix,iy,iz,nx,ny,nz,getParam,setParam,runXY 
    101101 
    102102# Bad variable names which should always be refused, separated by a comma 
  • src/sas/plottools/BaseInteractor.py

    r79492222 r2df0b74  
    99 
    1010 
    11 class _BaseInteractor: 
     11class _BaseInteractor(object): 
    1212    """ 
    1313    Share some functions between the interface interactor and various layer 
    1414    interactors. 
    15      
     15 
    1616    Individual interactors need the following functions: 
    17      
     17 
    1818        save(ev)  - save the current state for later restore 
    1919        restore() - restore the old state 
     
    2121        moveend(ev) - end the drag event 
    2222        update() - draw the interactors 
    23          
     23 
    2424    The following are provided by the base class: 
    25      
     25 
    2626        connect_markers(markers) - register callbacks for all markers 
    2727        clear_markers() - remove all items in self.markers 
     
    3232        onDrag(ev) - mouse move: calls move() or restore() 
    3333        onKey(ev) - keyboard move: calls move() or restore() 
    34          
     34 
    3535    Interactor attributes: 
    36      
     36 
    3737        base  - model we are operating on 
    3838        axes  - axes holding the interactor 
    3939        color - color of the interactor in non-active state 
    4040        markers - list of handles for the interactor 
    41          
     41 
    4242    """ 
    4343    def __init__(self, base, axes, color='black'): 
     
    4848        self.color = color 
    4949        self.markers = [] 
    50          
     50 
    5151    def clear_markers(self): 
    5252        ''' 
     
    6363        """ 
    6464        pass 
    65      
     65 
    6666    def restore(self, ev): 
    6767        """ 
    6868        """ 
    6969        pass 
    70      
     70 
    7171    def move(self, x, y, ev): 
    7272        """ 
    7373        """ 
    7474        pass 
    75      
     75 
    7676    def moveend(self, ev): 
    7777        """ 
     
    108108        self.base.draw() 
    109109        return True 
    110              
     110 
    111111    def onClick(self, ev): 
    112112        """ 
     
    137137        self.base.update() 
    138138        return True 
    139      
     139 
    140140    def onKey(self, ev): 
    141141        """ 
    142142        Respond to keyboard events.  Arrow keys move the widget.  Escape 
    143143        restores it to the position before the last click. 
    144          
     144 
    145145        Calls move() to update the state.  Calls restore() on escape. 
    146146        """ 
     
    173173        px, py = ax.transData.inverse_xy_tup((x, y)) 
    174174        if nudge: 
    175             nx, ny = ax.transData.xy_tup((px+0.2, py+0.2)) 
     175            nx, ny = ax.transData.xy_tup((px + 0.2, py + 0.2)) 
    176176        else: 
    177             nx, ny = ax.transData.xy_tup((px+1., py+1.)) 
    178         dx, dy = nx-x, ny-y 
     177            nx, ny = ax.transData.xy_tup((px + 1., py + 1.)) 
     178        dx, dy = nx - x, ny - y 
    179179        return dx, dy 
  • src/sas/plottools/LabelDialog.py

    r79492222 r2df0b74  
    77    FONT_VARIANT = 1 
    88    PNL_WIDTH = 300 
    9      
     9 
    1010class LabelDialog(wx.Dialog): 
    1111    def __init__(self, parent, id, title, label): 
    1212        wx.Dialog.__init__(self, parent, id, title, size=(PNL_WIDTH, 150)) 
    1313 
    14         #panel = wx.Panel(self, -1) 
    15         #Font 
     14        # Font 
    1615        self.SetWindowVariant(variant=FONT_VARIANT) 
    1716        mainbox = wx.BoxSizer(wx.VERTICAL) 
    1817        vbox = wx.BoxSizer(wx.VERTICAL) 
    1918        textbox = wx.BoxSizer(wx.HORIZONTAL) 
    20          
     19 
    2120        text1 = "Enter a new title/label:" 
    22         msg = wx.StaticText(self, -1, text1,(30,15), style=wx.ALIGN_LEFT) 
     21        msg = wx.StaticText(self, -1, text1, (30, 15), style=wx.ALIGN_LEFT) 
    2322        msg.SetLabel(text1) 
    24         self.myTxtCtrl = wx.TextCtrl(self, -1, '', (200, 30)) 
    25         self.myTxtCtrl.SetValue(str(label)) 
    26         textbox.Add(self.myTxtCtrl, flag=wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE,  
    27                  border=10, proportion=2) 
     23        self.label_ctrl = wx.TextCtrl(self, -1, '', (200, 30)) 
     24        self.label_ctrl.SetValue(str(label)) 
     25        textbox.Add(self.label_ctrl, flag=wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 
     26                    border=10, proportion=2) 
    2827        vbox.Add(msg, flag=wx.ALL, border=10, proportion=1) 
    29         vbox.Add(textbox, flag=wx.EXPAND|wx.TOP|wx.BOTTOM|wx.ADJUST_MINSIZE, 
    30                  border=5) 
     28        vbox.Add(textbox, flag=wx.EXPAND | wx.TOP | wx.BOTTOM | wx.ADJUST_MINSIZE, border=5) 
    3129        hbox = wx.BoxSizer(wx.HORIZONTAL) 
    32         okButton = wx.Button(self,wx.ID_OK, 'OK', size=(70, 25)) 
    33         closeButton = wx.Button(self,wx.ID_CANCEL, 'Cancel', size=(70, 25)) 
    34          
    35         hbox.Add(okButton, wx.LEFT, 10) 
     30        ok_button = wx.Button(self, wx.ID_OK, 'OK', size=(70, 25)) 
     31        close_button = wx.Button(self, wx.ID_CANCEL, 'Cancel', size=(70, 25)) 
     32 
     33        hbox.Add(ok_button, wx.LEFT, 10) 
    3634        hbox.Add((20, 20)) 
    37         hbox.Add(closeButton, wx.LEFT, 10) 
     35        hbox.Add(close_button, wx.LEFT, 10) 
    3836 
    3937        mainbox.Add(vbox, flag=wx.LEFT, border=5) 
    40         mainbox.Add(wx.StaticLine(self), 0, wx.ALL|wx.EXPAND, 5) 
    41         mainbox.Add(hbox, flag=wx.CENTER,  
    42                     border=20) 
     38        mainbox.Add(wx.StaticLine(self), 0, wx.ALL | wx.EXPAND, 5) 
     39        mainbox.Add(hbox, flag=wx.CENTER, border=20) 
    4340        self.SetSizer(mainbox) 
    44      
     41 
    4542    def getText(self): 
    46         return self.myTxtCtrl.GetValue() 
     43        return self.label_ctrl.GetValue() 
  • src/sas/plottools/LineModel.py

    r79492222 r2df0b74  
    11#!/usr/bin/env python 
    2 """  
    3 Provide Line function (y= A + Bx)  
     2""" 
     3Provide Line function (y= A + Bx) 
    44""" 
    55 
     
    77 
    88class LineModel(object): 
    9     """  
     9    """ 
    1010    Class that evaluates a linear model. 
    11      
     11 
    1212    f(x) = A + Bx 
    13       
     13 
    1414    List of default parameters: 
    1515    A = 0.0 
    16     B = 0.0  
     16    B = 0.0 
    1717    """ 
    18          
     18 
    1919    def __init__(self): 
    2020        """ Initialization """ 
    21         ## Name of the model 
     21        # # Name of the model 
    2222        self.name = "LineModel" 
    2323 
    24         ## Define parameters 
     24        # # Define parameters 
    2525        self.params = {} 
    2626        self.params['A'] = 1.0 
    2727        self.params['B'] = 1.0 
    2828 
    29         ## Parameter details [units, min, max] 
     29        # # Parameter details [units, min, max] 
    3030        self.details = {} 
    3131        self.details['A'] = ['', None, None] 
    3232        self.details['B'] = ['', None, None] 
    33                 
     33 
    3434    def getParam(self, name): 
    3535        """ 
     36            Return parameter value 
    3637        """ 
    3738        return self.params[name.upper()] 
    38      
     39 
    3940    def setParam(self, name, value): 
    4041        """ 
     42            Set parameter value 
    4143        """ 
    4244        self.params[name.upper()] = value 
    43      
     45 
    4446    def _line(self, x): 
    4547        """ 
    4648        Evaluate the function 
    47          
     49 
    4850        :param x: x-value 
    49          
     51 
    5052        :return: function value 
    51          
     53 
    5254        """ 
    5355        return  self.params['A'] + (x * self.params['B']) 
    54      
    55     def run(self, x = 0.0): 
    56         """  
     56 
     57    def run(self, x=0.0): 
     58        """ 
    5759        Evaluate the model 
    58          
     60 
    5961        :param x: simple value 
    60          
     62 
    6163        :return: (Line value) 
    6264        """ 
     
    6567                                self._line(x[0] * math.sin(x[1])) 
    6668        elif x.__class__.__name__ == 'tuple': 
    67             msg  = "Tuples are not allowed as input to BaseComponent models" 
     69            msg = "Tuples are not allowed as input to BaseComponent models" 
    6870            raise ValueError, msg 
    6971        else: 
    7072            return self._line(x) 
    71     
    72     def runXY(self, x = 0.0): 
    73         """  
     73 
     74    def runXY(self, x=0.0): 
     75        """ 
    7476        Evaluate the model 
    75              
     77 
    7678        :param x: simple value 
    77          
     79 
    7880        :return: Line value 
    79          
     81 
    8082        """ 
    8183        if x.__class__.__name__ == 'list': 
     
    8688        else: 
    8789            return self._line(x) 
    88     
    89  
    90 if __name__ == "__main__":  
    91     l = Line() 
    92  
  • src/sas/plottools/arrow3d.py

    r79492222 r2df0b74  
    66from mpl_toolkits.mplot3d import proj3d 
    77import time 
    8 #from matplotlib.artist import allow_rasterization 
     8# from matplotlib.artist import allow_rasterization 
    99class Arrow3D(FancyArrowPatch): 
    1010    """ 
    1111    Draw 3D arrow 
    1212    """ 
    13      
     13 
    1414    def __init__(self, base, xs, ys, zs, colors, *args, **kwargs): 
    1515        """ 
    1616        Init 
    17              
     17 
    1818        :Params xs: [[x0, x0+dx0], [x1, x1+dx1], ...] 
    1919        :Params ys: [[y0, y0+dy0], [y1, y1+dy1], ...] 
    2020        :Params zs: [[z0, z0+dz0], [z1, z1+dz1], ...] 
    21         :Params colors: [[R0, G0, B0], [R1, G1, B1], ...]  
     21        :Params colors: [[R0, G0, B0], [R1, G1, B1], ...] 
    2222        where R, G, B ranges (0,1) 
    2323        """ 
    24         FancyArrowPatch.__init__(self, (0,0), (0,0), *args, **kwargs) 
     24        FancyArrowPatch.__init__(self, (0, 0), (0, 0), *args, **kwargs) 
    2525        self.leftdown = False 
    2626        self.t_click = 0 
     
    2828        self.colors = colors 
    2929        self.base = base 
    30          
     30 
    3131        if base != None: 
    3232            # To turn the updating off during dragging 
    33             base.canvas.mpl_connect('button_press_event', self.onLeftDown) 
    34             base.canvas.mpl_connect('button_release_event', self.onLeftUp) 
    35              
    36     def onLeftDown(self, event): 
     33            base.canvas.mpl_connect('button_press_event', self.on_left_down) 
     34            base.canvas.mpl_connect('button_release_event', self.on_left_up) 
     35 
     36    def on_left_down(self, event): 
    3737        """ 
     38            Mouse left-down event 
    3839        """ 
    3940        self.leftdown = True 
    4041        self.t_click = time.time() 
    41          
    42     def onLeftUp(self, event): 
     42 
     43    def on_left_up(self, event): 
    4344        """ 
     45            Mouse left up event 
    4446        """ 
    4547        t_up = time.time() - self.t_click 
     
    4850            self.leftdown = False 
    4951            self.base.canvas.draw() 
    50      
     52 
    5153    def draw(self, renderer, rasterized=True): 
    5254        """ 
     
    5860        xs3d, ys3d, zs3d = self._verts3d 
    5961        for i in xrange(len(xs3d)): 
    60             xs, ys, _ = proj3d.proj_transform(xs3d[i], ys3d[i], zs3d[i],  
    61                                                renderer.M) 
    62             self.set_positions((xs[0],ys[0]),(xs[1],ys[1])) 
     62            xs, ys, _ = proj3d.proj_transform(xs3d[i], ys3d[i], zs3d[i], renderer.M) 
     63            self.set_positions((xs[0], ys[0]), (xs[1], ys[1])) 
    6364            self.set_color(self.colors[i]) 
    6465            FancyArrowPatch.draw(self, renderer) 
    65              
     66 
    6667        self.leftdown = False 
  • src/sas/plottools/binder.py

    r79492222 r2df0b74  
    33""" 
    44import sys 
    5  
    6  
    7 class Selection: 
     5import logging 
     6 
     7class Selection(object): 
    88    """ 
    99    Store and compare selections. 
     
    1111    # TODO: We need some way to check in prop matches, preferably 
    1212    # TODO: without imposing structure on prop. 
    13          
     13 
    1414    artist = None 
    1515    prop = {} 
    16      
     16 
    1717    def __init__(self, artist=None, prop={}): 
    1818        self.artist, self.prop = artist, self.prop 
    19          
     19 
    2020    def __eq__(self, other): 
    2121        return self.artist is other.artist 
    22      
     22 
    2323    def __ne__(self, other): 
    2424        return self.artist is not other.artist 
    25      
     25 
    2626    def __nonzero__(self): 
    2727        return self.artist is not None 
    2828 
    2929 
    30 class BindArtist: 
     30class BindArtist(object): 
    3131    """ 
    3232    """ 
     
    4141    dclick_threshhold = 0.25 
    4242    _last_button, _last_time = None, 0 
    43      
     43 
    4444    # Mouse/keyboard events we can bind to 
    4545    events = ['enter', 'leave', 'motion', 'click', 'dclick', 'drag', 'release', 
    46              'scroll', 'key', 'keyup'] 
     46              'scroll', 'key', 'keyup'] 
    4747    # TODO: Need our own event structure 
    48      
     48 
    4949    def __init__(self, figure): 
    5050        canvas = figure.canvas 
     
    6969                canvas.mpl_connect('key_release_event', self._onKeyRelease), 
    7070            ] 
    71              
     71 
    7272        self._current = None 
    7373        self._actions = {} 
     
    7575        self.figure = figure 
    7676        self.clearall() 
    77          
     77 
    7878    def clear(self, *artists): 
    7979        """ 
    8080        self.clear(h1,h2,...) 
    8181            Remove connections for artists h1, h2, ... 
    82              
     82 
    8383        Use clearall() to reset all connections. 
    8484        """ 
     
    9696        if self._haskey.artist in artists: 
    9797            self._haskey = Selection() 
    98          
     98 
    9999    def clearall(self): 
    100100        """ 
    101101        Clear connections to all artists. 
    102          
     102 
    103103        Use clear(h1,h2,...) to reset specific artists. 
    104104        """ 
     
    121121            for cid in self._connections: self.canvas.mpl_disconnect(cid) 
    122122        except: 
    123             print "Error disconnection canvas: %s" % sys.exc_value 
    124             pass 
     123            logging.error("Error disconnection canvas: %s" % sys.exc_value) 
    125124        self._connections = [] 
    126125 
     
    130129    def __call__(self, trigger, artist, action): 
    131130        """Register a callback for an artist to a particular trigger event. 
    132          
     131 
    133132        usage: 
    134133            self.connect(eventname,artist,action) 
    135      
     134 
    136135        where: 
    137136            eventname is a string 
     
    153152            key: key pressed when mouse is on the artist 
    154153            keyrelease: key released for the artist 
    155      
     154 
    156155        The event received by action has a number of attributes: 
    157156            name is the event name which was triggered 
     
    165164            details is a dictionary of artist specific details, such as the 
    166165                id(s) of the point that were clicked. 
    167                  
     166 
    168167        When receiving an event, first check the modifier state to be 
    169168        sure it applies.  E.g., the callback for 'press' might be: 
     
    203202        if action not in self.events: 
    204203            raise ValueError, "Trigger expects " + ", ".join(self.events) 
    205          
     204 
    206205        # Tag the event with modifiers 
    207206        for mod in ('alt', 'control', 'shift', 'meta'): 
     
    210209        setattr(ev, 'action', action) 
    211210        setattr(ev, 'prop', {}) 
    212          
     211 
    213212        # Fallback scheme.  If the event does not return false, pass to parent. 
    214213        processed = False 
     
    249248                found.artist, found.prop = artist, prop 
    250249                break 
    251          
     250 
    252251        # TODO: how to check if prop is equal? 
    253252        if found != self._current: 
     
    257256 
    258257        return found 
    259          
     258 
    260259    def _onMotion(self, event): 
    261260        """ 
     
    263262        other artists are invisible. 
    264263        """ 
    265         ## Can't kill double-click on motion since Windows produces 
    266         ## spurious motion events. 
    267         #self._last_button = None 
    268          
     264        # # Can't kill double-click on motion since Windows produces 
     265        # # spurious motion events. 
     266        # self._last_button = None 
     267 
    269268        # Dibs on the motion event for the clicked artist 
    270269        if self._hasclick: 
    271270            # Make sure the x,y data use the coordinate system of the 
    272271            # artist rather than the default axes coordinates. 
    273              
     272 
    274273            transform = self._hasclick.artist.get_transform() 
    275             #x,y = event.xdata,event.ydata 
     274            # x,y = event.xdata,event.ydata 
    276275            x, y = event.x, event.y 
    277276            try: 
     
    279278                    x, y = transform.inverted().transform((x, y)) 
    280279                else: 
    281                     ## For interactive plottable apply transform is not working 
    282                     ## don't know why maybe marker definition 
    283                     ##transform ="CompositeGenericTransform" crash 
     280                    # # For interactive plottable apply transform is not working 
     281                    # # don't know why maybe marker definition 
     282                    # #transform ="CompositeGenericTransform" crash 
    284283                    pass 
    285284            except: 
    286                 ## CRUFT matplotlib-0.91 support 
    287                 ## exception for transform ="CompositeGenericTransform" 
    288                 ## crashes also here 
     285                # # CRUFT matplotlib-0.91 support 
     286                # # exception for transform ="CompositeGenericTransform" 
     287                # # crashes also here 
    289288                x, y = transform.inverse_xy_tup((x, y)) 
    290289 
    291             #event.xdata, event.ydata = x, y 
     290            # event.xdata, event.ydata = x, y 
    292291            self.trigger(self._hasclick, 'drag', event) 
    293292        else: 
     
    300299        """ 
    301300        import time 
    302          
     301 
    303302        # Check for double-click 
    304303        event_time = time.time() 
     
    310309        self._last_button = event.button 
    311310        self._last_time = event_time 
    312          
     311 
    313312        # If an artist is already dragging, feed any additional button 
    314313        # presses to that artist. 
     
    320319        else: 
    321320            found = self._find_current(event) 
    322         #print "button %d pressed"%event.button 
     321        # print "button %d pressed"%event.button 
    323322        # Note: it seems like if "click" returns False then hasclick should 
    324323        # not be set.  The problem is that there are two reasons it can 
     
    355354        self.trigger(self._hasclick, 'release', event) 
    356355        self._hasclick = Selection() 
    357              
     356 
    358357    def _onKey(self, event): 
    359358        """ 
     
    377376        self.trigger(found, 'key', event) 
    378377        self._haskey = found 
    379      
     378 
    380379    def _onKeyRelease(self, event): 
    381380        """ 
     
    385384            setattr(self, event.key, False) 
    386385            return 
    387          
     386 
    388387        if self._haskey: 
    389388            self.trigger(self._haskey, 'keyup', event) 
  • src/sas/plottools/canvas.py

    r79492222 r2df0b74  
    55import wx 
    66import sys 
     7import logging 
    78from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg 
    8 from matplotlib.backends.backend_wxagg import _convert_agg_to_wx_bitmap 
    9 from matplotlib.backends.backend_agg import FigureCanvasAgg 
    109from matplotlib.backend_bases import MouseEvent, RendererBase 
    1110from matplotlib.backends.backend_wx import GraphicsContextWx, PrintoutWx 
     
    4847    dc = self.GetDC() 
    4948    try: 
    50         (ppw, pph) = self.GetPPIPrinter()      # printer's pixels per in 
     49        (ppw, pph) = self.GetPPIPrinter()  # printer's pixels per in 
    5150    except: 
    5251        ppw = 1 
    5352        pph = 1 
    54     (pgw, pgh) = self.GetPageSizePixels()  # page size in pixels 
    55     (dcw, dch) = dc.GetSize() 
    56     (grw, grh) = self.canvas.GetSizeTuple() 
     53    (pgw, _) = self.GetPageSizePixels()  # page size in pixels 
     54    (dcw, _) = dc.GetSize() 
     55    (grw, _) = self.canvas.GetSizeTuple() 
    5756 
    5857    # save current figure dpi resolution and bg color, 
     
    7877    page_scale = 1.0 
    7978    if self.IsPreview(): 
    80         page_scale = float(dcw)/pgw 
     79        page_scale = float(dcw) / pgw 
    8180 
    8281    # get margin in pixels = (margin in in) * (pixels/in) 
     
    9796            dc.DrawBitmap(self.canvas.bitmap, (0, 0)) 
    9897        except: 
    99             pass 
     98            logging.error(sys.exc_value) 
    10099 
    101100    # restore original figure  resolution 
    102101    self.canvas.figure.set_facecolor(bgcolor) 
    103     ## used to be self.canvas.figure.dpi.set( fig_dpi) 
     102    # # used to be self.canvas.figure.dpi.set( fig_dpi) 
    104103    self.canvas.figure.dpi = fig_dpi 
    105104    self.canvas.draw() 
     
    121120        super(FigureCanvas, self).__init__(*args, **kw) 
    122121        self._isRendered = False 
    123          
     122 
    124123        # Create an timer for handling draw_idle requests 
    125124        # If there are events pending when the timer is 
     
    136135        # Support for mouse wheel 
    137136        self.Bind(wx.EVT_MOUSEWHEEL, self._onMouseWheel) 
    138         
     137 
    139138    def set_panel(self, panel): 
    140139        """ 
     
    146145        self.xaxis = panel.subplot.xaxis 
    147146        self.yaxis = panel.subplot.yaxis 
    148          
     147 
    149148    def draw_idle(self, *args, **kwargs): 
    150149        """ 
     
    165164            self.draw(*args, **kwargs) 
    166165            self.resizing = False 
    167              
     166 
    168167    def _get_axes_switch(self): 
    169168        """ 
     
    184183        # set the resizing back to default= False 
    185184        self.set_resizing(False) 
    186          
     185 
    187186    def set_resizing(self, resizing=False): 
    188187        """ 
     
    191190        self.resizing = resizing 
    192191        self.panel.set_resizing(False) 
    193               
     192 
    194193    def draw(self, drawDC=None): 
    195194        """ 
     
    203202            self._isRendered = True 
    204203            self._get_axes_switch() 
    205             #import time 
    206             #st = time.time() 
     204            # import time 
     205            # st = time.time() 
    207206            try: 
    208207                fig.draw(self) 
    209208            except ValueError: 
    210                 pass 
    211             #self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None) 
    212             #self.gui_repaint(drawDC=drawDC) 
    213             #print "time", time.time() - st 
     209                logging.error(sys.exc_value) 
    214210        else: 
    215211            self._isRendered = False 
    216212        if self.ndraw <= 1: 
    217213            self.ndraw += 1 
    218          
     214 
    219215    def _onMouseWheel(self, evt): 
    220216        """Translate mouse wheel events into matplotlib events""" 
    221217        # Determine mouse location 
    222         w, h = self.figure.canvas.get_width_height() 
     218        _, h = self.figure.canvas.get_width_height() 
    223219        x = evt.GetX() 
    224220        y = h - evt.GetY() 
     
    228224        rotation = evt.GetWheelRotation() 
    229225        rate = evt.GetLinesPerAction() 
    230         #print "delta,rotation,rate",delta,rotation,rate 
     226        # print "delta,rotation,rate",delta,rotation,rate 
    231227        step = rate * float(rotation) / delta 
    232228 
     
    249245        if step != 0: 
    250246            self.panel.is_zoomed = True 
    251                 
     247 
    252248    def _onRightButtonDown(self, evt): 
    253249        """ 
    254250        Overload the right button down call back to avoid a problem 
    255251        with the context menu over matplotlib plots on linux. 
    256          
     252 
    257253        :TODO: Investigate what the root cause of the problem is. 
    258          
     254 
    259255        """ 
    260256        if sys.platform == 'linux2' or self.panel.dimension == 3: 
     
    271267    def _onLeave(self, evt): 
    272268        if self.HasCapture(): self.ReleaseMouse() 
    273         super(FigureCanvas,self)._onLeave(evt) 
     269        super(FigureCanvas, self)._onLeave(evt) 
  • src/sas/plottools/fitDialog.py

    rb9a5f0e r2df0b74  
    77import sys 
    88 
    9 #Linear fit panel size  
     9# Linear fit panel size 
    1010if sys.platform.count("win32") > 0: 
    1111    FONT_VARIANT = 0 
     
    1616    PNL_WIDTH = 500 
    1717    PNL_HEIGHT = 500 
    18 RG_ON = True     
    19      
     18RG_ON = True 
     19 
    2020def format_number(value, high=False): 
    2121    """ 
     
    2727        output = "NaN" 
    2828        return output.lstrip().rstrip() 
    29      
     29 
    3030    if high: 
    3131        output = "%-6.4g" % value 
    32          
     32 
    3333    else: 
    3434        output = "%-5.3g" % value 
     
    4242        Displays fitting parameters 
    4343        """ 
    44         wx.Dialog.__init__(self, parent, title=title,  
     44        wx.Dialog.__init__(self, parent, title=title, 
    4545                           size=(PNL_WIDTH, 350)) 
    4646        self.parent = parent 
    4747        self.transform = transform 
    48         #Font 
     48        # Font 
    4949        self.SetWindowVariant(variant=FONT_VARIANT) 
    5050        # Registered owner for close event 
    5151        self._registered_close = None 
    52          
    53         #dialog panel self call function to plot the fitting function 
     52 
     53        # dialog panel self call function to plot the fitting function 
    5454        self.push_data = push_data 
    55         #dialog self plottable 
     55        # dialog self plottable 
    5656        self.plottable = plottable 
    5757        self.rg_on = False 
    5858        # Receive transformations of x and y 
    59         self.xLabel, self.yLabel, self.Avalue, self.Bvalue,\ 
     59        self.xLabel, self.yLabel, self.Avalue, self.Bvalue, \ 
    6060               self.ErrAvalue, self.ErrBvalue, self.Chivalue = self.transform() 
    61          
    62         #Dialog interface 
    63         vbox  = wx.BoxSizer(wx.VERTICAL) 
     61 
     62        # Dialog interface 
     63        vbox = wx.BoxSizer(wx.VERTICAL) 
    6464        sizer = wx.GridBagSizer(5, 5) 
    6565        _BOX_WIDTH = 100 
    66   
    67         self.tcA      = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 
     66 
     67        self.tcA = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 
    6868        self.tcA.SetToolTipString("Fit value for the slope parameter.") 
    69         self.tcErrA   = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 
     69        self.tcErrA = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 
    7070        self.tcErrA.SetToolTipString("Error on the slope parameter.") 
    71         self.tcB      = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 
     71        self.tcB = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 
    7272        self.tcA.SetToolTipString("Fit value for the constant parameter.") 
    73         self.tcErrB   = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 
     73        self.tcErrB = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 
    7474        self.tcErrB.SetToolTipString("Error on the constant parameter.") 
    75         self.tcChi    = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 
     75        self.tcChi = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 
    7676        self.tcChi.SetToolTipString("Chi^2 over degrees of freedom.") 
    77         self.xminFit  = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 
     77        self.xminFit = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 
    7878        msg = "Enter the minimum value on " 
    7979        msg += "the x-axis to be included in the fit." 
    8080        self.xminFit.SetToolTipString(msg) 
    81         self.xmaxFit  = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 
     81        self.xmaxFit = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 
    8282        msg = "Enter the maximum value on " 
    8383        msg += " the x-axis to be included in the fit." 
     
    9191 
    9292        # Make the info box not editable 
    93         #_BACKGROUND_COLOR = '#ffdf85' 
     93        # _BACKGROUND_COLOR = '#ffdf85' 
    9494        _BACKGROUND_COLOR = self.GetBackgroundColour() 
    9595        self.initXmin.SetEditable(False) 
     
    9797        self.initXmax.SetEditable(False) 
    9898        self.initXmax.SetBackgroundColour(_BACKGROUND_COLOR) 
    99          
     99 
    100100        # Buttons on the bottom 
    101101        self.bg_on = False 
     
    104104        self.btFit.Bind(wx.EVT_BUTTON, self._onFit) 
    105105        self.btFit.SetToolTipString("Perform fit.") 
    106         self.btClose =wx.Button(self, wx.ID_CANCEL, 'Close') 
     106        self.btClose = wx.Button(self, wx.ID_CANCEL, 'Close') 
    107107        self.btClose.Bind(wx.EVT_BUTTON, self._on_close) 
    108108        if RG_ON: 
     
    122122        iy = 1 
    123123        sizer.Add(wx.StaticText(self, -1, explanation), (iy, ix), 
    124                  (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     124                  (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    125125        iy += 2 
    126126        sizer.Add(wx.StaticText(self, -1, param_a), (iy, ix), 
    127                  (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    128         ix += 1 
    129         sizer.Add(self.tcA,(iy, ix),(1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     127                  (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     128        ix += 1 
     129        sizer.Add(self.tcA, (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    130130        ix += 1 
    131131        sizer.Add(wx.StaticText(self, -1, '+/-'), 
    132                   (iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     132                  (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    133133        ix += 1 
    134134        sizer.Add(self.tcErrA, (iy, ix), (1, 1), 
    135                   wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     135                  wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    136136        iy += 1 
    137137        ix = 0 
    138         sizer.Add(wx.StaticText(self, -1, 'Parameter b'), (iy, ix),(1, 1), 
    139                    wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    140         ix += 1 
    141         sizer.Add(self.tcB, (iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     138        sizer.Add(wx.StaticText(self, -1, 'Parameter b'), (iy, ix), (1, 1), 
     139                  wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     140        ix += 1 
     141        sizer.Add(self.tcB, (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    142142        ix += 1 
    143143        sizer.Add(wx.StaticText(self, -1, '+/-'), (iy, ix), 
    144                   (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     144                  (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    145145        ix += 1 
    146146        sizer.Add(self.tcErrB, (iy, ix), (1, 1), 
    147                    wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     147                  wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    148148        iy += 1 
    149149        ix = 0 
    150150        sizer.Add(wx.StaticText(self, -1, 'Chi2/dof'), (iy, ix), (1, 1), 
    151                    wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    152         ix += 1 
    153         sizer.Add(self.tcChi, (iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    154  
    155          
    156         #sizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 
     151                  wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     152        ix += 1 
     153        sizer.Add(self.tcChi, (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    157154        iy += 2 
    158155        ix = 1 
    159156        sizer.Add(wx.StaticText(self, -1, 'Min'), (iy, ix), (1, 1), 
    160                    wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     157                  wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    161158        ix += 2 
    162159        sizer.Add(wx.StaticText(self, -1, 'Max'), (iy, ix), 
    163                   (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     160                  (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    164161 
    165162        iy += 1 
    166163        ix = 0 
    167164        sizer.Add(wx.StaticText(self, -1, 'Maximum range (linear scale)'), 
    168                   (iy, ix),(1,1), 
    169                    wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    170         ix += 1 
    171         sizer.Add(self.initXmin, (iy, ix), (1,1), 
    172                    wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     165                  (iy, ix), (1, 1), 
     166                  wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     167        ix += 1 
     168        sizer.Add(self.initXmin, (iy, ix), (1, 1), 
     169                  wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    173170        ix += 2 
    174         sizer.Add(self.initXmax, (iy, ix), (1,1),  
    175                   wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    176         
     171        sizer.Add(self.initXmax, (iy, ix), (1, 1), 
     172                  wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     173 
    177174        iy += 1 
    178175        ix = 0 
    179176        sizer.Add(wx.StaticText(self, -1, 'Fit range of ' + self.xLabel), 
    180177                  (iy, ix), (1, 1), 
    181                    wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     178                  wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    182179        ix += 1 
    183180        sizer.Add(self.xminFit, (iy, ix), (1, 1), 
    184                    wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     181                  wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    185182        ix += 2 
    186         sizer.Add(self.xmaxFit, (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     183        sizer.Add(self.xmaxFit, (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    187184        if self.rg_on: 
    188185            self.SetSize((PNL_WIDTH, PNL_HEIGHT)) 
     
    195192            self.I0err_tctr.SetBackgroundColour(_BACKGROUND_COLOR) 
    196193            Rg_stxt = wx.StaticText(self, -1, 'Rg [A]') 
    197             Rg_stxt.Show(self.yLabel == "ln(y)" ) 
     194            Rg_stxt.Show(self.yLabel == "ln(y)") 
    198195            self.Rg_tctr = wx.TextCtrl(self, -1, '') 
    199196            self.Rg_tctr.SetEditable(False) 
    200197            self.Rg_tctr.SetBackgroundColour(_BACKGROUND_COLOR) 
    201             self.Rg_tctr.Show(self.yLabel == "ln(y)" ) 
     198            self.Rg_tctr.Show(self.yLabel == "ln(y)") 
    202199            self.Rgerr_tctr = wx.TextCtrl(self, -1, '') 
    203200            self.Rgerr_tctr.SetEditable(False) 
    204201            self.Rgerr_tctr.SetBackgroundColour(_BACKGROUND_COLOR) 
    205             self.Rgerr_tctr.Show(self.yLabel == "ln(y)" ) 
     202            self.Rgerr_tctr.Show(self.yLabel == "ln(y)") 
    206203            self.Rgerr_pm = wx.StaticText(self, -1, '+/-') 
    207             self.Rgerr_pm.Show(self.yLabel == "ln(y)" ) 
     204            self.Rgerr_pm.Show(self.yLabel == "ln(y)") 
    208205            Diameter_stxt = wx.StaticText(self, -1, 'Rod Diameter [A]') 
    209206            Diameter_stxt.Show(self.yLabel == "ln(y*x)") 
     
    229226            iy += 2 
    230227            ix = 0 
    231             sizer.Add(I0_stxt, (iy, ix), (1,1), 
    232                                     wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    233             ix += 1 
    234             sizer.Add(self.I0_tctr, (iy, ix), (1,1), 
    235                                     wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     228            sizer.Add(I0_stxt, (iy, ix), (1, 1), 
     229                      wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     230            ix += 1 
     231            sizer.Add(self.I0_tctr, (iy, ix), (1, 1), 
     232                      wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    236233            ix += 1 
    237234            sizer.Add(wx.StaticText(self, -1, '+/-'), (iy, ix), 
    238                                     (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    239             ix += 1 
    240             sizer.Add(self.I0err_tctr, (iy, ix), (1,1),  
    241                                     wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    242              
     235                      (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     236            ix += 1 
     237            sizer.Add(self.I0err_tctr, (iy, ix), (1, 1), 
     238                      wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     239 
    243240            iy += 1 
    244241            ix = 0 
    245             sizer.Add(Rg_stxt, (iy, ix),(1,1), 
    246                                     wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    247             ix += 1 
    248             sizer.Add(self.Rg_tctr, (iy, ix), (1,1), 
    249                                     wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    250      
     242            sizer.Add(Rg_stxt, (iy, ix), (1, 1), 
     243                      wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     244            ix += 1 
     245            sizer.Add(self.Rg_tctr, (iy, ix), (1, 1), 
     246                      wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     247 
    251248            ix += 1 
    252249            sizer.Add(self.Rgerr_pm, (iy, ix), 
    253                                     (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    254             ix += 1 
    255             sizer.Add(self.Rgerr_tctr, (iy, ix), (1,1),  
    256                                     wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     250                      (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     251            ix += 1 
     252            sizer.Add(self.Rgerr_tctr, (iy, ix), (1, 1), 
     253                      wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    257254            iy += 1 
    258255            ix = 0 
    259             sizer.Add(Diameter_stxt, (iy, ix),(1,1), 
    260                                     wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    261             ix += 1 
    262             sizer.Add(self.Diameter_tctr, (iy, ix), (1,1), 
    263                                     wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    264      
     256            sizer.Add(Diameter_stxt, (iy, ix), (1, 1), 
     257                      wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     258            ix += 1 
     259            sizer.Add(self.Diameter_tctr, (iy, ix), (1, 1), 
     260                      wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     261 
    265262            ix += 1 
    266263            sizer.Add(self.Diameter_pm, (iy, ix), 
    267                                     (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    268             ix += 1 
    269             sizer.Add(self.Diametererr_tctr, (iy, ix), (1,1),  
    270                                     wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     264                      (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     265            ix += 1 
     266            sizer.Add(self.Diametererr_tctr, (iy, ix), (1, 1), 
     267                      wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    271268            iy += 1 
    272269            ix = 0 
    273             sizer.Add(RgQmin_stxt, (iy, ix),(1,1), 
    274                                     wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    275             ix += 1 
    276             sizer.Add(self.RgQmin_tctr, (iy, ix), (1,1), 
    277                                     wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     270            sizer.Add(RgQmin_stxt, (iy, ix), (1, 1), 
     271                      wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     272            ix += 1 
     273            sizer.Add(self.RgQmin_tctr, (iy, ix), (1, 1), 
     274                      wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    278275            iy += 1 
    279276            ix = 0 
    280             sizer.Add(RgQmax_stxt, (iy, ix),(1,1), 
    281                                     wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    282             ix += 1 
    283             sizer.Add(self.RgQmax_tctr, (iy, ix), (1,1), 
    284                                     wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    285              
     277            sizer.Add(RgQmax_stxt, (iy, ix), (1, 1), 
     278                      wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     279            ix += 1 
     280            sizer.Add(self.RgQmax_tctr, (iy, ix), (1, 1), 
     281                      wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     282 
    286283        iy += 1 
    287284        ix = 1 
    288          
     285 
    289286        vbox.Add(self.static_line_1, 0, wx.EXPAND, 0) 
    290287        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    291         sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    292         sizer_button.Add(self.btFit, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
     288        sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     289        sizer_button.Add(self.btFit, 0, wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
    293290        sizer_button.Add(self.btClose, 0, 
    294                           wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
    295         vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 
    296          
    297         sizer.Add(self.btFit, (iy, ix), (1,1), wx.LEFT|wx.ADJUST_MINSIZE, 0) 
    298         #panel.SetSizer(sizer) 
     291                         wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
     292        vbox.Add(sizer_button, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 10) 
     293 
     294        sizer.Add(self.btFit, (iy, ix), (1, 1), wx.LEFT | wx.ADJUST_MINSIZE, 0) 
     295        # panel.SetSizer(sizer) 
    299296        self.SetSizer(vbox) 
    300297        self.Centre() 
     
    302299        from LineModel import LineModel 
    303300        self.model = LineModel() 
    304         #Display the fittings values 
     301        # Display the fittings values 
    305302        self.default_A = self.model.getParam('A') 
    306303        self.default_B = self.model.getParam('B') 
    307304        self.cstA = fittings.Parameter(self.model, 'A', self.default_A) 
    308305        self.cstB = fittings.Parameter(self.model, 'B', self.default_B) 
    309          
     306 
    310307        # Set default value of parameter in fit dialog 
    311308        if self.Avalue == None: 
     
    330327            self.tcChi.SetLabel(format_number(self.Chivalue)) 
    331328        if self.plottable.x != []: 
    332             #store the values of View in self.x,self.y,self.dx,self.dy 
     329            # store the values of View in self.x,self.y,self.dx,self.dy 
    333330            self.x, self.y, self.dx, \ 
    334331                     self.dy = self.plottable.returnValuesOfView() 
     
    348345            self.xminFit.SetValue(format_number(self.mini)) 
    349346            self.xmaxFit.SetValue(format_number(self.maxi)) 
    350      
     347 
    351348    def register_close(self, owner): 
    352349        """ 
     
    354351        window that needs notification when the dialog 
    355352        is closed 
    356          
     353 
    357354        :param owner: parent window 
    358          
     355 
    359356        """ 
    360357        self._registered_close = owner 
    361          
     358 
    362359    def _on_close(self, event): 
    363360        """ 
     
    368365        if self._registered_close is not None: 
    369366            self._registered_close() 
    370          
     367 
    371368    def _onFit(self, event): 
    372369        """ 
     
    379376        tempy = [] 
    380377        tempdy = [] 
    381              
     378 
    382379        # Check if View contains a x array .we online fit when x exits 
    383380        # makes transformation for y as a line to fit 
    384381        if self.x != []: 
    385             if(self.checkFitValues(self.xminFit) == True): 
    386                 #Check if the field of Fit Dialog contain values 
     382            if self.checkFitValues(self.xminFit) == True: 
     383                # Check if the field of Fit Dialog contain values 
    387384                # and use the x max and min of the user 
    388                 #xminView,xmaxView = self._checkVal(self.xminFit.GetValue(), 
    389                 #self.xmaxFit.GetValue()) 
    390385                if not self._checkVal(self.xminFit, self.xmaxFit): 
    391386                    return 
    392387                xminView = float(self.xminFit.GetValue()) 
    393388                xmaxView = float(self.xmaxFit.GetValue()) 
    394                 #xmin = self.floatInvTransform(xminView) 
    395                 #xmax = self.floatInvTransform(xmaxView) 
    396389                xmin = xminView 
    397390                xmax = xmaxView 
     
    399392                # in variables  before the fit 
    400393                if self.yLabel.lower() == "log10(y)": 
    401                     if (self.xLabel.lower() == "log10(x)"): 
     394                    if self.xLabel.lower() == "log10(x)": 
    402395                        for i in range(len(self.x)): 
    403396                            if self.x[i] >= math.log10(xmin): 
    404397                                tempy.append(math.log10(self.y[i])) 
    405                                 tempdy.append(transform.errToLogX(self.y[i], 
    406                                                         0, self.dy[i], 0)) 
     398                                tempdy.append(transform.errToLogX(self.y[i], 0, self.dy[i], 0)) 
    407399                    else: 
    408400                        for i in range(len(self.y)): 
    409401                            tempy.append(math.log10(self.y[i])) 
    410                             tempdy.append(transform.errToLogX(self.y[i], 
    411                                                             0, self.dy[i], 0)) 
     402                            tempdy.append(transform.errToLogX(self.y[i], 0, self.dy[i], 0)) 
    412403                else: 
    413404                    tempy = self.y 
    414405                    tempdy = self.dy 
    415                 
    416                 if (self.xLabel.lower() == "log10(x)"): 
     406 
     407                if self.xLabel.lower() == "log10(x)": 
    417408                    for x_i in self.x: 
    418409                        if x_i >= math.log10(xmin): 
     
    420411                else: 
    421412                    tempx = self.x 
    422                
    423                 #Find the fitting parameters 
     413 
     414                # Find the fitting parameters 
    424415                # Always use the same defaults, so that fit history 
    425                 #doesn't play a role! 
     416                # doesn't play a role! 
    426417                self.cstA = fittings.Parameter(self.model, 'A', self.default_A) 
    427418                self.cstB = fittings.Parameter(self.model, 'B', self.default_B) 
    428                  
    429                 if (self.xLabel.lower() == "log10(x)"): 
     419 
     420                if self.xLabel.lower() == "log10(x)": 
    430421                    tempdy = numpy.asarray(tempdy) 
    431422                    tempdy[tempdy == 0] = 1 
    432423                    chisqr, out, cov = fittings.sasfit(self.model, 
    433                                                         [self.cstA, self.cstB], 
    434                                                         tempx, tempy, 
    435                                                         tempdy, 
    436                                                         math.log10(xmin), 
    437                                                         math.log10(xmax)) 
     424                                                       [self.cstA, self.cstB], 
     425                                                       tempx, tempy, 
     426                                                       tempdy, 
     427                                                       math.log10(xmin), 
     428                                                       math.log10(xmax)) 
    438429                else: 
    439430                    tempdy = numpy.asarray(tempdy) 
    440431                    tempdy[tempdy == 0] = 1 
    441432                    chisqr, out, cov = fittings.sasfit(self.model, 
    442                                                         [self.cstA, self.cstB], 
    443                                                         tempx, tempy, tempdy, 
    444                                                         xminView, xmaxView) 
     433                                                       [self.cstA, self.cstB], 
     434                                                       tempx, tempy, tempdy, 
     435                                                       xminView, xmaxView) 
    445436                # Use chi2/dof 
    446437                if len(tempx) > 0: 
    447                     chisqr = chisqr/len(tempx) 
    448                  
    449                 #Check that cov and out are iterable before displaying them 
     438                    chisqr = chisqr / len(tempx) 
     439 
     440                # Check that cov and out are iterable before displaying them 
    450441                if cov == None: 
    451442                    errA = 0.0 
     
    463454                self.model.setParam('A', float(cstA)) 
    464455                self.model.setParam('B', float(cstB)) 
    465                  
     456 
    466457                tempx = [] 
    467458                tempy = [] 
    468459                y_model = 0.0 
    469460                # load tempy with the minimum transformation 
    470                 
     461 
    471462                if self.xLabel == "log10(x)": 
    472463                    y_model = self.model.run(math.log10(xmin)) 
     
    475466                    y_model = self.model.run(xminView) 
    476467                    tempx.append(xminView) 
    477                      
     468 
    478469                if self.yLabel == "log10(y)": 
    479470                    tempy.append(math.pow(10, y_model)) 
    480471                else: 
    481472                    tempy.append(y_model) 
    482                      
     473 
    483474                # load tempy with the maximum transformation 
    484475                if self.xLabel == "log10(x)": 
     
    488479                    y_model = self.model.run(xmaxView) 
    489480                    tempx.append(xmaxView) 
    490                      
     481 
    491482                if self.yLabel == "log10(y)": 
    492483                    tempy.append(math.pow(10, y_model)) 
    493484                else: 
    494485                    tempy.append(y_model) 
    495                 #Set the fit parameter display when  FitDialog is opened again 
     486                # Set the fit parameter display when  FitDialog is opened again 
    496487                self.Avalue = cstB 
    497488                self.Bvalue = cstA 
     
    501492                self.push_data(tempx, tempy, xminView, xmaxView, 
    502493                               xmin, xmax, self._ongetValues()) 
    503                  
     494 
    504495                # Display the fitting value on the Fit Dialog 
    505496                self._onsetValues(cstB, cstA, errA, errB, chisqr) 
    506                 
     497 
    507498    def _onsetValues(self, cstA, cstB, errA, errB, Chi): 
    508499        """ 
     
    527518                    value = format_number(3 * float(cstA) / (2 * rg)) 
    528519                else: 
    529                     value ='' 
     520                    value = '' 
    530521                self.Rgerr_tctr.SetValue(value) 
    531522                if self.I0err_tctr.IsShown(): 
     
    540531                    value = format_number(8 * float(cstA) / rg) 
    541532                else: 
    542                     value ='' 
     533                    value = '' 
    543534                self.Diametererr_tctr.SetValue(value) 
    544535            if self.RgQmin_tctr.IsShown(): 
     
    548539                value = format_number(rg * self.maxi) 
    549540                self.RgQmax_tctr.SetValue(value) 
    550                  
     541 
    551542    def _ongetValues(self): 
    552543        """ 
     
    555546        return self.Avalue, self.Bvalue, self.ErrAvalue, \ 
    556547                            self.ErrBvalue, self.Chivalue 
    557      
     548 
    558549    def _checkVal(self, usermin, usermax): 
    559550        """ 
     
    579570            usermin.SetBackgroundColour("pink") 
    580571            usermin.Refresh() 
    581        
     572 
    582573        return flag 
    583              
     574 
    584575    def floatForwardTransform(self, x): 
    585576        """ 
    586577        transform a float. 
    587578        """ 
    588         #TODO: refactor this with proper object-oriented design 
     579        # TODO: refactor this with proper object-oriented design 
    589580        # This code stinks. 
    590         if(self.xLabel == "x"): 
     581        if self.xLabel == "x": 
    591582            return transform.toX(x) 
    592         if(self.xLabel == "x^(2)"): 
     583        if self.xLabel == "x^(2)": 
    593584            return transform.toX2(x) 
    594         if(self.xLabel == "ln(x)"): 
     585        if self.xLabel == "ln(x)": 
    595586            return transform.toLogX(x) 
    596         if(self.xLabel == "log10(x)"): 
     587        if self.xLabel == "log10(x)": 
    597588            return math.log10(x) 
    598                      
     589 
    599590    def floatTransform(self, x): 
    600591        """ 
     
    603594        not in x 
    604595        """ 
    605         #TODO: refactor this with proper object-oriented design 
     596        # TODO: refactor this with proper object-oriented design 
    606597        # This code stinks. 
    607         if(self.xLabel == "x"): 
     598        if self.xLabel == "x": 
    608599            return transform.toX(x) 
    609         if(self.xLabel == "x^(2)"): 
     600        if self.xLabel == "x^(2)": 
    610601            return transform.toX2(x) 
    611         if(self.xLabel == "ln(x)"): 
     602        if self.xLabel == "ln(x)": 
    612603            return transform.toLogX(x) 
    613         if(self.xLabel == "log10(x)"): 
     604        if self.xLabel == "log10(x)": 
    614605            if x > 0: 
    615606                return x 
    616607            else: 
    617608                raise ValueError, "cannot compute log of a negative number" 
    618              
     609 
    619610    def floatInvTransform(self, x): 
    620611        """ 
    621612        transform a float.It is use to determine the x.View min and x.View 
    622613        max for values not in x 
    623          
    624         """ 
    625         #TODO: refactor this. This is just a hack to make the 
     614 
     615        """ 
     616        # TODO: refactor this. This is just a hack to make the 
    626617        # functionality work without rewritting the whole code 
    627618        # with good design (which really should be done...). 
    628         if(self.xLabel == "x^(2)"): 
     619        if self.xLabel == "x^(2)": 
    629620            return math.sqrt(x) 
    630          
    631         elif(self.xLabel == "log10(x)"): 
     621        elif self.xLabel == "log10(x)": 
    632622            return math.pow(10, x) 
    633          
    634         elif(self.xLabel == "ln(x)"): 
     623        elif self.xLabel == "ln(x)": 
    635624            return math.exp(x) 
    636625        return x 
    637              
     626 
    638627    def checkFitValues(self, item): 
    639628        """ 
     
    643632        value = item.GetValue() 
    644633        # Check for possible values entered 
    645         if (self.xLabel == "log10(x)"):  #or self.xLabel=="ln(x)"): 
    646             if(float(value) > 0): 
     634        if self.xLabel == "log10(x)": 
     635            if float(value) > 0: 
    647636                item.SetBackgroundColour(wx.WHITE) 
    648637                item.Refresh() 
     
    652641                item.Refresh() 
    653642        return flag 
    654         
     643 
    655644    def setFitRange(self, xmin, xmax, xminTrans, xmaxTrans): 
    656645        """ 
     
    659648        self.xminFit.SetValue(format_number(xmin)) 
    660649        self.xmaxFit.SetValue(format_number(xmax)) 
    661          
     650 
    662651    def set_fit_region(self, xmin, xmax): 
    663652        """ 
     
    675664        self.xminFit.SetValue(format_number(xmin)) 
    676665        self.xmaxFit.SetValue(format_number(xmax)) 
    677    
    678    
     666 
     667 
    679668class MyApp(wx.App): 
    680669    """ 
     670        Test application 
    681671    """ 
    682672    def OnInit(self): 
    683673        """ 
     674            Test application initialization 
    684675        """ 
    685676        wx.InitAllImageHandlers() 
     
    688679                           push_data=self.onFitDisplay, 
    689680                           transform=self.returnTrans, 
    690                             title='Linear Fit') 
     681                           title='Linear Fit') 
    691682        if dialog.ShowModal() == wx.ID_OK: 
    692683            pass 
    693684        dialog.Destroy() 
    694685        return 1 
    695      
     686 
    696687    def onFitDisplay(self, tempx, tempy, xminView, xmaxView, xmin, xmax, func): 
    697688        """ 
     689            Test application dummy method 
    698690        """ 
    699691        pass 
    700          
     692 
    701693    def returnTrans(self): 
    702694        """ 
     695            Test application dummy method 
    703696        """ 
    704697        return '', '', 0, 0, 0, 0, 0 
  • src/sas/plottools/fittings.py

    rb9a5f0e r2df0b74  
    44 
    55 
    6 class Parameter: 
     6class Parameter(object): 
    77    """ 
    88    Class to handle model parameters 
    99    """ 
    1010    def __init__(self, model, name, value=None): 
    11             self.model = model 
    12             self.name = name 
    13             if not value == None: 
    14                 self.model.setParam(self.name, value) 
    15             
     11        self.model = model 
     12        self.name = name 
     13        if not value == None: 
     14            self.model.setParam(self.name, value) 
     15 
    1616    def set(self, value): 
    1717        """ 
     
    2525        """ 
    2626        return self.model.getParam(self.name) 
    27      
    28      
    29 def sasfit(model, pars, x, y, err_y , qmin=None, qmax=None): 
     27 
     28 
     29def sasfit(model, pars, x, y, err_y, qmin=None, qmax=None): 
    3030    """ 
    3131    Fit function 
    32      
     32 
    3333    :param model: sas model object 
    3434    :param pars: list of parameters 
     
    4141        Calculates the vector of residuals for each point 
    4242        in y for a given set of input parameters. 
    43          
     43 
    4444        :param params: list of parameter values 
    4545        :return: vector of residuals 
     
    4949            p.set(params[i]) 
    5050            i += 1 
    51          
     51 
    5252        residuals = [] 
    5353        for j in range(len(x)): 
     
    5555                residuals.append((y[j] - model.runXY(x[j])) / err_y[j]) 
    5656        return residuals 
    57          
     57 
    5858    def chi2(params): 
    5959        """ 
    6060        Calculates chi^2 
    61          
     61 
    6262        :param params: list of parameter values 
    63          
     63 
    6464        :return: chi^2 
    65          
     65 
    6666        """ 
    6767        sum = 0 
     
    7070            sum += item * item 
    7171        return sum 
    72          
     72 
    7373    p = [param() for param in pars] 
    7474    out, cov_x, info, mesg, success = optimize.leastsq(f, p, full_output=1) 
     
    7878    elif len(pars) == 1: 
    7979        chisqr = chi2([out]) 
    80          
     80 
    8181    return chisqr, out, cov_x 
    8282 
    8383 
    8484def calcCommandline(event): 
    85     #Testing implementation 
     85    # Testing implementation 
    8686    # Fit a Line model 
    8787    from LineModel import LineModel 
Note: See TracChangeset for help on using the changeset viewer.