Changeset 2df0b74 in sasview for src/sas/plottools/fitDialog.py
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.