Changeset f52bea1 in sasview for guitools/fitDialog.py
- Timestamp:
- Apr 8, 2008 5:04:51 PM (16 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:
- 3d3a0e5
- Parents:
- 8742751
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/fitDialog.py
r5789654 rf52bea1 9 9 class LinearFit(wx.Dialog): 10 10 #def __init__(self, parent, id, title): 11 def __init__(self, parent, plottable, push_data, id, title):11 def __init__(self, parent, plottable, push_data,transform, id, title): 12 12 wx.Dialog.__init__(self, parent, id, title, size=(550, 300)) 13 13 """ … … 15 15 """ 16 16 self.parent = parent 17 self.transform = transform 17 18 #dialog panel self call function to plot the fitting function 18 19 self.push_data = push_data 19 20 #dialog self plottable 20 21 self.plottable = plottable 22 21 23 22 24 #Dialog interface … … 75 77 sizer.Add(self.tcXmax, (iy, ix)) 76 78 iy += 1 77 ix = 179 ix = 3 78 80 sizer.Add(self.btFit, (iy, ix)) 79 81 self.btFit.Bind(wx.EVT_BUTTON, self._onFit) 80 ix += 2 82 iy +=1 83 ix = 3 81 84 sizer.Add(btClose, (iy, ix)) 82 85 … … 92 95 93 96 def _onFit(self ,event): 94 95 print "we are on fit" 97 """ 98 Performs the fit. Receive an event when clicking on the button Fit.Computes chisqr , 99 A and B parameters of the best linear fit y=Ax +B 100 Push a plottable to 101 """ 102 96 103 temp =[] 104 tempx=[] 105 tempy=[] 97 106 xmin = self._checkVal(self.tcXmin.GetValue()) 98 107 xmax = self._checkVal(self.tcXmax.GetValue()) … … 100 109 #store the values of View in x,y, dx,dy 101 110 x,y,dx,dy=self.plottable.returnValuesOfView() 102 111 self.xtrans,self.ytrans= self.transform() 112 #Display the fittings values 113 default_A = self.model.getParam('A') 114 default_B = self.model.getParam('B') 115 cstA = fittings.Parameter(self.model, 'A', default_A) 116 cstB = fittings.Parameter(self.model, 'B', default_B) 117 if self.ytrans == "Log(y)": 118 for y_i in y: 119 tempy.append(log(y_i)) 120 chisqr, out, cov = fittings.sansfit(self.model, 121 [cstA, cstB],x, tempy,dy,min(x),max(x)) 122 else : 123 chisqr, out, cov = fittings.sansfit(self.model, 124 [cstA, cstB],x, y,dy,min(x),max(x)) 125 #Check that cov and out are iterable before displaying them 126 if cov ==None: 127 errA =0.0 128 errB =0.0 129 else: 130 errA= math.sqrt(cov[0][0]) 131 errB= math.sqrt(cov[1][1]) 132 if out==None: 133 cstA=0.0 134 cstB=0.0 135 else: 136 cstA=out[0] 137 cstB=out[1] 138 self.model.setParam('A', float(cstA)) 139 self.model.setParam('B', float(cstB)) 140 103 141 if x != []: 104 142 if xmin !=None and xmax != None: 105 143 for j in range(len(x)): 106 if x[j] >xmin and x[j]<xmax:144 if x[j] > xmin and x[j] < xmax: 107 145 temp.append(self.model.run(x[j])) 108 109 for y_i in temp:110 tempdy.append(math.sqrt(y_i))111 146 else: 112 147 # x has a default value in case the user doesn't load data 113 148 for x_i in x: 114 149 temp.append(self.model.run(x_i)) 115 116 self.tcXmin.SetValue(str(min(x))) 117 self.tcXmax.SetValue(str(max(x))) 118 xmin = self._checkVal(self.tcXmin.GetValue()) 119 xmax = self._checkVal(self.tcXmax.GetValue()) 150 self.tcXmin.SetValue(str(min(x))) 151 self.tcXmax.SetValue(str(max(x))) 152 xmin = self._checkVal(self.tcXmin.GetValue()) 153 xmax = self._checkVal(self.tcXmax.GetValue()) 120 154 121 155 self.file_data1.x =x 122 self.file_data1.y =temp 123 156 # Create new data plottable with result 157 self.file_data1.y =[] 158 self.xtrans, self.ytrans= self.transform() 159 160 if self.ytrans == "Log(y)": 161 for x_i in x: 162 self.file_data1.y.append(exp(self.model.run(x_i))) 163 else: 164 self.file_data1.y =temp 124 165 self.file_data1.dx=None 125 166 self.file_data1.dy=None 167 126 168 self.file_data1.reset_view() 127 128 # Display the fittings values129 default_A = self.model.getParam('A')130 default_B = self.model.getParam('B')131 cstA = fittings.Parameter(self.model, 'A', default_A)132 cstB = fittings.Parameter(self.model, 'B', default_B)133 chisqr, out, cov = fittings.sansfit(self.model,134 [cstA, cstB],x, y,dy,min(x),max(x))135 169 136 137 #Check that cov and out are iterable before displaying them138 if cov ==None:139 errA =str(0.0)140 errB =str(0.0)141 else:142 errA= str(math.sqrt(cov[0][0]))143 errB= str(math.sqrt(cov[1][1]))144 if out==None:145 cstA=str(0.0)146 cstB=str(0.0)147 else:148 cstA=str(out[0])149 cstB=str(out[1])150 151 self.model.setParam('A', float(cstA))152 self.model.setParam('B', float(cstB))153 # Create new data plottable with result154 self.file_data1.y = []155 156 for x_i in x:157 self.file_data1.y.append(self.model.run(x_i))158 170 #Send the data to display to the PlotPanel 159 self.file_data1.reset_view()171 # 160 172 self.push_data(self.file_data1) 161 173 # Display the fitting value on the Fit Dialog 162 self._onsetValues(cstA, cstB, errA,errB, str(chisqr))174 self._onsetValues(cstA, cstB, errA,errB,chisqr) 163 175 164 176 def _onsetValues(self,cstA,cstB,errA,errB,Chi): 165 166 self.tcA.SetValue(cstA) 167 self.tcB.SetValue(cstB) 168 self.tcErrA.SetValue(errA) 169 self.tcErrB.SetValue(errB) 170 self.tcChi.SetValue(Chi) 177 """ 178 Display the value on fit Dialog 179 """ 180 self.tcA.SetValue(str(cstA)) 181 self.tcB.SetValue(str(cstB)) 182 self.tcErrA.SetValue(str(errA)) 183 self.tcErrB.SetValue(str(errB)) 184 self.tcChi.SetValue(str(Chi)) 171 185 172 186 def _returnPlottable(self): … … 175 189 def _checkVal(self,value): 176 190 """ 177 Ensure that field sparameter contains a value178 before sending to fit in Plotter1D191 Ensure that field parameter contains a value 192 before sending to fit 179 193 """ 180 194 try:
Note: See TracChangeset
for help on using the changeset viewer.