- Timestamp:
- Mar 6, 2009 5:06:30 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:
- fbc3e04
- Parents:
- 19ef1e5
- Location:
- sansview/perspectives/fitting
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fitpage1D.py
r76dab10 r0b99881 18 18 class FitPage1D(ModelPage): 19 19 """ 20 FitPanel class contains fields allowing to display results when 21 fitting a model and one data 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. 22 23 @note: For Fit to be performed the user should check at least one parameter 23 24 on fit Panel window. … … 30 31 name=None 31 32 32 def __init__(self, parent,data, *args, **kwargs): 33 wx.ScrolledWindow.__init__(self, parent, *args, **kwargs) 34 33 def __init__(self, parent,data,model=None, name=None, *args, **kwargs): 35 34 """ 36 35 Initialization of the Panel 37 36 """ 37 ModelPage.__init__(self, parent,model,name,data,*args, **kwargs) 38 38 39 #TODO: remove this once the inheritence is cleaned up 39 40 ## Data member to store the dispersion object created 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 41 42 43 44 def draw_panel(self): 53 45 #panel interface 54 46 self.vbox = wx.BoxSizer(wx.VERTICAL) … … 87 79 #---------sizer 1 draw-------------------------------- 88 80 #Filling the sizer containing data related fields 89 self.DataSource =wx.StaticText(self, -1,str( data.name))81 self.DataSource =wx.StaticText(self, -1,str(self.data.name)) 90 82 ix = 0 91 83 iy = 1 … … 101 93 iy = 1 102 94 # Minimum value of data 103 self.data_min = wx.StaticText(self, -1,str(format_number(numpy.min(data.x))))95 self.data_min = wx.StaticText(self, -1,str(format_number(numpy.min(self.data.x)))) 104 96 # Maximum value of data 105 self.data_max = wx.StaticText(self, -1,str(format_number(numpy.max(data.x))))97 self.data_max = wx.StaticText(self, -1,str(format_number(numpy.max(self.data.x)))) 106 98 self.text4_3 = wx.StaticText(self, -1, 'Maximum Data Range(Linear)', style=wx.ALIGN_LEFT) 107 99 self.sizer2.Add(self.text4_3,(iy,ix),(1,1),\ … … 160 152 self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) 161 153 self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30)) 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())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()) 164 156 ix= 0 165 157 iy=1 … … 247 239 iy+=1 248 240 self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 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 241 276 242 277 243 self.vbox.Layout() … … 280 246 self.SetScrollbars(20,20,55,40) 281 247 282 self.Centre()283 self.Layout()284 self.GrandParent.GetSizer().Layout()285 286 248 def compute_chisqr2D(self): 287 249 """ … … 298 260 for j in range(len(self.data.y_bins)): 299 261 #Check the range containing data between self.qmin_x and self.qmax_x 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] 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] 305 269 #Vector containing residuals 306 270 res.append( math.pow(chisqrji,2) ) … … 312 276 self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res)))) 313 277 except: 314 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\315 "Chisqr cannot be compute: %s"% sys.exc_value))278 msg= "Chisqr cannot be compute: %s"% sys.exc_value 279 wx.PostEvent(self.parent.GrandParent, StatusEvent(status= msg )) 316 280 return 317 281 … … 331 295 self.qmin_x = float(self.qmin.GetValue()) 332 296 self.qmax_x = float(self.qmax.GetValue()) 333 # returnresiduals within self.qmin_x and self.qmax_x297 # Compute residuals within self.qmin_x and self.qmax_x 334 298 x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)] 335 299 if self.qmin_x==None and self.qmax_x==None: … … 349 313 self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res)))) 350 314 except: 351 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\352 "Chisqr cannot be compute: %s"% sys.exc_value))315 msg= "Chisqr cannot be compute: %s"% sys.exc_value 316 wx.PostEvent(self.parent.GrandParent, StatusEvent(status= msg)) 353 317 return 318 354 319 355 320 def _on_select_model(self,event): … … 380 345 381 346 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) 382 351 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()388 352 self.compute_chisqr() 389 353 self.tcChi.Show() 354 self.text1_1.Show() 390 355 except: 391 raise #ValueError,"model.name is not equal to model class name" 356 self.text1_1.Hide() 357 pass 392 358 break 393 359 394 360 395 361 def onFit(self,event): … … 417 383 self.parent.GetSizer().Layout() 418 384 else: 419 wx.PostEvent(self.parent.parent, StatusEvent(status=\420 "Select at least one parameter to fit "))385 msg= "Select at least one parameter to fit " 386 wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) 421 387 422 423 def _onTextEnter(self,event):424 """425 set a flag to determine if the fitting range entered by the user is valid426 """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 439 388 440 389 def get_param_list(self): … … 459 408 self.compute_chisqr() 460 409 except: 410 self.text1_1.Hide() 461 411 pass 462 412 … … 512 462 if item in self.param_toFit: 513 463 self.param_toFit.remove(item) 514 #Set the value of checkbox that selected every checkbox or not464 #Set the value of checkbox that selected all checkboxes or not to true or false 515 465 if len(self.parameters)+len(self.fittable_param) ==len(self.param_toFit): 516 466 self.cb1.SetValue(True) -
sansview/perspectives/fitting/fitpanel.py
r925a30e r0b99881 126 126 if not name in self.fit_page_name : 127 127 from fitpage1D import FitPage1D 128 panel = FitPage1D( self,data,-1)128 panel = FitPage1D(parent=self,data=data, id=-1) 129 129 panel.name=name 130 130 -
sansview/perspectives/fitting/modelpage.py
ra38c284 r0b99881 14 14 15 15 16 17 16 class ModelPage(wx.ScrolledWindow): 18 17 """ 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. 18 ModelPage is a panel that allows the user to view information related to a 19 model. 23 20 24 21 """ … … 27 24 ## Title to appear on top of the window 28 25 window_caption = "Fit Page" 29 name="" 30 31 def __init__(self, parent,model,name, *args, **kwargs): 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): 32 30 wx.ScrolledWindow.__init__(self, parent, *args, **kwargs) 33 31 """ … … 39 37 ## Data member to store the dispersion object created 40 38 self._disp_obj_dict = {} 41 42 #list of dispersion param aters39 40 #list of dispersion parameters 43 41 self.disp_list=[] 44 42 try: … … 51 49 # this panel does contain data .existing data allow a different drawing 52 50 #on set_model parameters 53 self.data=None 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): 54 82 #panel interface 55 83 self.vbox = wx.BoxSizer(wx.VERTICAL) … … 62 90 self.sizer5 = wx.GridBagSizer(5,5) 63 91 self.sizer4 = wx.GridBagSizer(5,5) 64 65 92 #model selection 66 93 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) … … 79 106 # plotting range 80 107 self.vbox.Add(self.sizer9) 81 #close layer 82 #self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 83 #self.vbox.Add(self.sizer10) 84 85 108 86 109 #------------------ sizer 4 draw------------------------ 87 88 89 110 # define combox box 90 111 self.modelbox = wx.ComboBox(self, -1) 91 112 # preview selected model name 92 self.prevmodel_name=name113 93 114 #print "model view prev_model",name 94 115 self.modelbox.SetValue(self.prevmodel_name) … … 121 142 self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) 122 143 self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30)) 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())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()) 125 146 ix= 0 126 147 iy=1 … … 134 155 iy+=1 135 156 self.sizer6.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 136 137 138 157 #---------sizer 9 draw---------------------------------------- 139 140 ## Q range 158 ## Q range 141 159 self.qmin_x= 0.001 142 160 self.qmax_x= 0.1 … … 190 208 iy+=1 191 209 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= 3200 iy= 1201 self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)202 ix +=1203 self.sizer10.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)204 ix =0205 iy+=1206 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 organization209 self.parameters=[]210 self.fixed_param=[]211 self.fittable_param=[]212 self.polydisp= {}213 #contains link between a model and selected parameters to fit214 self.param_toFit=[]215 216 #dictionary of model name and model class217 self.model_list_box={}218 #Draw initial panel219 #-----sizer 11--------------------model description------220 if self.model!=None:221 self.set_panel(self.model)222 self.theta_cb=None223 224 225 210 self.vbox.Layout() 226 211 self.vbox.Fit(self) … … 228 213 self.SetScrollbars(20,20,55,40) 229 214 230 self.Centre() 231 self.Layout() 232 self.parent.GetSizer().Layout() 215 233 216 def set_model_description(self, model): 234 217 """ 218 Set a sizer with model description field 219 @param model: the model select that provides the description 220 """ 235 221 if model !=None and str(model.description)!=""and self.data==None: 236 222 self.sizer11.Clear(True) … … 280 266 281 267 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. 268 def set_Dispers_Param(self, event): 269 """ 270 set a sizer with dispersion parameters 288 271 """ 289 272 if self.enable_disp.GetValue(): … … 304 287 return 305 288 else: 306 # Show the default dispersion/averaging sub-panel 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 307 295 self.populate_disp_box() 308 296 self.set_panel_dispers(self.disp_list) … … 335 323 336 324 def populate_disp_box(self): 325 """ 326 populate polydispersion combo box 327 """ 337 328 self.sizer7.Clear(True) 338 329 if len(self.disp_list)>0: … … 381 372 self.qmax.SetValue(format_number(self.qmax_x)) 382 373 self.npts.SetValue(format_number(self.num_points)) 374 375 383 376 def checkFitRange(self): 384 377 """ … … 387 380 background is colored in pink. 388 381 """ 389 390 382 flag = True 391 383 valueMin = self.qmin.GetValue() 392 384 valueMax = self.qmax.GetValue() 393 385 # Check for possible values entered 394 #print "fitpage: checkfitrange:",valueMin,valueMax395 386 try: 396 387 if (float(valueMax)> float(valueMin)): … … 410 401 return flag 411 402 412 413 414 def onClose(self,event):415 """ close the page associated with this panel"""416 self.parent.onClose()417 418 419 403 420 404 def onModel2D(self, event): … … 456 440 type =event.GetString() 457 441 self.set_panel_dispers( self.disp_list,type ) 458 442 443 459 444 def _on_select_model(self,event): 460 445 """ … … 547 532 self.text2_3.Hide() 548 533 549 550 534 ix +=1 551 535 self.text2_4 = wx.StaticText(self, -1, 'Units') … … 554 538 self.text2_4.Hide() 555 539 disp_list=self.model.getDispParamList() 540 # 556 541 for item in keys: 557 542 if not item in disp_list: … … 614 599 615 600 def _selectDlg(self): 601 """ 602 Create a dialog to select files 603 """ 616 604 import os 617 605 dlg = wx.FileDialog(self, "Choose a weight file", os.getcwd(), "", "*.*", wx.OPEN) … … 621 609 dlg.Destroy() 622 610 return path 611 612 623 613 def read_file(self, path): 614 """ 615 Read a file of 2 colons 616 @param path: the path to the file 617 @return 2 numpy arrays containing numbers 618 """ 624 619 try: 625 620 if path==None: … … 646 641 return numpy.array(angles), numpy.array(weights) 647 642 except: 648 raise 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 649 647 650 648 … … 654 652 @param event: check box event 655 653 """ 656 657 658 654 # Go through the list of dispersion check boxes to identify which one has changed 659 655 for p in self.disp_cb_dict: … … 717 713 self._draw_model() 718 714 return 719 720 721 715 722 716 723 717 def set_panel_dispers(self, disp_list, type="GaussianModel" ): 724 718 """ 719 Fill sizer with disperstion info 725 720 """ 726 721 … … 843 838 self.parent.GetSizer().Layout() 844 839 840 845 841 def checkFitValues(self,val_min, val_max): 846 842 """ … … 898 894 self.set_model_parameter() 899 895 896 897 900 898 def set_model_parameter(self): 901 899 """ 900 Value Enter by the user on the parameter fields are used to reset the model 901 and model will be drawn again if the user enters different values 902 902 """ 903 903 if len(self.parameters) !=0 and self.model !=None: … … 915 915 916 916 except: 917 #raise918 917 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 919 918 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) … … 932 931 933 932 except: 934 raise935 933 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 936 "Model Drawing 934 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 937 935 938 936 for item in self.parameters: … … 949 947 #raise 950 948 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 951 "Model Drawing 949 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 952 950 return 953 951 … … 970 968 self._draw_model() 971 969 970 972 971 def _draw_model(self, name=None): 973 972 """ … … 986 985 enable2D=self.enable2D) 987 986 987 988 988 def select_param(self,event): 989 989 """ 990 990 Select_parameter is implemented in fitpage.py 991 991 """ 992 992 pass 993 994 993 995 def select_all_param(self,event): 994 996 """ 995 997 Implemented in fitpage.py 996 998 """ 997 999 pass 1000 1001 998 1002 def select_all_param_helper(self): 999 1003 """ 1000 Allows selecting or delectingbutton1004 Allows selecting or unselecting checkbutton 1001 1005 """ 1002 1006 self.param_toFit=[]
Note: See TracChangeset
for help on using the changeset viewer.