- Timestamp:
- Mar 31, 2008 5:51:17 PM (17 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:
- 8e4516f
- Parents:
- 6cfe703
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/fitDialog.py
r6cfe703 re40b651 4 4 5 5 import wx 6 from sans.guitools.PlotPanel import PlotPanel 7 6 from PlotPanel import PlotPanel 7 from plottables import Theory1D 8 import math,pylab,fittings 8 9 class LinearFit(wx.Dialog): 9 def __init__(self, parent, id, title): 10 #def __init__(self, parent, id, title): 11 def __init__(self, parent, plottable, push_data, id, title): 10 12 wx.Dialog.__init__(self, parent, id, title, size=(500, 300)) 11 13 """ … … 13 15 """ 14 16 self.parent = parent 17 #dialog panel self call function to plot the fitting function 18 self.push_data = push_data 19 #dialog self plottable 20 self.plottable = plottable 21 22 #Dialog interface 15 23 panel = wx.Panel(self, -1, style=wx.SIMPLE_BORDER) 16 24 vbox = wx.BoxSizer(wx.VERTICAL) … … 40 48 ix += 1 41 49 sizer.Add(self.tcErrA, (iy, ix)) 42 #self.tcErrA.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)43 50 iy += 1 44 51 ix = 1 … … 46 53 ix += 1 47 54 sizer.Add(self.tcB, (iy, ix)) 48 #self.tcB.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)49 55 ix += 1 50 #sizer.Add(wx.StaticText(panel, -1, '+/-'),(iy, ix))56 sizer.Add(wx.StaticText(panel, -1, '+/-'),(iy, ix)) 51 57 ix += 1 52 58 sizer.Add(self.tcErrB, (iy, ix)) 53 self.tcErrB.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)54 59 iy += 1 55 60 ix = 1 … … 57 62 ix += 1 58 63 sizer.Add(self.tcChi, (iy, ix)) 59 #self.tcChi.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)60 64 iy += 1 61 65 ix = 1 … … 66 70 ix = 1 67 71 sizer.Add(self.tcXmin, (iy, ix)) 68 #self.tcXmin.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)69 72 ix += 2 70 73 sizer.Add(self.tcXmax, (iy, ix)) 71 #self.tcXmax.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)72 74 iy += 1 73 75 ix = 1 74 76 sizer.Add(self.btFit, (iy, ix)) 75 self. tcXmax.Bind(wx.EVT_KILL_FOCUS, self._onFit)77 self.btFit.Bind(wx.EVT_BUTTON, self._onFit) 76 78 ix += 2 77 79 sizer.Add(btClose, (iy, ix)) … … 80 82 self.SetSizer(vbox) 81 83 self.Centre() 84 # Receives the type of model for the fitting 85 from LineModel import LineModel 86 self.model = LineModel() 87 # new data for the fit 88 self.file_data1 = Theory1D(x=[], y=[], dy=None) 89 self.file_data1.name = "y= exp(A + bx**2)" 90 82 91 def _onFit(self ,event): 83 param_evt1 = PlotPanel.FunctionFitEvent(\ 84 Xmin=self._checkVal(self.tcXmin.GetValue()),\ 85 Xmax=self._checkVal(self.tcXmax.GetValue()) ) 86 wx.PostEvent(self, param_evt1) 87 92 93 print "we are on fit" 94 temp =[] 95 tempdx =[] 96 tempdy =[] 97 xmin = self._checkVal(self.tcXmin.GetValue()) 98 xmax = self._checkVal(self.tcXmax.GetValue()) 99 x= self.plottable.x 100 if x: 101 if xmin !=None and xmax != None: 102 for j in range(len(x)): 103 if x[j]>xmin and x[j]<xmax: 104 temp.append(self.model.run(x[j])) 105 tempdx.append(math.sqrt(x[j])) 106 for y_i in temp: 107 tempdy.append(math.sqrt(y_i)) 108 else: 109 # x has a default value in case the user doesn't load data 110 for x_i in x: 111 temp.append(self.model.run(x_i)) 112 tempdx.append(math.sqrt(x_i)) 113 for y_i in temp: 114 tempdy.append(math.sqrt(y_i)) 115 self.tcXmin.SetValue(str(min(self.plottable.x))) 116 self.tcXmax.SetValue(str(max(self.plottable.x))) 117 xmin = self._checkVal(self.tcXmin.GetValue()) 118 xmax = self._checkVal(self.tcXmax.GetValue()) 119 120 self.file_data1.x =x 121 self.file_data1.y =temp 122 self.file_data1.dx=tempdx 123 self.file_data1.dy=tempdy 124 125 126 # Display the fittings values 127 default_A = self.model.getParam('A') 128 default_B = self.model.getParam('B') 129 cstA = fittings.Parameter(self.model, 'A', default_A) 130 cstB = fittings.Parameter(self.model, 'B', default_B) 131 chisqr, out, cov = fittings.sansfit(self.model, 132 [cstA, cstB], self.plottable.x, 133 self.plottable.y, self.plottable.dy,xmin,xmax) 134 # Create new data plottable with result 135 136 self.file_data1.y = [] 137 for x_i in self.file_data1.x: 138 self.file_data1.y.append(self.model.run(x_i)) 139 140 self.push_data(self.file_data1) 141 142 self._onsetValues(str(out[0]),str(out[1]),\ 143 str(math.sqrt(cov[0][0])),str(math.sqrt(cov[1][1])),str(chisqr)) 144 88 145 def _onsetValues(self,cstA,cstB,errA,errB,Chi): 89 146 … … 93 150 self.tcErrB.SetValue(cstA) 94 151 self.tcChi.SetValue(Chi) 95 def _getXrange(self): 96 if self.tcXmin.GetValue() and self.tcXmax.GetValue(): 97 return float(),float(self.tcXmax.GetValue()) 98 else: 99 return None, None 152 153 def _returnPlottable(self): 154 return self.file_data1 155 100 156 def _checkVal(self,value): 101 157 """
Note: See TracChangeset
for help on using the changeset viewer.