Changeset fbc3e04 in sasview for sansview/perspectives
- 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
- Location:
- sansview/perspectives/fitting
- Files:
-
- 2 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) -
sansview/perspectives/fitting/modelpage.py
r0b99881 rfbc3e04 14 14 15 15 16 16 17 class ModelPage(wx.ScrolledWindow): 17 18 """ 18 ModelPage is a panel that allows the user to view information related to a 19 model. 19 FitPanel class contains fields allowing to display results when 20 fitting a model and one data 21 @note: For Fit to be performed the user should check at least one parameter 22 on fit Panel window. 20 23 21 24 """ … … 24 27 ## Title to appear on top of the window 25 28 window_caption = "Fit Page" 26 # name of the panel directly related to the model name selected 27 name =" " 28 29 def __init__(self, parent,model=None,name=None,data=None, *args, **kwargs): 29 name="" 30 31 def __init__(self, parent,model,name, *args, **kwargs): 30 32 wx.ScrolledWindow.__init__(self, parent, *args, **kwargs) 31 33 """ … … 37 39 ## Data member to store the dispersion object created 38 40 self._disp_obj_dict = {} 39 40 #list of dispersion param eters41 42 #list of dispersion paramaters 41 43 self.disp_list=[] 42 44 try: … … 49 51 # this panel does contain data .existing data allow a different drawing 50 52 #on set_model parameters 51 self.data=data 52 53 54 # contains link between model ,all its parameters, and panel organization 55 self.parameters=[] 56 #list of parameters that cannot be fitted and panel object related to this parameters 57 #values 58 self.fixed_param=[] 59 # 60 self.fittable_param=[] 61 self.polydisp= {} 62 #contains link between a model and selected parameters to fit 63 self.param_toFit=[] 64 65 self.prevmodel_name=name 66 self.draw_panel() 67 #dictionary of model name and model class 68 self.model_list_box={} 69 #Draw initial panel 70 if self.model!=None: 71 self.set_panel(self.model) 72 self.theta_cb=None 73 # flag to allow data2D plot 74 self.enable2D=False 75 76 77 self.Centre() 78 self.Layout() 79 self.parent.GetSizer().Layout() 80 81 def draw_panel(self): 53 self.data=None 82 54 #panel interface 83 55 self.vbox = wx.BoxSizer(wx.VERTICAL) … … 90 62 self.sizer5 = wx.GridBagSizer(5,5) 91 63 self.sizer4 = wx.GridBagSizer(5,5) 64 92 65 #model selection 93 66 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) … … 106 79 # plotting range 107 80 self.vbox.Add(self.sizer9) 108 81 #close layer 82 #self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 83 #self.vbox.Add(self.sizer10) 84 85 109 86 #------------------ sizer 4 draw------------------------ 87 88 110 89 # define combox box 111 90 self.modelbox = wx.ComboBox(self, -1) 112 91 # preview selected model name 113 92 self.prevmodel_name=name 114 93 #print "model view prev_model",name 115 94 self.modelbox.SetValue(self.prevmodel_name) … … 142 121 self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) 143 122 self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30)) 144 self.Bind(wx.EVT_RADIOBUTTON, self. set_Dispers_Param, id=self.disable_disp.GetId())145 self.Bind(wx.EVT_RADIOBUTTON, self. set_Dispers_Param, id=self.enable_disp.GetId())123 self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.disable_disp.GetId()) 124 self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId()) 146 125 ix= 0 147 126 iy=1 … … 155 134 iy+=1 156 135 self.sizer6.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 136 137 157 138 #---------sizer 9 draw---------------------------------------- 158 ## Q range 139 140 ## Q range 159 141 self.qmin_x= 0.001 160 142 self.qmax_x= 0.1 … … 208 190 iy+=1 209 191 self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 192 #----------sizer 10 draw------------------------------------------------------ 193 """ 194 id = wx.NewId() 195 self.btClose =wx.Button(self,id,'Close') 196 self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id) 197 self.btClose.SetToolTipString("Close page.") 198 199 ix= 3 200 iy= 1 201 self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 202 ix +=1 203 self.sizer10.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 204 ix =0 205 iy+=1 206 self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 207 """ 208 # contains link between model ,all its parameters, and panel organization 209 self.parameters=[] 210 self.fixed_param=[] 211 self.fittable_param=[] 212 self.polydisp= {} 213 #contains link between a model and selected parameters to fit 214 self.param_toFit=[] 215 216 #dictionary of model name and model class 217 self.model_list_box={} 218 #Draw initial panel 219 #-----sizer 11--------------------model description------ 220 if self.model!=None: 221 self.set_panel(self.model) 222 self.theta_cb=None 223 224 210 225 self.vbox.Layout() 211 226 self.vbox.Fit(self) … … 213 228 self.SetScrollbars(20,20,55,40) 214 229 215 230 self.Centre() 231 self.Layout() 232 self.parent.GetSizer().Layout() 216 233 def set_model_description(self, model): 217 """ 218 Set a sizer with model description field 219 @param model: the model select that provides the description 220 """ 234 221 235 if model !=None and str(model.description)!=""and self.data==None: 222 236 self.sizer11.Clear(True) … … 266 280 267 281 268 def set_Dispers_Param(self, event): 269 """ 270 set a sizer with dispersion parameters 282 def Set_DipersParam(self, event): 283 """ 284 This method is called when the user changes the state 285 of the "dispersity" radio buttons. 286 287 #TODO: correct the spelling mistake in the name of this method, start name with lowercase. 271 288 """ 272 289 if self.enable_disp.GetValue(): … … 287 304 return 288 305 else: 289 # allow to recognize data panel from model panel 290 if self.data !=None and self.model !=None: 291 292 self.cb1.SetValue(False) 293 self.select_all_param_helper() 294 306 # Show the default dispersion/averaging sub-panel 295 307 self.populate_disp_box() 296 308 self.set_panel_dispers(self.disp_list) … … 323 335 324 336 def populate_disp_box(self): 325 """326 populate polydispersion combo box327 """328 337 self.sizer7.Clear(True) 329 338 if len(self.disp_list)>0: … … 341 350 for k,v in self.polydisp.iteritems(): 342 351 if str(v)=="MyModel": 343 352 # Remove the option until the rest of the code is ready for it 344 353 #self.disp_box.Insert("Select customized Model",id) 345 354 pass … … 372 381 self.qmax.SetValue(format_number(self.qmax_x)) 373 382 self.npts.SetValue(format_number(self.num_points)) 374 375 376 383 def checkFitRange(self): 377 384 """ … … 380 387 background is colored in pink. 381 388 """ 389 382 390 flag = True 383 391 valueMin = self.qmin.GetValue() 384 392 valueMax = self.qmax.GetValue() 385 393 # Check for possible values entered 394 #print "fitpage: checkfitrange:",valueMin,valueMax 386 395 try: 387 396 if (float(valueMax)> float(valueMin)): … … 401 410 return flag 402 411 412 413 414 def onClose(self,event): 415 """ close the page associated with this panel""" 416 self.parent.onClose() 417 418 403 419 404 420 def onModel2D(self, event): … … 440 456 type =event.GetString() 441 457 self.set_panel_dispers( self.disp_list,type ) 442 443 458 444 459 def _on_select_model(self,event): 445 460 """ … … 532 547 self.text2_3.Hide() 533 548 549 534 550 ix +=1 535 551 self.text2_4 = wx.StaticText(self, -1, 'Units') … … 538 554 self.text2_4.Hide() 539 555 disp_list=self.model.getDispParamList() 540 #541 556 for item in keys: 542 557 if not item in disp_list: … … 599 614 600 615 def _selectDlg(self): 601 """602 Create a dialog to select files603 """604 616 import os 605 617 dlg = wx.FileDialog(self, "Choose a weight file", os.getcwd(), "", "*.*", wx.OPEN) … … 609 621 dlg.Destroy() 610 622 return path 611 612 613 623 def read_file(self, path): 614 """615 Read a file of 2 colons616 @param path: the path to the file617 @return 2 numpy arrays containing numbers618 """619 624 try: 620 625 if path==None: … … 641 646 return numpy.array(angles), numpy.array(weights) 642 647 except: 643 msg= "Simultaneous Fit completed but Following error occurred: " 644 msg+= "%s"%sys.exc_value 645 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 646 return 648 raise 647 649 648 650 … … 652 654 @param event: check box event 653 655 """ 656 657 654 658 # Go through the list of dispersion check boxes to identify which one has changed 655 659 for p in self.disp_cb_dict: … … 713 717 self._draw_model() 714 718 return 715 719 720 721 716 722 717 723 def set_panel_dispers(self, disp_list, type="GaussianModel" ): 718 724 """ 719 Fill sizer with disperstion info720 725 """ 721 726 … … 838 843 self.parent.GetSizer().Layout() 839 844 840 841 845 def checkFitValues(self,val_min, val_max): 842 846 """ … … 894 898 self.set_model_parameter() 895 899 896 897 898 900 def set_model_parameter(self): 899 901 """ 900 Value Enter by the user on the parameter fields are used to reset the model901 and model will be drawn again if the user enters different values902 902 """ 903 903 if len(self.parameters) !=0 and self.model !=None: … … 915 915 916 916 except: 917 #raise 917 918 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 918 919 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) … … 931 932 932 933 except: 934 raise 933 935 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 934 "Model Drawing Error:wrong value entered : %s"% sys.exc_value))936 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 935 937 936 938 for item in self.parameters: … … 947 949 #raise 948 950 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 949 "Model Drawing Error:wrong value entered : %s"% sys.exc_value))951 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 950 952 return 951 953 … … 968 970 self._draw_model() 969 971 970 971 972 def _draw_model(self, name=None): 972 973 """ … … 985 986 enable2D=self.enable2D) 986 987 987 988 988 def select_param(self,event): 989 989 """ 990 Select_parameter is implemented in fitpage.py990 991 991 """ 992 992 pass 993 994 995 993 def select_all_param(self,event): 996 994 """ 997 Implemented in fitpage.py995 998 996 """ 999 997 pass 1000 1001 1002 998 def select_all_param_helper(self): 1003 999 """ 1004 Allows selecting or unselecting checkbutton1000 Allows selecting or delecting button 1005 1001 """ 1006 1002 self.param_toFit=[]
Note: See TracChangeset
for help on using the changeset viewer.