Changeset b43a009 in sasview for guitools/fitDialog.py
- Timestamp:
- May 5, 2008 2:44:40 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:
- edce46e
- Parents:
- 2d06beb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/fitDialog.py
r416223d rb43a009 11 11 12 12 class LinearFit(wx.Dialog): 13 #def __init__(self, parent, id, title):14 13 def __init__(self, parent, plottable, push_data,transform, id, title): 15 14 wx.Dialog.__init__(self, parent, id, title, size=(450, 400)) 16 15 """ 17 for the fit window 16 Dialog window pops- up when select Linear fit on Context menu 17 Displays fitting parameters 18 18 """ 19 19 self.parent = parent … … 22 22 self.push_data = push_data 23 23 #dialog self plottable 24 24 25 self.plottable = plottable 25 26 # Receive transformations of x and y 26 self.xtrans,self.ytrans= self.transform() 27 self.xLabel,self.yLabel,self.Avalue,self.Bvalue,\ 28 self.ErrAvalue,self.ErrBvalue,self.Chivalue= self.transform() 27 29 #Dialog interface 28 30 panel = wx.Panel(self, -1, style=wx.SIMPLE_BORDER) … … 91 93 ix += 2 92 94 sizer.Add(self.PXmax, (iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 93 iy += 1 94 ix = 1 95 sizer.Add(wx.StaticText(panel, -1,"x transofrmation is: "+self.xtrans ),(iy, ix),(1,1),\ 96 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 97 iy += 1 98 ix = 0 99 sizer.Add(wx.StaticText(panel, -1, 'Fit Range'),(iy, ix),(1,1),\ 95 96 iy += 1 97 ix = 0 98 sizer.Add(wx.StaticText(panel, -1, 'Fit Range of '+self.xLabel),(iy, ix),(1,1),\ 100 99 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 101 100 ix += 1 … … 138 137 139 138 # Set default value of parameter in fit dialog 140 self.tcA.SetLabel(str(self.default_A)) 141 self.tcB.SetLabel(str(self.default_B)) 142 self.tcErrA.SetLabel(str(0.0)) 143 self.tcErrB.SetLabel(str(0.0)) 144 self.tcChi.SetLabel(str(0.0)) 145 139 140 if self.Avalue==None: 141 self.tcA.SetLabel(str(self.default_A)) 142 else : 143 self.tcA.SetLabel(str(self.Avalue)) 144 if self.Bvalue==None: 145 self.tcB.SetLabel(str(self.default_B)) 146 else: 147 self.tcB.SetLabel(str(self.Bvalue)) 148 if self.ErrAvalue==None: 149 self.tcErrA.SetLabel(str(0.0)) 150 else: 151 self.tcErrA.SetLabel(str(self.ErrAvalue)) 152 if self.ErrBvalue==None: 153 self.tcErrB.SetLabel(str(0.0)) 154 else: 155 self.tcErrB.SetLabel(str(self.ErrBvalue)) 156 if self.Chivalue==None: 157 self.tcChi.SetLabel(str(0.0)) 158 else: 159 self.tcChi.SetLabel(str(self.Chivalue)) 146 160 if self.plottable.x !=[]: 147 161 self.mini =min(self.plottable.x) … … 186 200 xminView=self.floatTransform(xmin) 187 201 xmaxView=self.floatTransform(xmax) 188 if (self.x trans=="log10(x)"):202 if (self.xLabel=="log10(x)"): 189 203 self.FXmin.SetValue(str(math.log10(xminView))) 190 204 self.FXmax.SetValue(str(math.log10(xmaxView))) … … 195 209 self.FXmax.Disable() 196 210 # Store the transformed values of view x, y,dy in variables before the fit 197 if self.y trans.lower() == "log10(y)":198 if (self.x trans.lower() == "log10(x)"):211 if self.yLabel.lower() == "log10(y)": 212 if (self.xLabel.lower() == "log10(x)"): 199 213 for i in range(len(x)): 200 214 if x[i]>= math.log10(xmin): … … 209 223 tempdy = dy 210 224 211 if (self.x trans.lower() == "log10(x)"):225 if (self.xLabel.lower() == "log10(x)"): 212 226 for x_i in x: 213 227 if x_i >= math.log10(xmin): … … 215 229 else: 216 230 tempx = x 217 218 #for y_i in y: 219 # dy = math.sqrt(math.fabs(y_i)) 220 # if dy >= y_i: 221 # dy = 0.9*y_i 222 # tempdy.append(dy) 223 231 224 232 #Find the fitting parameters 225 233 226 if (self.x trans.lower() == "log10(x)"):234 if (self.xLabel.lower() == "log10(x)"): 227 235 chisqr, out, cov = fittings.sansfit(self.model, [self.cstA, self.cstB], 228 236 tempx, tempy,tempdy,math.log10(xmin),math.log10(xmax)) … … 230 238 chisqr, out, cov = fittings.sansfit(self.model, 231 239 [self.cstA, self.cstB],tempx, tempy,tempdy,xminView,xmaxView) 232 print "this out",out240 #print "this out",out 233 241 #Check that cov and out are iterable before displaying them 234 242 if cov ==None: … … 253 261 # load tempy with the minimum transformation 254 262 255 if self.x trans== "log10(x)":263 if self.xLabel == "log10(x)": 256 264 y_model = self.model.run(math.log10(xmin)) 257 265 tempx.append(xmin) … … 260 268 tempx.append(xminView) 261 269 262 if self.y trans== "log10(y)":270 if self.yLabel == "log10(y)": 263 271 tempy.append(math.pow(10,y_model)) 264 272 print "tempy",tempy … … 267 275 268 276 # load tempy with the maximum transformation 269 if self.x trans== "log10(x)":277 if self.xLabel == "log10(x)": 270 278 y_model = self.model.run(math.log10(xmax)) 271 279 tempx.append(xmax) … … 274 282 tempx.append(xmaxView) 275 283 276 if self.y trans== "log10(y)":284 if self.yLabel == "log10(y)": 277 285 tempy.append(math.pow(10,y_model)) 278 286 else: 279 287 tempy.append(y_model) 280 281 self.push_data(tempx,tempy,xminView,xmaxView,xmin,xmax) 288 self.Avalue=cstA 289 self.Bvalue=cstB 290 self.ErrAvalue=errA 291 self.ErrBvalue=errB 292 self.Chivalue=chisqr 293 self.push_data(tempx,tempy,xminView,xmaxView,xmin,xmax,self._ongetValues()) 282 294 283 295 # Display the fitting value on the Fit Dialog 284 296 self._onsetValues(cstA, cstB, errA,errB,chisqr) 297 298 285 299 286 300 def _onsetValues(self,cstA,cstB,errA,errB,Chi): … … 293 307 self.tcErrB.SetValue(str(errB)) 294 308 self.tcChi.SetValue(str(Chi)) 309 310 def _ongetValues(self): 311 """ 312 Display the value on fit Dialog 313 """ 314 return self.Avalue, self.Bvalue,self.ErrAvalue,self.ErrBvalue,self.Chivalue 295 315 296 316 def _returnPlottable(self): … … 322 342 not in x 323 343 """ 324 if ( self.x trans=="x" ):344 if ( self.xLabel=="x" ): 325 345 return transform.toX(x) 326 346 327 if ( self.x trans=="x^(2)" ):347 if ( self.xLabel=="x^(2)" ): 328 348 return transform.toX2(x) 329 349 330 if (self.x trans=="log10(x)" ):350 if (self.xLabel=="log10(x)" ): 331 351 if x >0: 332 352 return x … … 341 361 value = item.GetValue() 342 362 # Check for possible values entered 343 if (self.x trans=="log10(x)"):363 if (self.xLabel=="log10(x)"): 344 364 if (float(value) > 0): 345 365 item.SetBackgroundColour(wx.WHITE) … … 353 373 354 374 def setFitRange(self,xmin,xmax,Reelxmin,Reelxmax): 355 if (self.x trans=="log10(x)"):375 if (self.xLabel=="log10(x)"): 356 376 self.FXmin.SetValue(str(math.log10(xmin))) 357 377 self.FXmax.SetValue(str(math.log10(xmax)))
Note: See TracChangeset
for help on using the changeset viewer.