Changeset fbc3e04 in sasview for sansview/perspectives/fitting/fitpage1D.py
- Timestamp:
- Mar 6, 2009 9:19:16 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:
- bdb27e6
- Parents:
- 0b99881
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fitpage1D.py
r0b99881 rfbc3e04 18 18 class FitPage1D(ModelPage): 19 19 """ 20 FitPage1D class contains fields allowing to display results when 21 fitting a model and one data. 22 This class used most of the methods of ModelPage class. 20 FitPanel class contains fields allowing to display results when 21 fitting a model and one data 23 22 @note: For Fit to be performed the user should check at least one parameter 24 23 on fit Panel window. … … 31 30 name=None 32 31 33 def __init__(self, parent,data,model=None, name=None, *args, **kwargs): 32 def __init__(self, parent,data, *args, **kwargs): 33 wx.ScrolledWindow.__init__(self, parent, *args, **kwargs) 34 34 35 """ 35 36 Initialization of the Panel 36 37 """ 37 ModelPage.__init__(self, parent,model,name,data,*args, **kwargs)38 39 38 #TODO: remove this once the inheritence is cleaned up 40 39 ## Data member to store the dispersion object created 41 42 43 44 def draw_panel(self): 40 self._disp_obj_dict = {} 41 42 #Data used for fitting 43 self.data = data 44 # flag to allow data2D plot 45 self.enable2D=False 46 #fit page manager 47 self.manager = None 48 #Store the parent of this panel parent 49 # For this application fitpanel is the parent 50 self.parent = parent 51 # Event_owner is the owner of model event 52 self.event_owner = None 45 53 #panel interface 46 54 self.vbox = wx.BoxSizer(wx.VERTICAL) … … 79 87 #---------sizer 1 draw-------------------------------- 80 88 #Filling the sizer containing data related fields 81 self.DataSource =wx.StaticText(self, -1,str( self.data.name))89 self.DataSource =wx.StaticText(self, -1,str(data.name)) 82 90 ix = 0 83 91 iy = 1 … … 93 101 iy = 1 94 102 # Minimum value of data 95 self.data_min = wx.StaticText(self, -1,str(format_number(numpy.min(self.data.x))))103 self.data_min = wx.StaticText(self, -1,str(format_number(numpy.min(data.x)))) 96 104 # Maximum value of data 97 self.data_max = wx.StaticText(self, -1,str(format_number(numpy.max(self.data.x))))105 self.data_max = wx.StaticText(self, -1,str(format_number(numpy.max(data.x)))) 98 106 self.text4_3 = wx.StaticText(self, -1, 'Maximum Data Range(Linear)', style=wx.ALIGN_LEFT) 99 107 self.sizer2.Add(self.text4_3,(iy,ix),(1,1),\ … … 152 160 self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) 153 161 self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30)) 154 self.Bind(wx.EVT_RADIOBUTTON, self. set_Dispers_Param, id=self.disable_disp.GetId())155 self.Bind(wx.EVT_RADIOBUTTON, self. set_Dispers_Param, id=self.enable_disp.GetId())162 self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.disable_disp.GetId()) 163 self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId()) 156 164 ix= 0 157 165 iy=1 … … 239 247 iy+=1 240 248 self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 241 249 250 # Contains link between model ,all its parameters, and panel organization 251 self.parameters=[] 252 # Contains list of parameters that cannot be fitted and reference to 253 #panel objects 254 self.fixed_param=[] 255 # Contains list of parameters with dispersity and reference to 256 #panel objects 257 self.fittable_param=[] 258 #list of dispersion paramaters 259 self.disp_list=[] 260 #contains link between a model and selected parameters to fit 261 self.param_toFit=[] 262 # model on which the fit would be performed 263 self.model=None 264 265 self.back_up_model= None 266 #dictionary of model name and model class 267 self.model_list_box={} 268 269 if self.model == None: 270 self.qmin.Disable() 271 self.qmax.Disable() 272 else: 273 self.qmin.Enable() 274 self.qmax.Enable() 275 242 276 243 277 self.vbox.Layout() … … 246 280 self.SetScrollbars(20,20,55,40) 247 281 282 self.Centre() 283 self.Layout() 284 self.GrandParent.GetSizer().Layout() 285 248 286 def compute_chisqr2D(self): 249 287 """ … … 260 298 for j in range(len(self.data.y_bins)): 261 299 #Check the range containing data between self.qmin_x and self.qmax_x 262 radius = math.pow(self.data.x_bins[i],2)\ 263 + math.pow(self.data.y_bins[j],2) 264 265 if radius >= math.pow(self.qmin_x,2): 266 if radius <=math.pow(self.qmax_x,2): 267 temp= self.model.runXY( [self.data.y_bins[j],self.data.x_bins[i]] ) 268 chisqrji=(self.data.data[j][i]- temp)/self.data.err_data[j][i] 300 if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)>=math.pow(self.qmin_x,2): 301 if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)<=math.pow(self.qmax_x,2): 302 chisqrji=(self.data.data[j][i]- self.model.runXY(\ 303 [self.data.y_bins[j],self.data.x_bins[i]]))\ 304 /self.data.err_data[j][i] 269 305 #Vector containing residuals 270 306 res.append( math.pow(chisqrji,2) ) … … 276 312 self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res)))) 277 313 except: 278 msg= "Chisqr cannot be compute: %s"% sys.exc_value279 wx.PostEvent(self.parent.GrandParent, StatusEvent(status= msg))314 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 315 "Chisqr cannot be compute: %s"% sys.exc_value)) 280 316 return 281 317 … … 295 331 self.qmin_x = float(self.qmin.GetValue()) 296 332 self.qmax_x = float(self.qmax.GetValue()) 297 # Computeresiduals within self.qmin_x and self.qmax_x333 # return residuals within self.qmin_x and self.qmax_x 298 334 x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)] 299 335 if self.qmin_x==None and self.qmax_x==None: … … 313 349 self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res)))) 314 350 except: 315 msg= "Chisqr cannot be compute: %s"% sys.exc_value316 wx.PostEvent(self.parent.GrandParent, StatusEvent(status= msg))351 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 352 "Chisqr cannot be compute: %s"% sys.exc_value)) 317 353 return 318 319 354 320 355 def _on_select_model(self,event): … … 345 380 346 381 if name ==event.GetString(): 347 self.model=item()348 self.back_up_model= self.model.clone()349 evt = ModelEventbox(model=self.model,name=name)350 wx.PostEvent(self.event_owner, evt)351 382 try: 383 self.model=item() 384 self.back_up_model= self.model.clone() 385 evt = ModelEventbox(model=self.model,name=name) 386 wx.PostEvent(self.event_owner, evt) 387 self.text1_1.Show() 352 388 self.compute_chisqr() 353 389 self.tcChi.Show() 354 self.text1_1.Show()355 390 except: 356 self.text1_1.Hide() 357 pass 391 raise #ValueError,"model.name is not equal to model class name" 358 392 break 359 393 360 394 361 395 def onFit(self,event): … … 383 417 self.parent.GetSizer().Layout() 384 418 else: 385 msg= "Select at least one parameter to fit "386 wx.PostEvent(self.parent.parent, StatusEvent(status= msg))419 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 420 "Select at least one parameter to fit ")) 387 421 422 423 def _onTextEnter(self,event): 424 """ 425 set a flag to determine if the fitting range entered by the user is valid 426 """ 427 428 try: 429 flag=self.checkFitRange() 430 if flag==True and self.model!=None: 431 self.manager.redraw_model(float(self.xmin.GetValue())\ 432 ,float(self.xmax.GetValue())) 433 except: 434 435 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 436 "Drawing Error:wrong value entered %s"% sys.exc_value)) 437 438 388 439 389 440 def get_param_list(self): … … 408 459 self.compute_chisqr() 409 460 except: 410 self.text1_1.Hide()411 461 pass 412 462 … … 462 512 if item in self.param_toFit: 463 513 self.param_toFit.remove(item) 464 #Set the value of checkbox that selected all checkboxes or not to true or false514 #Set the value of checkbox that selected every checkbox or not 465 515 if len(self.parameters)+len(self.fittable_param) ==len(self.param_toFit): 466 516 self.cb1.SetValue(True)
Note: See TracChangeset
for help on using the changeset viewer.