Changeset 2df0b74 in sasview for src/sas/plottools
- Timestamp:
- Mar 5, 2015 11:17:05 AM (10 years ago)
- 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
- Location:
- src/sas/plottools
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/plottools/BaseInteractor.py
r79492222 r2df0b74 9 9 10 10 11 class _BaseInteractor :11 class _BaseInteractor(object): 12 12 """ 13 13 Share some functions between the interface interactor and various layer 14 14 interactors. 15 15 16 16 Individual interactors need the following functions: 17 17 18 18 save(ev) - save the current state for later restore 19 19 restore() - restore the old state … … 21 21 moveend(ev) - end the drag event 22 22 update() - draw the interactors 23 23 24 24 The following are provided by the base class: 25 25 26 26 connect_markers(markers) - register callbacks for all markers 27 27 clear_markers() - remove all items in self.markers … … 32 32 onDrag(ev) - mouse move: calls move() or restore() 33 33 onKey(ev) - keyboard move: calls move() or restore() 34 34 35 35 Interactor attributes: 36 36 37 37 base - model we are operating on 38 38 axes - axes holding the interactor 39 39 color - color of the interactor in non-active state 40 40 markers - list of handles for the interactor 41 41 42 42 """ 43 43 def __init__(self, base, axes, color='black'): … … 48 48 self.color = color 49 49 self.markers = [] 50 50 51 51 def clear_markers(self): 52 52 ''' … … 63 63 """ 64 64 pass 65 65 66 66 def restore(self, ev): 67 67 """ 68 68 """ 69 69 pass 70 70 71 71 def move(self, x, y, ev): 72 72 """ 73 73 """ 74 74 pass 75 75 76 76 def moveend(self, ev): 77 77 """ … … 108 108 self.base.draw() 109 109 return True 110 110 111 111 def onClick(self, ev): 112 112 """ … … 137 137 self.base.update() 138 138 return True 139 139 140 140 def onKey(self, ev): 141 141 """ 142 142 Respond to keyboard events. Arrow keys move the widget. Escape 143 143 restores it to the position before the last click. 144 144 145 145 Calls move() to update the state. Calls restore() on escape. 146 146 """ … … 173 173 px, py = ax.transData.inverse_xy_tup((x, y)) 174 174 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)) 176 176 else: 177 nx, ny = ax.transData.xy_tup((px +1., py+1.))178 dx, dy = nx -x, ny-y177 nx, ny = ax.transData.xy_tup((px + 1., py + 1.)) 178 dx, dy = nx - x, ny - y 179 179 return dx, dy -
src/sas/plottools/LabelDialog.py
r79492222 r2df0b74 7 7 FONT_VARIANT = 1 8 8 PNL_WIDTH = 300 9 9 10 10 class LabelDialog(wx.Dialog): 11 11 def __init__(self, parent, id, title, label): 12 12 wx.Dialog.__init__(self, parent, id, title, size=(PNL_WIDTH, 150)) 13 13 14 #panel = wx.Panel(self, -1) 15 #Font 14 # Font 16 15 self.SetWindowVariant(variant=FONT_VARIANT) 17 16 mainbox = wx.BoxSizer(wx.VERTICAL) 18 17 vbox = wx.BoxSizer(wx.VERTICAL) 19 18 textbox = wx.BoxSizer(wx.HORIZONTAL) 20 19 21 20 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) 23 22 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) 28 27 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) 31 29 hbox = wx.BoxSizer(wx.HORIZONTAL) 32 ok Button = wx.Button(self,wx.ID_OK, 'OK', size=(70, 25))33 close Button = wx.Button(self,wx.ID_CANCEL, 'Cancel', size=(70, 25))34 35 hbox.Add(ok Button, 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) 36 34 hbox.Add((20, 20)) 37 hbox.Add(close Button, wx.LEFT, 10)35 hbox.Add(close_button, wx.LEFT, 10) 38 36 39 37 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) 43 40 self.SetSizer(mainbox) 44 41 45 42 def getText(self): 46 return self. myTxtCtrl.GetValue()43 return self.label_ctrl.GetValue() -
src/sas/plottools/LineModel.py
r79492222 r2df0b74 1 1 #!/usr/bin/env python 2 """ 3 Provide Line function (y= A + Bx) 2 """ 3 Provide Line function (y= A + Bx) 4 4 """ 5 5 … … 7 7 8 8 class LineModel(object): 9 """ 9 """ 10 10 Class that evaluates a linear model. 11 11 12 12 f(x) = A + Bx 13 13 14 14 List of default parameters: 15 15 A = 0.0 16 B = 0.0 16 B = 0.0 17 17 """ 18 18 19 19 def __init__(self): 20 20 """ Initialization """ 21 # # Name of the model21 # # Name of the model 22 22 self.name = "LineModel" 23 23 24 # # Define parameters24 # # Define parameters 25 25 self.params = {} 26 26 self.params['A'] = 1.0 27 27 self.params['B'] = 1.0 28 28 29 # # Parameter details [units, min, max]29 # # Parameter details [units, min, max] 30 30 self.details = {} 31 31 self.details['A'] = ['', None, None] 32 32 self.details['B'] = ['', None, None] 33 33 34 34 def getParam(self, name): 35 35 """ 36 Return parameter value 36 37 """ 37 38 return self.params[name.upper()] 38 39 39 40 def setParam(self, name, value): 40 41 """ 42 Set parameter value 41 43 """ 42 44 self.params[name.upper()] = value 43 45 44 46 def _line(self, x): 45 47 """ 46 48 Evaluate the function 47 49 48 50 :param x: x-value 49 51 50 52 :return: function value 51 53 52 54 """ 53 55 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 """ 57 59 Evaluate the model 58 60 59 61 :param x: simple value 60 62 61 63 :return: (Line value) 62 64 """ … … 65 67 self._line(x[0] * math.sin(x[1])) 66 68 elif x.__class__.__name__ == 'tuple': 67 msg 69 msg = "Tuples are not allowed as input to BaseComponent models" 68 70 raise ValueError, msg 69 71 else: 70 72 return self._line(x) 71 72 def runXY(self, x =0.0):73 """ 73 74 def runXY(self, x=0.0): 75 """ 74 76 Evaluate the model 75 77 76 78 :param x: simple value 77 79 78 80 :return: Line value 79 81 80 82 """ 81 83 if x.__class__.__name__ == 'list': … … 86 88 else: 87 89 return self._line(x) 88 89 90 if __name__ == "__main__":91 l = Line()92 -
src/sas/plottools/arrow3d.py
r79492222 r2df0b74 6 6 from mpl_toolkits.mplot3d import proj3d 7 7 import time 8 # from matplotlib.artist import allow_rasterization8 # from matplotlib.artist import allow_rasterization 9 9 class Arrow3D(FancyArrowPatch): 10 10 """ 11 11 Draw 3D arrow 12 12 """ 13 13 14 14 def __init__(self, base, xs, ys, zs, colors, *args, **kwargs): 15 15 """ 16 16 Init 17 17 18 18 :Params xs: [[x0, x0+dx0], [x1, x1+dx1], ...] 19 19 :Params ys: [[y0, y0+dy0], [y1, y1+dy1], ...] 20 20 :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], ...] 22 22 where R, G, B ranges (0,1) 23 23 """ 24 FancyArrowPatch.__init__(self, (0, 0), (0,0), *args, **kwargs)24 FancyArrowPatch.__init__(self, (0, 0), (0, 0), *args, **kwargs) 25 25 self.leftdown = False 26 26 self.t_click = 0 … … 28 28 self.colors = colors 29 29 self.base = base 30 30 31 31 if base != None: 32 32 # To turn the updating off during dragging 33 base.canvas.mpl_connect('button_press_event', self.on LeftDown)34 base.canvas.mpl_connect('button_release_event', self.on LeftUp)35 36 def on LeftDown(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): 37 37 """ 38 Mouse left-down event 38 39 """ 39 40 self.leftdown = True 40 41 self.t_click = time.time() 41 42 def on LeftUp(self, event):42 43 def on_left_up(self, event): 43 44 """ 45 Mouse left up event 44 46 """ 45 47 t_up = time.time() - self.t_click … … 48 50 self.leftdown = False 49 51 self.base.canvas.draw() 50 52 51 53 def draw(self, renderer, rasterized=True): 52 54 """ … … 58 60 xs3d, ys3d, zs3d = self._verts3d 59 61 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])) 63 64 self.set_color(self.colors[i]) 64 65 FancyArrowPatch.draw(self, renderer) 65 66 66 67 self.leftdown = False -
src/sas/plottools/binder.py
r79492222 r2df0b74 3 3 """ 4 4 import sys 5 6 7 class Selection :5 import logging 6 7 class Selection(object): 8 8 """ 9 9 Store and compare selections. … … 11 11 # TODO: We need some way to check in prop matches, preferably 12 12 # TODO: without imposing structure on prop. 13 13 14 14 artist = None 15 15 prop = {} 16 16 17 17 def __init__(self, artist=None, prop={}): 18 18 self.artist, self.prop = artist, self.prop 19 19 20 20 def __eq__(self, other): 21 21 return self.artist is other.artist 22 22 23 23 def __ne__(self, other): 24 24 return self.artist is not other.artist 25 25 26 26 def __nonzero__(self): 27 27 return self.artist is not None 28 28 29 29 30 class BindArtist :30 class BindArtist(object): 31 31 """ 32 32 """ … … 41 41 dclick_threshhold = 0.25 42 42 _last_button, _last_time = None, 0 43 43 44 44 # Mouse/keyboard events we can bind to 45 45 events = ['enter', 'leave', 'motion', 'click', 'dclick', 'drag', 'release', 46 'scroll', 'key', 'keyup']46 'scroll', 'key', 'keyup'] 47 47 # TODO: Need our own event structure 48 48 49 49 def __init__(self, figure): 50 50 canvas = figure.canvas … … 69 69 canvas.mpl_connect('key_release_event', self._onKeyRelease), 70 70 ] 71 71 72 72 self._current = None 73 73 self._actions = {} … … 75 75 self.figure = figure 76 76 self.clearall() 77 77 78 78 def clear(self, *artists): 79 79 """ 80 80 self.clear(h1,h2,...) 81 81 Remove connections for artists h1, h2, ... 82 82 83 83 Use clearall() to reset all connections. 84 84 """ … … 96 96 if self._haskey.artist in artists: 97 97 self._haskey = Selection() 98 98 99 99 def clearall(self): 100 100 """ 101 101 Clear connections to all artists. 102 102 103 103 Use clear(h1,h2,...) to reset specific artists. 104 104 """ … … 121 121 for cid in self._connections: self.canvas.mpl_disconnect(cid) 122 122 except: 123 print "Error disconnection canvas: %s" % sys.exc_value 124 pass 123 logging.error("Error disconnection canvas: %s" % sys.exc_value) 125 124 self._connections = [] 126 125 … … 130 129 def __call__(self, trigger, artist, action): 131 130 """Register a callback for an artist to a particular trigger event. 132 131 133 132 usage: 134 133 self.connect(eventname,artist,action) 135 134 136 135 where: 137 136 eventname is a string … … 153 152 key: key pressed when mouse is on the artist 154 153 keyrelease: key released for the artist 155 154 156 155 The event received by action has a number of attributes: 157 156 name is the event name which was triggered … … 165 164 details is a dictionary of artist specific details, such as the 166 165 id(s) of the point that were clicked. 167 166 168 167 When receiving an event, first check the modifier state to be 169 168 sure it applies. E.g., the callback for 'press' might be: … … 203 202 if action not in self.events: 204 203 raise ValueError, "Trigger expects " + ", ".join(self.events) 205 204 206 205 # Tag the event with modifiers 207 206 for mod in ('alt', 'control', 'shift', 'meta'): … … 210 209 setattr(ev, 'action', action) 211 210 setattr(ev, 'prop', {}) 212 211 213 212 # Fallback scheme. If the event does not return false, pass to parent. 214 213 processed = False … … 249 248 found.artist, found.prop = artist, prop 250 249 break 251 250 252 251 # TODO: how to check if prop is equal? 253 252 if found != self._current: … … 257 256 258 257 return found 259 258 260 259 def _onMotion(self, event): 261 260 """ … … 263 262 other artists are invisible. 264 263 """ 265 # # Can't kill double-click on motion since Windows produces266 # # spurious motion events.267 # self._last_button = None268 264 # # Can't kill double-click on motion since Windows produces 265 # # spurious motion events. 266 # self._last_button = None 267 269 268 # Dibs on the motion event for the clicked artist 270 269 if self._hasclick: 271 270 # Make sure the x,y data use the coordinate system of the 272 271 # artist rather than the default axes coordinates. 273 272 274 273 transform = self._hasclick.artist.get_transform() 275 # x,y = event.xdata,event.ydata274 # x,y = event.xdata,event.ydata 276 275 x, y = event.x, event.y 277 276 try: … … 279 278 x, y = transform.inverted().transform((x, y)) 280 279 else: 281 # # For interactive plottable apply transform is not working282 # # don't know why maybe marker definition283 # #transform ="CompositeGenericTransform" crash280 # # For interactive plottable apply transform is not working 281 # # don't know why maybe marker definition 282 # #transform ="CompositeGenericTransform" crash 284 283 pass 285 284 except: 286 # # CRUFT matplotlib-0.91 support287 # # exception for transform ="CompositeGenericTransform"288 # # crashes also here285 # # CRUFT matplotlib-0.91 support 286 # # exception for transform ="CompositeGenericTransform" 287 # # crashes also here 289 288 x, y = transform.inverse_xy_tup((x, y)) 290 289 291 # event.xdata, event.ydata = x, y290 # event.xdata, event.ydata = x, y 292 291 self.trigger(self._hasclick, 'drag', event) 293 292 else: … … 300 299 """ 301 300 import time 302 301 303 302 # Check for double-click 304 303 event_time = time.time() … … 310 309 self._last_button = event.button 311 310 self._last_time = event_time 312 311 313 312 # If an artist is already dragging, feed any additional button 314 313 # presses to that artist. … … 320 319 else: 321 320 found = self._find_current(event) 322 # print "button %d pressed"%event.button321 # print "button %d pressed"%event.button 323 322 # Note: it seems like if "click" returns False then hasclick should 324 323 # not be set. The problem is that there are two reasons it can … … 355 354 self.trigger(self._hasclick, 'release', event) 356 355 self._hasclick = Selection() 357 356 358 357 def _onKey(self, event): 359 358 """ … … 377 376 self.trigger(found, 'key', event) 378 377 self._haskey = found 379 378 380 379 def _onKeyRelease(self, event): 381 380 """ … … 385 384 setattr(self, event.key, False) 386 385 return 387 386 388 387 if self._haskey: 389 388 self.trigger(self._haskey, 'keyup', event) -
src/sas/plottools/canvas.py
r79492222 r2df0b74 5 5 import wx 6 6 import sys 7 import logging 7 8 from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg 8 from matplotlib.backends.backend_wxagg import _convert_agg_to_wx_bitmap9 from matplotlib.backends.backend_agg import FigureCanvasAgg10 9 from matplotlib.backend_bases import MouseEvent, RendererBase 11 10 from matplotlib.backends.backend_wx import GraphicsContextWx, PrintoutWx … … 48 47 dc = self.GetDC() 49 48 try: 50 (ppw, pph) = self.GetPPIPrinter() 49 (ppw, pph) = self.GetPPIPrinter() # printer's pixels per in 51 50 except: 52 51 ppw = 1 53 52 pph = 1 54 (pgw, pgh) = self.GetPageSizePixels() # page size in pixels55 (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() 57 56 58 57 # save current figure dpi resolution and bg color, … … 78 77 page_scale = 1.0 79 78 if self.IsPreview(): 80 page_scale = float(dcw) /pgw79 page_scale = float(dcw) / pgw 81 80 82 81 # get margin in pixels = (margin in in) * (pixels/in) … … 97 96 dc.DrawBitmap(self.canvas.bitmap, (0, 0)) 98 97 except: 99 pass98 logging.error(sys.exc_value) 100 99 101 100 # restore original figure resolution 102 101 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) 104 103 self.canvas.figure.dpi = fig_dpi 105 104 self.canvas.draw() … … 121 120 super(FigureCanvas, self).__init__(*args, **kw) 122 121 self._isRendered = False 123 122 124 123 # Create an timer for handling draw_idle requests 125 124 # If there are events pending when the timer is … … 136 135 # Support for mouse wheel 137 136 self.Bind(wx.EVT_MOUSEWHEEL, self._onMouseWheel) 138 137 139 138 def set_panel(self, panel): 140 139 """ … … 146 145 self.xaxis = panel.subplot.xaxis 147 146 self.yaxis = panel.subplot.yaxis 148 147 149 148 def draw_idle(self, *args, **kwargs): 150 149 """ … … 165 164 self.draw(*args, **kwargs) 166 165 self.resizing = False 167 166 168 167 def _get_axes_switch(self): 169 168 """ … … 184 183 # set the resizing back to default= False 185 184 self.set_resizing(False) 186 185 187 186 def set_resizing(self, resizing=False): 188 187 """ … … 191 190 self.resizing = resizing 192 191 self.panel.set_resizing(False) 193 192 194 193 def draw(self, drawDC=None): 195 194 """ … … 203 202 self._isRendered = True 204 203 self._get_axes_switch() 205 # import time206 # st = time.time()204 # import time 205 # st = time.time() 207 206 try: 208 207 fig.draw(self) 209 208 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) 214 210 else: 215 211 self._isRendered = False 216 212 if self.ndraw <= 1: 217 213 self.ndraw += 1 218 214 219 215 def _onMouseWheel(self, evt): 220 216 """Translate mouse wheel events into matplotlib events""" 221 217 # Determine mouse location 222 w, h = self.figure.canvas.get_width_height()218 _, h = self.figure.canvas.get_width_height() 223 219 x = evt.GetX() 224 220 y = h - evt.GetY() … … 228 224 rotation = evt.GetWheelRotation() 229 225 rate = evt.GetLinesPerAction() 230 # print "delta,rotation,rate",delta,rotation,rate226 # print "delta,rotation,rate",delta,rotation,rate 231 227 step = rate * float(rotation) / delta 232 228 … … 249 245 if step != 0: 250 246 self.panel.is_zoomed = True 251 247 252 248 def _onRightButtonDown(self, evt): 253 249 """ 254 250 Overload the right button down call back to avoid a problem 255 251 with the context menu over matplotlib plots on linux. 256 252 257 253 :TODO: Investigate what the root cause of the problem is. 258 254 259 255 """ 260 256 if sys.platform == 'linux2' or self.panel.dimension == 3: … … 271 267 def _onLeave(self, evt): 272 268 if self.HasCapture(): self.ReleaseMouse() 273 super(FigureCanvas, self)._onLeave(evt)269 super(FigureCanvas, self)._onLeave(evt) -
src/sas/plottools/fitDialog.py
rb9a5f0e r2df0b74 7 7 import sys 8 8 9 # Linear fit panel size9 # Linear fit panel size 10 10 if sys.platform.count("win32") > 0: 11 11 FONT_VARIANT = 0 … … 16 16 PNL_WIDTH = 500 17 17 PNL_HEIGHT = 500 18 RG_ON = True 19 18 RG_ON = True 19 20 20 def format_number(value, high=False): 21 21 """ … … 27 27 output = "NaN" 28 28 return output.lstrip().rstrip() 29 29 30 30 if high: 31 31 output = "%-6.4g" % value 32 32 33 33 else: 34 34 output = "%-5.3g" % value … … 42 42 Displays fitting parameters 43 43 """ 44 wx.Dialog.__init__(self, parent, title=title, 44 wx.Dialog.__init__(self, parent, title=title, 45 45 size=(PNL_WIDTH, 350)) 46 46 self.parent = parent 47 47 self.transform = transform 48 # Font48 # Font 49 49 self.SetWindowVariant(variant=FONT_VARIANT) 50 50 # Registered owner for close event 51 51 self._registered_close = None 52 53 # dialog panel self call function to plot the fitting function52 53 # dialog panel self call function to plot the fitting function 54 54 self.push_data = push_data 55 # dialog self plottable55 # dialog self plottable 56 56 self.plottable = plottable 57 57 self.rg_on = False 58 58 # Receive transformations of x and y 59 self.xLabel, self.yLabel, self.Avalue, self.Bvalue, \59 self.xLabel, self.yLabel, self.Avalue, self.Bvalue, \ 60 60 self.ErrAvalue, self.ErrBvalue, self.Chivalue = self.transform() 61 62 # Dialog interface63 vbox 61 62 # Dialog interface 63 vbox = wx.BoxSizer(wx.VERTICAL) 64 64 sizer = wx.GridBagSizer(5, 5) 65 65 _BOX_WIDTH = 100 66 67 self.tcA 66 67 self.tcA = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 68 68 self.tcA.SetToolTipString("Fit value for the slope parameter.") 69 self.tcErrA 69 self.tcErrA = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 70 70 self.tcErrA.SetToolTipString("Error on the slope parameter.") 71 self.tcB 71 self.tcB = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 72 72 self.tcA.SetToolTipString("Fit value for the constant parameter.") 73 self.tcErrB 73 self.tcErrB = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 74 74 self.tcErrB.SetToolTipString("Error on the constant parameter.") 75 self.tcChi 75 self.tcChi = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 76 76 self.tcChi.SetToolTipString("Chi^2 over degrees of freedom.") 77 self.xminFit 77 self.xminFit = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 78 78 msg = "Enter the minimum value on " 79 79 msg += "the x-axis to be included in the fit." 80 80 self.xminFit.SetToolTipString(msg) 81 self.xmaxFit 81 self.xmaxFit = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 82 82 msg = "Enter the maximum value on " 83 83 msg += " the x-axis to be included in the fit." … … 91 91 92 92 # Make the info box not editable 93 # _BACKGROUND_COLOR = '#ffdf85'93 # _BACKGROUND_COLOR = '#ffdf85' 94 94 _BACKGROUND_COLOR = self.GetBackgroundColour() 95 95 self.initXmin.SetEditable(False) … … 97 97 self.initXmax.SetEditable(False) 98 98 self.initXmax.SetBackgroundColour(_BACKGROUND_COLOR) 99 99 100 100 # Buttons on the bottom 101 101 self.bg_on = False … … 104 104 self.btFit.Bind(wx.EVT_BUTTON, self._onFit) 105 105 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') 107 107 self.btClose.Bind(wx.EVT_BUTTON, self._on_close) 108 108 if RG_ON: … … 122 122 iy = 1 123 123 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) 125 125 iy += 2 126 126 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) 130 130 ix += 1 131 131 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) 133 133 ix += 1 134 134 sizer.Add(self.tcErrA, (iy, ix), (1, 1), 135 wx.EXPAND |wx.ADJUST_MINSIZE, 0)135 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 136 136 iy += 1 137 137 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) 142 142 ix += 1 143 143 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) 145 145 ix += 1 146 146 sizer.Add(self.tcErrB, (iy, ix), (1, 1), 147 wx.EXPAND|wx.ADJUST_MINSIZE, 0)147 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 148 148 iy += 1 149 149 ix = 0 150 150 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) 157 154 iy += 2 158 155 ix = 1 159 156 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) 161 158 ix += 2 162 159 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) 164 161 165 162 iy += 1 166 163 ix = 0 167 164 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) 173 170 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 177 174 iy += 1 178 175 ix = 0 179 176 sizer.Add(wx.StaticText(self, -1, 'Fit range of ' + self.xLabel), 180 177 (iy, ix), (1, 1), 181 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)178 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 182 179 ix += 1 183 180 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) 185 182 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) 187 184 if self.rg_on: 188 185 self.SetSize((PNL_WIDTH, PNL_HEIGHT)) … … 195 192 self.I0err_tctr.SetBackgroundColour(_BACKGROUND_COLOR) 196 193 Rg_stxt = wx.StaticText(self, -1, 'Rg [A]') 197 Rg_stxt.Show(self.yLabel == "ln(y)" 194 Rg_stxt.Show(self.yLabel == "ln(y)") 198 195 self.Rg_tctr = wx.TextCtrl(self, -1, '') 199 196 self.Rg_tctr.SetEditable(False) 200 197 self.Rg_tctr.SetBackgroundColour(_BACKGROUND_COLOR) 201 self.Rg_tctr.Show(self.yLabel == "ln(y)" 198 self.Rg_tctr.Show(self.yLabel == "ln(y)") 202 199 self.Rgerr_tctr = wx.TextCtrl(self, -1, '') 203 200 self.Rgerr_tctr.SetEditable(False) 204 201 self.Rgerr_tctr.SetBackgroundColour(_BACKGROUND_COLOR) 205 self.Rgerr_tctr.Show(self.yLabel == "ln(y)" 202 self.Rgerr_tctr.Show(self.yLabel == "ln(y)") 206 203 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)") 208 205 Diameter_stxt = wx.StaticText(self, -1, 'Rod Diameter [A]') 209 206 Diameter_stxt.Show(self.yLabel == "ln(y*x)") … … 229 226 iy += 2 230 227 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) 236 233 ix += 1 237 234 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 243 240 iy += 1 244 241 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 251 248 ix += 1 252 249 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) 257 254 iy += 1 258 255 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 265 262 ix += 1 266 263 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) 271 268 iy += 1 272 269 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) 278 275 iy += 1 279 276 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 286 283 iy += 1 287 284 ix = 1 288 285 289 286 vbox.Add(self.static_line_1, 0, wx.EXPAND, 0) 290 287 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) 293 290 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) 299 296 self.SetSizer(vbox) 300 297 self.Centre() … … 302 299 from LineModel import LineModel 303 300 self.model = LineModel() 304 # Display the fittings values301 # Display the fittings values 305 302 self.default_A = self.model.getParam('A') 306 303 self.default_B = self.model.getParam('B') 307 304 self.cstA = fittings.Parameter(self.model, 'A', self.default_A) 308 305 self.cstB = fittings.Parameter(self.model, 'B', self.default_B) 309 306 310 307 # Set default value of parameter in fit dialog 311 308 if self.Avalue == None: … … 330 327 self.tcChi.SetLabel(format_number(self.Chivalue)) 331 328 if self.plottable.x != []: 332 # store the values of View in self.x,self.y,self.dx,self.dy329 # store the values of View in self.x,self.y,self.dx,self.dy 333 330 self.x, self.y, self.dx, \ 334 331 self.dy = self.plottable.returnValuesOfView() … … 348 345 self.xminFit.SetValue(format_number(self.mini)) 349 346 self.xmaxFit.SetValue(format_number(self.maxi)) 350 347 351 348 def register_close(self, owner): 352 349 """ … … 354 351 window that needs notification when the dialog 355 352 is closed 356 353 357 354 :param owner: parent window 358 355 359 356 """ 360 357 self._registered_close = owner 361 358 362 359 def _on_close(self, event): 363 360 """ … … 368 365 if self._registered_close is not None: 369 366 self._registered_close() 370 367 371 368 def _onFit(self, event): 372 369 """ … … 379 376 tempy = [] 380 377 tempdy = [] 381 378 382 379 # Check if View contains a x array .we online fit when x exits 383 380 # makes transformation for y as a line to fit 384 381 if self.x != []: 385 if (self.checkFitValues(self.xminFit) == True):386 # Check if the field of Fit Dialog contain values382 if self.checkFitValues(self.xminFit) == True: 383 # Check if the field of Fit Dialog contain values 387 384 # and use the x max and min of the user 388 #xminView,xmaxView = self._checkVal(self.xminFit.GetValue(),389 #self.xmaxFit.GetValue())390 385 if not self._checkVal(self.xminFit, self.xmaxFit): 391 386 return 392 387 xminView = float(self.xminFit.GetValue()) 393 388 xmaxView = float(self.xmaxFit.GetValue()) 394 #xmin = self.floatInvTransform(xminView)395 #xmax = self.floatInvTransform(xmaxView)396 389 xmin = xminView 397 390 xmax = xmaxView … … 399 392 # in variables before the fit 400 393 if self.yLabel.lower() == "log10(y)": 401 if (self.xLabel.lower() == "log10(x)"):394 if self.xLabel.lower() == "log10(x)": 402 395 for i in range(len(self.x)): 403 396 if self.x[i] >= math.log10(xmin): 404 397 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)) 407 399 else: 408 400 for i in range(len(self.y)): 409 401 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)) 412 403 else: 413 404 tempy = self.y 414 405 tempdy = self.dy 415 416 if (self.xLabel.lower() == "log10(x)"):406 407 if self.xLabel.lower() == "log10(x)": 417 408 for x_i in self.x: 418 409 if x_i >= math.log10(xmin): … … 420 411 else: 421 412 tempx = self.x 422 423 # Find the fitting parameters413 414 # Find the fitting parameters 424 415 # Always use the same defaults, so that fit history 425 # doesn't play a role!416 # doesn't play a role! 426 417 self.cstA = fittings.Parameter(self.model, 'A', self.default_A) 427 418 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)": 430 421 tempdy = numpy.asarray(tempdy) 431 422 tempdy[tempdy == 0] = 1 432 423 chisqr, out, cov = fittings.sasfit(self.model, 433 434 435 436 437 424 [self.cstA, self.cstB], 425 tempx, tempy, 426 tempdy, 427 math.log10(xmin), 428 math.log10(xmax)) 438 429 else: 439 430 tempdy = numpy.asarray(tempdy) 440 431 tempdy[tempdy == 0] = 1 441 432 chisqr, out, cov = fittings.sasfit(self.model, 442 443 444 433 [self.cstA, self.cstB], 434 tempx, tempy, tempdy, 435 xminView, xmaxView) 445 436 # Use chi2/dof 446 437 if len(tempx) > 0: 447 chisqr = chisqr /len(tempx)448 449 # Check that cov and out are iterable before displaying them438 chisqr = chisqr / len(tempx) 439 440 # Check that cov and out are iterable before displaying them 450 441 if cov == None: 451 442 errA = 0.0 … … 463 454 self.model.setParam('A', float(cstA)) 464 455 self.model.setParam('B', float(cstB)) 465 456 466 457 tempx = [] 467 458 tempy = [] 468 459 y_model = 0.0 469 460 # load tempy with the minimum transformation 470 461 471 462 if self.xLabel == "log10(x)": 472 463 y_model = self.model.run(math.log10(xmin)) … … 475 466 y_model = self.model.run(xminView) 476 467 tempx.append(xminView) 477 468 478 469 if self.yLabel == "log10(y)": 479 470 tempy.append(math.pow(10, y_model)) 480 471 else: 481 472 tempy.append(y_model) 482 473 483 474 # load tempy with the maximum transformation 484 475 if self.xLabel == "log10(x)": … … 488 479 y_model = self.model.run(xmaxView) 489 480 tempx.append(xmaxView) 490 481 491 482 if self.yLabel == "log10(y)": 492 483 tempy.append(math.pow(10, y_model)) 493 484 else: 494 485 tempy.append(y_model) 495 # Set the fit parameter display when FitDialog is opened again486 # Set the fit parameter display when FitDialog is opened again 496 487 self.Avalue = cstB 497 488 self.Bvalue = cstA … … 501 492 self.push_data(tempx, tempy, xminView, xmaxView, 502 493 xmin, xmax, self._ongetValues()) 503 494 504 495 # Display the fitting value on the Fit Dialog 505 496 self._onsetValues(cstB, cstA, errA, errB, chisqr) 506 497 507 498 def _onsetValues(self, cstA, cstB, errA, errB, Chi): 508 499 """ … … 527 518 value = format_number(3 * float(cstA) / (2 * rg)) 528 519 else: 529 value = ''520 value = '' 530 521 self.Rgerr_tctr.SetValue(value) 531 522 if self.I0err_tctr.IsShown(): … … 540 531 value = format_number(8 * float(cstA) / rg) 541 532 else: 542 value = ''533 value = '' 543 534 self.Diametererr_tctr.SetValue(value) 544 535 if self.RgQmin_tctr.IsShown(): … … 548 539 value = format_number(rg * self.maxi) 549 540 self.RgQmax_tctr.SetValue(value) 550 541 551 542 def _ongetValues(self): 552 543 """ … … 555 546 return self.Avalue, self.Bvalue, self.ErrAvalue, \ 556 547 self.ErrBvalue, self.Chivalue 557 548 558 549 def _checkVal(self, usermin, usermax): 559 550 """ … … 579 570 usermin.SetBackgroundColour("pink") 580 571 usermin.Refresh() 581 572 582 573 return flag 583 574 584 575 def floatForwardTransform(self, x): 585 576 """ 586 577 transform a float. 587 578 """ 588 # TODO: refactor this with proper object-oriented design579 # TODO: refactor this with proper object-oriented design 589 580 # This code stinks. 590 if (self.xLabel == "x"):581 if self.xLabel == "x": 591 582 return transform.toX(x) 592 if (self.xLabel == "x^(2)"):583 if self.xLabel == "x^(2)": 593 584 return transform.toX2(x) 594 if (self.xLabel == "ln(x)"):585 if self.xLabel == "ln(x)": 595 586 return transform.toLogX(x) 596 if (self.xLabel == "log10(x)"):587 if self.xLabel == "log10(x)": 597 588 return math.log10(x) 598 589 599 590 def floatTransform(self, x): 600 591 """ … … 603 594 not in x 604 595 """ 605 # TODO: refactor this with proper object-oriented design596 # TODO: refactor this with proper object-oriented design 606 597 # This code stinks. 607 if (self.xLabel == "x"):598 if self.xLabel == "x": 608 599 return transform.toX(x) 609 if (self.xLabel == "x^(2)"):600 if self.xLabel == "x^(2)": 610 601 return transform.toX2(x) 611 if (self.xLabel == "ln(x)"):602 if self.xLabel == "ln(x)": 612 603 return transform.toLogX(x) 613 if (self.xLabel == "log10(x)"):604 if self.xLabel == "log10(x)": 614 605 if x > 0: 615 606 return x 616 607 else: 617 608 raise ValueError, "cannot compute log of a negative number" 618 609 619 610 def floatInvTransform(self, x): 620 611 """ 621 612 transform a float.It is use to determine the x.View min and x.View 622 613 max for values not in x 623 624 """ 625 # TODO: refactor this. This is just a hack to make the614 615 """ 616 # TODO: refactor this. This is just a hack to make the 626 617 # functionality work without rewritting the whole code 627 618 # with good design (which really should be done...). 628 if (self.xLabel == "x^(2)"):619 if self.xLabel == "x^(2)": 629 620 return math.sqrt(x) 630 631 elif(self.xLabel == "log10(x)"): 621 elif self.xLabel == "log10(x)": 632 622 return math.pow(10, x) 633 634 elif(self.xLabel == "ln(x)"): 623 elif self.xLabel == "ln(x)": 635 624 return math.exp(x) 636 625 return x 637 626 638 627 def checkFitValues(self, item): 639 628 """ … … 643 632 value = item.GetValue() 644 633 # 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: 647 636 item.SetBackgroundColour(wx.WHITE) 648 637 item.Refresh() … … 652 641 item.Refresh() 653 642 return flag 654 643 655 644 def setFitRange(self, xmin, xmax, xminTrans, xmaxTrans): 656 645 """ … … 659 648 self.xminFit.SetValue(format_number(xmin)) 660 649 self.xmaxFit.SetValue(format_number(xmax)) 661 650 662 651 def set_fit_region(self, xmin, xmax): 663 652 """ … … 675 664 self.xminFit.SetValue(format_number(xmin)) 676 665 self.xmaxFit.SetValue(format_number(xmax)) 677 678 666 667 679 668 class MyApp(wx.App): 680 669 """ 670 Test application 681 671 """ 682 672 def OnInit(self): 683 673 """ 674 Test application initialization 684 675 """ 685 676 wx.InitAllImageHandlers() … … 688 679 push_data=self.onFitDisplay, 689 680 transform=self.returnTrans, 690 681 title='Linear Fit') 691 682 if dialog.ShowModal() == wx.ID_OK: 692 683 pass 693 684 dialog.Destroy() 694 685 return 1 695 686 696 687 def onFitDisplay(self, tempx, tempy, xminView, xmaxView, xmin, xmax, func): 697 688 """ 689 Test application dummy method 698 690 """ 699 691 pass 700 692 701 693 def returnTrans(self): 702 694 """ 695 Test application dummy method 703 696 """ 704 697 return '', '', 0, 0, 0, 0, 0 -
src/sas/plottools/fittings.py
rb9a5f0e r2df0b74 4 4 5 5 6 class Parameter :6 class Parameter(object): 7 7 """ 8 8 Class to handle model parameters 9 9 """ 10 10 def __init__(self, model, name, value=None): 11 12 13 14 15 11 self.model = model 12 self.name = name 13 if not value == None: 14 self.model.setParam(self.name, value) 15 16 16 def set(self, value): 17 17 """ … … 25 25 """ 26 26 return self.model.getParam(self.name) 27 28 29 def sasfit(model, pars, x, y, err_y 27 28 29 def sasfit(model, pars, x, y, err_y, qmin=None, qmax=None): 30 30 """ 31 31 Fit function 32 32 33 33 :param model: sas model object 34 34 :param pars: list of parameters … … 41 41 Calculates the vector of residuals for each point 42 42 in y for a given set of input parameters. 43 43 44 44 :param params: list of parameter values 45 45 :return: vector of residuals … … 49 49 p.set(params[i]) 50 50 i += 1 51 51 52 52 residuals = [] 53 53 for j in range(len(x)): … … 55 55 residuals.append((y[j] - model.runXY(x[j])) / err_y[j]) 56 56 return residuals 57 57 58 58 def chi2(params): 59 59 """ 60 60 Calculates chi^2 61 61 62 62 :param params: list of parameter values 63 63 64 64 :return: chi^2 65 65 66 66 """ 67 67 sum = 0 … … 70 70 sum += item * item 71 71 return sum 72 72 73 73 p = [param() for param in pars] 74 74 out, cov_x, info, mesg, success = optimize.leastsq(f, p, full_output=1) … … 78 78 elif len(pars) == 1: 79 79 chisqr = chi2([out]) 80 80 81 81 return chisqr, out, cov_x 82 82 83 83 84 84 def calcCommandline(event): 85 # Testing implementation85 # Testing implementation 86 86 # Fit a Line model 87 87 from LineModel import LineModel
Note: See TracChangeset
for help on using the changeset viewer.