Changeset 51d47b5 in sasview for sansview/perspectives/fitting
- Timestamp:
- Feb 26, 2009 3:38:02 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:
- 3199b59
- Parents:
- 8346667
- Location:
- sansview/perspectives/fitting
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fitpage1D.py
r6e659ae8 r51d47b5 41 41 #panel interface 42 42 self.vbox = wx.BoxSizer(wx.VERTICAL) 43 self.sizer10 = wx.GridBagSizer(5,5)43 #self.sizer10 = wx.GridBagSizer(5,5) 44 44 self.sizer9 = wx.GridBagSizer(5,5) 45 45 self.sizer8 = wx.GridBagSizer(5,5) … … 73 73 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 74 74 self.vbox.Add(self.sizer9) 75 #close layer 76 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 77 self.vbox.Add(self.sizer10) 75 78 76 79 77 #---------sizer 1 draw-------------------------------- … … 243 241 ix += 1 244 242 self.sizer9.Add(self.btFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 243 244 id = wx.NewId() 245 self.btStopFit =wx.Button(self,id,'Stop') 246 self.btStopFit.Bind(wx.EVT_BUTTON, self.onStopFit,id=id) 247 self.btStopFit.SetToolTipString("Stop the current fitting job.") 248 self.btStopFit.Hide() 249 ix += 1 250 self.sizer9.Add(self.btStopFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 251 245 252 ix =0 246 253 iy+=1 247 254 self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 248 255 #----------sizer 10 draw------------------------------------------------------ 256 """ 249 257 id = wx.NewId() 250 258 self.btClose =wx.Button(self,id,'Close') … … 260 268 iy+=1 261 269 self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 262 270 """ 263 271 # contains link between model ,all its parameters, and panel organization 264 272 self.parameters=[] … … 325 333 "Chisqr cannot be compute: %s"% sys.exc_value)) 326 334 327 335 def onStopFit(self, event): 336 337 self.manager.stop_fit() 338 self.btStopFit.Hide() 339 self.vbox.Layout() 340 self.SetScrollbars(20,20,55,40) 341 self.Layout() 342 self.parent.GetSizer().Layout() 328 343 def compute_chisqr(self): 329 344 """ @param fn: function that return model value … … 419 434 ymin=self.data.ymin, ymax=self.data.ymax, 420 435 xmin=self.data.xmin,xmax=self.data.xmax) 421 #self.manager._on_single_fit(qmin=self.qmin_x,qmax=self.qmax_x, 422 #ymin=self.data.ymin, ymax=self.data.ymax) 436 self.btStopFit.Show() 423 437 else: 424 438 self.manager._on_single_fit(qmin=self.qmin_x,qmax=self.qmax_x) 439 self.btStopFit.Show() 440 self.vbox.Layout() 441 self.SetScrollbars(20,20,55,40) 442 self.Layout() 443 self.parent.GetSizer().Layout() 425 444 else: 426 445 wx.PostEvent(self.parent.parent, StatusEvent(status=\ -
sansview/perspectives/fitting/fitpanel.py
r6e659ae8 r51d47b5 23 23 def __init__(self, parent, *args, **kwargs): 24 24 25 wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_SCROLL_BUTTONS )26 #wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_DEFAULT_STYLE )25 #wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_SCROLL_BUTTONS ) 26 wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_DEFAULT_STYLE ) 27 27 28 28 … … 34 34 self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage) 35 35 #Creating the default page --welcomed page 36 self.about_page=None 36 37 from sans.guiframe.welcome_panel import PanelAbout 37 38 self.about_page = PanelAbout(self, -1) … … 39 40 #self.about_page.Disable() 40 41 #Creating a page for simultaneous fitting 41 from simfitpage import SimultaneousFitPage 42 self.sim_page = SimultaneousFitPage(self, id=-1) 43 self.AddPage(self.sim_page,"Simultaneous Fit") 42 44 43 45 44 self._mgr = self.GetAuiManager() … … 55 54 56 55 self.model_page=None 56 self.sim_page=None 57 57 # increment number for model name 58 58 self.count=0 … … 63 63 64 64 def onClosePage(self, event): 65 """ 65 66 self.ToggleWindowStyle(wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB) 66 67 #print "went here",self.get_current_page(), self.GetPage(0) … … 71 72 # Prevent last tab from being closed 72 73 self.ToggleWindowStyle(~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB) 73 74 74 """ 75 selected_page = self.GetPage(self.GetSelection()) 76 page_number = self.GetSelection() 77 if self.sim_page != selected_page and selected_page!=self.about_page: 78 print "sim_page ",sim_page ,selected_page 79 # remove the check box link to the model name of this page (selected_page) 80 self.sim_page.remove_model(selected_page) 81 #remove that page from page_finder of fitting module 82 page_finder=self.manager.get_page_finder() 83 for page, value in page_finder.iteritems(): 84 if page==selected_page: 85 del page_finder[page] 86 break 87 #Delete the page from notebook 88 89 #print "on close",selected_page.name,self.GetPageText(page_number),self.draw_model_name 90 91 if selected_page.name in self.fit_page_name: 92 self.fit_page_name.remove(selected_page.name) 93 94 if selected_page.name== self.draw_model_name: 95 print "went here" 96 self.draw_model_name=None 97 self.model_page=None 98 if page_number == 1: 99 self.model_page=None 100 self.draw_model_name=None 101 #selected_page.Destroy() 102 #self.RemovePage(page_number) 103 #i=self.DeletePage(page_number) 104 elif selected_page==self.about_page: 105 #selected_page.Destroy() 106 #self.DeletePage(page_number) 107 self.about_page=None 108 else: 109 110 self.manager.sim_page=None 111 #self.DeletePage(page_number) 75 112 76 113 … … 83 120 """ 84 121 self.manager = manager 85 self.sim_page.set_manager(manager)122 #self.sim_page.set_manager(manager) 86 123 87 124 def set_owner(self,owner): … … 91 128 """ 92 129 self.event_owner=owner 93 130 131 def add_sim_page(self): 132 from simfitpage import SimultaneousFitPage 133 self.sim_page = SimultaneousFitPage(self, id=-1) 134 self.AddPage(self.sim_page,caption="Simultaneous Fit",select=True) 135 self.sim_page.set_manager(self.manager) 136 return self.sim_page 94 137 95 138 def add_fit_page( self,data ): -
sansview/perspectives/fitting/fitting.py
r6e659ae8 r51d47b5 55 55 # model 2D view 56 56 self.model2D_id=None 57 self.sim_page=None 57 58 self.err_dy={} 58 59 … … 70 71 #Menu for fitting 71 72 self.menu1 = wx.Menu() 72 #id1 = wx.NewId()73 #self.menu1.Append(id1, '&fit panel')74 #wx.EVT_MENU(owner, id1, self.on_perspective)73 id1 = wx.NewId() 74 self.menu1.Append(id1, '&Simultaneous') 75 wx.EVT_MENU(owner, id1, self.on_add_sim_page) 75 76 #Set park engine 76 77 id3 = wx.NewId() … … 84 85 id2 = wx.NewId() 85 86 owner.Bind(models.EVT_MODEL,self._on_model_menu) 86 #owner.Bind(modelpage.EVT_MODEL,self._on_model_menu)87 87 88 self.fit_panel.set_owner(owner) 88 89 self.fit_panel.set_model_list(self.menu_mng.get_model_list()) 89 90 owner.Bind(fitpage1D.EVT_MODEL_BOX,self._on_model_panel) 90 #owner.Bind(fitpage2D.EVT_MODEL_BOX,self._on_model_panel)91 91 92 #create menubar items 92 93 return [(id, self.menu1, "Fitting"),(id2, menu2, "Model")] 93 94 94 95 def on_add_sim_page(self, event): 96 self.sim_page= self.fit_panel.add_sim_page() 97 self.sim_page.add_model(self.page_finder) 98 99 95 100 def help(self, evt): 96 101 """ … … 300 305 @note: expecting park used for fit. 301 306 """ 302 sim_page=self.fit_panel.GetPage(1) 307 #sim_page=self.fit_panel.GetPage(1) 308 sim_page= self.sim_page 303 309 for page, value in self.page_finder.iteritems(): 304 310 if page != sim_page: … … 419 425 wx.PostEvent(self.parent, StatusEvent(status="Simultaneous Fitting error: %s" % sys.exc_value)) 420 426 return 421 427 def stop_fit(self): 428 if self.calc_thread != None and self.calc_thread.isrunning(): 429 430 self.calc_thread.interrupt() 431 self.calc_thread.stop() 432 wx.PostEvent(self.parent, StatusEvent(status="Fitting \ 433 is cancelled" , type="stop")) 422 434 def _on_single_fit(self,id=None,qmin=None, qmax=None,ymin=None, ymax=None,xmin=None,xmax=None): 423 435 """ … … 442 454 #with the fit will be perform 443 455 current_pg=self.fit_panel.get_current_page() 444 simul_pg=self.fit_panel.GetPage(1 ) 456 #simul_pg=self.fit_panel.GetPage(1 ) 457 simul_pg=self.sim_page 445 458 pars=[] 446 459 #for page, value in self.page_finder.iteritems(): … … 465 478 #Do the single fit 466 479 self.fitter.set_model(Model(model), self.fit_id, pars) 480 if self._fit_engine=="scipy": 481 wx.PostEvent(self.parent, StatusEvent(status="Parameters range will\ 482 be ignored for %s fitting engine"%str(self._fit_engine))) 467 483 #print "args...:",metadata,self.fit_id,smearer,qmin,qmax,ymin,ymax 468 484 dy=[] … … 565 581 param_value = item[1] 566 582 param_name = item[0] 567 #print "fitting ", param,param_name, param_value 568 569 #new_model.set( model.getParam(param_name[0])= param_value) 570 #new_model.set( exec"%s=%s"%(param_name[0], param_value)) 571 #new_model.set( exec "%s"%(param_nam) = param_value) 583 572 584 new_model.parameterset[ param_name].set( param_value ) 573 585 … … 659 671 660 672 print "name fitting", name 661 sim_page=self.fit_panel.GetPage(1) 673 #sim_page=self.fit_panel.GetPage(1) 674 sim_page=self.sim_page 662 675 current_pg = self.fit_panel.get_current_page() 663 676 if current_pg != sim_page: … … 679 692 self.page_finder[current_pg].set_model(model,M_name) 680 693 self.plot_helper(currpage= current_pg,qmin= None,qmax= None) 681 sim_page.add_model(self.page_finder) 694 if self.sim_page!=None: 695 self.sim_page.add_model(self.page_finder) 682 696 683 697 def set_smearer(self,smearer): -
sansview/perspectives/fitting/modelpage.py
r50c769e r51d47b5 34 34 # model on which the fit would be performed 35 35 self.model=model 36 self.back_up_model= model.clone() 36 37 #list of dispersion paramaters 37 38 self.disp_list=[] … … 49 50 self.vbox = wx.BoxSizer(wx.VERTICAL) 50 51 self.sizer11 = wx.BoxSizer(wx.HORIZONTAL) 51 self.sizer10 = wx.GridBagSizer(5,5)52 #self.sizer10 = wx.GridBagSizer(5,5) 52 53 self.sizer9 = wx.GridBagSizer(5,5) 53 54 self.sizer8 = wx.GridBagSizer(5,5) … … 74 75 self.vbox.Add(self.sizer9) 75 76 #close layer 76 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 77 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 78 self.vbox.Add(self.sizer10) 77 #self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 78 #self.vbox.Add(self.sizer10) 79 79 80 80 … … 186 186 self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 187 187 #----------sizer 10 draw------------------------------------------------------ 188 """ 188 189 id = wx.NewId() 189 190 self.btClose =wx.Button(self,id,'Close') … … 199 200 iy+=1 200 201 self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 201 202 """ 202 203 # contains link between model ,all its parameters, and panel organization 203 204 self.parameters=[] … … 214 215 if self.model!=None: 215 216 self.set_panel(self.model) 216 217 self.theta_cb=None 217 218 218 219 … … 291 292 else: 292 293 if self.data !=None and self.model !=None: # allow to recognize data panel from model panel 293 #if self.data !=None and self.model !=None: 294 295 294 296 self.cb1.SetValue(False) 295 297 self.select_all_param_helper() … … 302 304 if self.cb1.GetValue(): 303 305 self.select_all_param_helper() 306 307 if self.back_up_model!=None: 308 keys = self.back_up_model.getDispParamList() 309 keys.sort() 310 #disperse param into the initial state 311 for item in keys: 312 value= self.back_up_model.getParam(item) 313 self.model.setParam(item, value) 314 self._draw_model() 315 316 304 317 self.fittable_param=[] 305 318 self.fixed_param=[] … … 326 339 self.disp_box.SetValue("GaussianModel") 327 340 for k,v in self.polydisp.iteritems(): 328 self.disp_box.Insert(str(v),id) 341 """ 342 if str(v)=="MyModel": 343 self.disp_box.Insert("Select customized Model",id) 344 else: 345 self.disp_box.Insert(str(v),id) 346 """ 347 if str(v)!="MyModel": 348 self.disp_box.Insert(str(v),id) 349 329 350 id+=1 330 351 wx.EVT_COMBOBOX(self.disp_box,-1, self._on_select_Disp) … … 409 430 self.parent.model_page.name = name 410 431 self.parent.draw_model_name = name 411 self.model_view.Enable() 412 self.enable2D=False 413 print "select_model", self.name,model.__class__ 432 414 433 self.set_panel(model) 415 434 self._draw_model(name) … … 418 437 items = self.modelbox.GetItems() 419 438 for i in range(len(items)): 420 print "model name",items[i],model.name, model.__class__.__name__421 439 if items[i]==name: 422 440 self.modelbox.SetSelection(i) 423 441 self.model_view.SetFocus() 424 442 425 443 def _on_select_Disp(self,event): … … 452 470 self.set_panel(model) 453 471 self.name= name 454 472 self.model_view.SetFocus() 455 473 self.parent.model_page.name=name 456 474 self.parent.draw_model_name=name 457 #self.manager.draw_model(model, name) 458 #self.enable2D=False 459 #self.model_view.Enable() 475 460 476 self._draw_model(name) 461 477 … … 523 539 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 524 540 self.text2_3.Hide() 541 ix +=1 542 self.text2_5 = wx.StaticText(self, -1, 'Min') 543 self.sizer5.Add(self.text2_5,(iy, ix),(1,1),\ 544 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 545 ix +=1 546 self.text2_6 = wx.StaticText(self, -1, 'Max') 547 self.sizer5.Add(self.text2_6,(iy, ix),(1,1),\ 548 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 525 549 ix +=1 526 550 self.text2_4 = wx.StaticText(self, -1, 'Units') … … 559 583 self.sizer5.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 560 584 ctl2.Hide() 585 ix += 1 586 param_min= format_number(self.model.details[item][1]) 587 ctl3 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER) 588 if float(param_min) ==0: 589 ctl3.SetValue("-inf") 590 else: 591 ctl3.SetValue(str (format_number(param_min))) 592 ctl3.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 593 ctl3.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) 594 595 self.sizer5.Add(ctl3, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 596 ix += 1 597 param_max= format_number(self.model.details[item][2]) 598 ctl4 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER) 599 if float(param_max)==0: 600 ctl4.SetValue("+inf") 601 else: 602 ctl4.SetValue(str (format_number(param_max))) 603 ctl4.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 604 ctl4.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) 605 self.sizer5.Add(ctl4, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 606 561 607 ix +=1 562 608 # Units … … 567 613 self.sizer5.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 568 614 569 self.parameters.append([cb,ctl1,text2,ctl2 ])615 self.parameters.append([cb,ctl1,text2,ctl2, ctl3, ctl4]) 570 616 571 617 iy+=1 … … 579 625 else: 580 626 self.text2_4.Hide() 581 #Disable or enable fit button 582 """ 583 if not (len(self.param_toFit ) >0): 584 self.qmin.Disable() 585 self.qmax.Disable() 586 else: 587 self.qmin.Enable() 588 self.qmax.Enable() 589 """ 627 590 628 self.vbox.Layout() 591 629 self.SetScrollbars(20,20,55,40) 592 630 self.Layout() 593 631 self.parent.GetSizer().Layout() 632 633 634 594 635 def _selectDlg(self): 595 636 import os … … 602 643 def read_file(self, path): 603 644 try: 645 if path==None: 646 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 647 " Selected Distribution was not loaded: %s"%path)) 648 return None, None 604 649 input_f = open(path, 'r') 605 650 buff = input_f.read() … … 621 666 return numpy.array(angles), numpy.array(weights) 622 667 except: 668 raise 669 670 def _draw_disp_theta(self): 671 path = self._selectDlg() 672 dispersion=None 673 674 for key, value in self.polydisp.iteritems(): 675 if value =="MyModel": 676 disp_ph = key() 677 disp_th = key() 678 break 679 values,weights = self.read_file(path) 680 if values ==None and weights==None: 681 return 682 import math 683 disp_ph.set_weights( values, weights) 684 disp_th.set_weights( values, weights) 685 686 if self.theta_cb !=None: 687 angle= self.theta_cb.GetLabelText() 688 n=0 689 self.disp_list=self.model.getDispParamList() 690 if angle.lower().count("theta")>0: 691 for param in self.model.getParamList(): 692 if not param in self.disp_list and param.lower().count("theta")>0: 693 self.model.set_dispersion(param, disp_th) 694 self.model.dispersion[param]['npts'] = len(values) 695 n+=1 696 697 if n ==0: 698 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 699 " Model contains no theta distribution")) 700 else: 701 self._draw_model() 702 def _draw_disp_Phi(self): 703 path = self._selectDlg() 704 dispersion=None 705 706 for key, value in self.polydisp.iteritems(): 707 if value =="MyModel": 708 disp_ph = key() 709 disp_th = key() 710 break 711 values,weights = self.read_file(path) 712 if values ==None and weights==None: 713 return 714 import math 715 disp_ph.set_weights( values, weights) 716 disp_th.set_weights( values, weights) 717 718 if self.theta_cb !=None: 719 angle= self.theta_cb.GetLabelText() 720 n=0 721 self.disp_list=self.model.getDispParamList() 722 if angle.lower().count("theta")>0: 723 for param in self.model.getParamList(): 724 if not param in self.disp_list and param.lower().count("theta")>0: 725 self.model.set_dispersion(param, disp_th) 726 self.model.dispersion[param]['npts'] = len(values) 727 n+=1 728 729 if n ==0: 730 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 731 " Model contains no theta distribution")) 732 else: 733 self._draw_model() 734 735 736 def select_disp_angle(self, event): 737 if not self.phi_cb.GetValue(): 738 return 739 path = self._selectDlg() 740 dispersion=None 741 742 for key, value in self.polydisp.iteritems(): 743 if value =="MyModel": 744 disp_ph = key() 745 disp_th = key() 746 747 break 748 try: 749 values,weights = self.read_file(path) 750 except: 623 751 raise 624 625 def set_panel_dispers(self, disp_list, type="GaussianModel" ): 752 753 if values ==None and weights==None: 754 return 755 import math 756 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 757 " Costumized Distribution: %s"% path)) 758 759 disp_ph.set_weights( values, weights) 760 disp_th.set_weights( values, weights) 761 762 763 764 if self.theta_cb !=None: 765 angle= self.phi_cb.GetLabelText() 766 n=0 767 print "hello1",self.model.runXY([0.01,0.01]) 768 self.disp_list=self.model.getDispParamList() 769 name= "phi" 770 if angle.lower().count(name)>0: 771 for param in self.model.getParamList(): 772 if not param in self.disp_list and param.lower().count(name)>0: 773 self.model.set_dispersion(param, disp_th) 774 print "para, th",param, disp_th 775 #self.model.dispersion[param]['npts'] = len(values) 776 n+=1 777 print "model dispers list",self.model.getDispParamList() 778 if n ==0: 779 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 780 " Model contains no %s distribution"%name)) 781 else: 782 print "hello2",self.model.runXY([0.01,0.01]) 783 #self._draw_model() 784 qmin=self.qmin_x 785 qmax=self.qmax_x 786 qstep= self.num_points 787 x= numpy.linspace(start= -1*qmax, 788 stop= qmax, 789 num= qstep, 790 endpoint=True ) 791 y = numpy.linspace(start= -1*qmax, 792 stop= qmax, 793 num= qstep, 794 endpoint=True ) 795 output= numpy.zeros([len(x),len(y)]) 796 for i_x in range(int(len(x))): 797 for i_y in range(int(len(y))): 798 if (x[i_x]*x[i_x]+y[i_y]*y[i_y]) \ 799 < qmin * qmin: 800 output[i_x] [i_y]=0 801 else: 802 value = self.model.runXY([x[i_x], y[i_y]]) 803 output[i_x] [i_y]=value 804 print"modelpage", output 805 self.manager.complete( output=output, elapsed=None, model=self.model, qmin=qmin, qmax=qmax,qstep=qstep) 806 #self._draw_model() 807 808 809 810 def set_panel_dispers(self, disp_list, type="GaussianModel" ): 626 811 627 812 self.fittable_param=[] 628 813 self.fixed_param=[] 629 814 630 815 ix=0 631 816 iy=1 632 817 ### this will become a separate method 633 if type== "MyModel": 634 635 self.sizer8.Clear(True) 636 path = self._selectDlg() 637 dispersion=None 638 for key, value in self.polydisp.iteritems(): 639 if value =="MyModel": 640 dispersion= key() 641 break 642 values,weights = self.read_file(path) 643 dispersion.set_weights( values, weights) 644 print "sipersion model", dispersion.value 645 for param in self.model.dispersion.keys(): 646 print 647 print "on MyModel disp",dispersion,param, self.model.set_dispersion(param, dispersion) 648 649 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 650 " Selected Distribution: %s"%path)) 651 818 if type== "Select customized Model": 819 ix=0 820 iy=1 821 self.sizer8.Clear(True) 822 disp1 = wx.StaticText(self, -1, 'Array Dispersion') 823 self.sizer8.Add(disp1,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 824 825 ix+=1 826 self.theta_cb = wx.CheckBox(self, -1,"Theta ", (10, 10)) 827 wx.EVT_CHECKBOX(self, self.theta_cb.GetId(), self.select_disp_angle) 828 self.sizer8.Add(self.theta_cb,(iy, ix),(1,1),\ 829 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 830 ix+=1 831 self.phi_cb = wx.CheckBox(self, -1,"Phi", (10, 10)) 832 wx.EVT_CHECKBOX(self, self.phi_cb.GetId(), self.select_disp_angle) 833 self.sizer8.Add(self.phi_cb,(iy, ix),(1,1),\ 834 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 835 836 ix =0 837 iy +=1 838 self.sizer8.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 839 self.vbox.Layout() 840 self.SetScrollbars(20,20,55,40) 841 self.Layout() 842 self.parent.GetSizer().Layout() 843 652 844 if type== "GaussianModel" : 653 print "went here" 654 845 655 846 self.sizer8.Clear(True) 656 847 disp = wx.StaticText(self, -1, 'Dispersion') … … 738 929 self.parent.GetSizer().Layout() 739 930 740 931 def checkFitValues(self,val_min, val_max): 932 """ 933 Check the validity of input values 934 """ 935 flag = True 936 min_value = val_min.GetValue() 937 max_value = val_max.GetValue() 938 # Check for possible values entered 939 if min_value.lstrip().rstrip() =="-inf": 940 min_value= -numpy.inf 941 if max_value.lstrip().rstrip() =="+inf": 942 max_value= numpy.inf 943 if min_value==-numpy.inf and max_value== numpy.inf: 944 val_min.SetBackgroundColour(wx.WHITE) 945 val_min.Refresh() 946 val_max.SetBackgroundColour(wx.WHITE) 947 val_max.Refresh() 948 return flag 949 elif max_value== numpy.inf: 950 try: 951 float(min_value) 952 val_min.SetBackgroundColour(wx.WHITE) 953 val_min.Refresh() 954 except: 955 flag = False 956 val_min.SetBackgroundColour("pink") 957 val_min.Refresh() 958 return flag 959 elif min_value==-numpy.inf: 960 try: 961 float(max_value) 962 val_max.SetBackgroundColour(wx.WHITE) 963 val_max.Refresh() 964 except: 965 flag = False 966 val_max.SetBackgroundColour("pink") 967 val_max.Refresh() 968 return flag 969 else: 970 if (float(min_value)< float(max_value)): 971 val_min.SetBackgroundColour(wx.WHITE) 972 val_min.Refresh() 973 else: 974 flag = False 975 val_min.SetBackgroundColour("pink") 976 val_min.Refresh() 977 return flag 741 978 742 979 … … 755 992 name=str(item[0].GetLabelText()) 756 993 value= float(item[1].GetValue()) 994 757 995 #print "model para", name,value 758 996 # If the value of the parameter has changed, … … 789 1027 name=str(item[0].GetLabelText()) 790 1028 value= float(item[1].GetValue()) 1029 param_min= item[4].GetValue() 1030 param_max= item[5].GetValue() 791 1031 #print " fittable model para", name,value 792 1032 # If the value of the parameter has changed, … … 796 1036 self.model.setParam(name,value) 797 1037 is_modified = True 1038 if self.checkFitValues(item[4], item[5]): 1039 if param_min.lstrip().rstrip()== "-inf": 1040 param_min=None 1041 else: 1042 param_min=float(param_min) 1043 if param_max.lstrip().rstrip() =="+inf": 1044 param_max=None 1045 else: 1046 param_max=float(param_max) 1047 if param_min != self.model.details[name][1]: 1048 self.model.details[name][1]= param_min 1049 is_modified = True 1050 if param_max != self.model.details[name][2]: 1051 self.model.details[name][2]= param_max 1052 is_modified = True 1053 798 1054 except: 799 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 800 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 1055 print item[4].GetValue(),item[5].GetValue() 1056 raise 1057 #wx.PostEvent(self.parent.parent, StatusEvent(status=\ 1058 # "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 801 1059 802 1060 # Here we should check whether the boundaries have been modified. … … 847 1105 for item in self.parameters: 848 1106 item[0].SetValue(True) 849 list= [item[0],item[1],item[2],item[3] ]1107 list= [item[0],item[1],item[2],item[3],item[4],item[5]] 850 1108 self.param_toFit.append(list ) 851 1109 if len(self.fittable_param)>0: -
sansview/perspectives/fitting/simfitpage.py
r2fe03d5 r51d47b5 21 21 """ 22 22 self.parent = parent 23 #self.page_finder = page_finder 24 self.page_finder={} 23 25 self.sizer3 = wx.GridBagSizer(5,5) 24 26 self.sizer1 = wx.GridBagSizer(5,5) … … 51 53 self.model_list=[] 52 54 self.model_toFit=[] 53 self.page_finder={}54 55 56 #self.add_model(self.page_finder) 55 57 self.vbox.Layout() 56 58 self.vbox.Fit(self) … … 64 66 for page in self.page_finder.iterkeys(): 65 67 page.set_model_parameter() 66 67 #if len(self.model_toFit) ==1 :68 # self.manager._on_single_fit()69 # print "simfitpage: when here"70 68 if len(self.model_toFit) >= 1 : 71 69 self._onTextEnter() … … 84 82 """ 85 83 self.manager = manager 86 84 self.add_model( self.manager.page_finder) 87 85 88 86 def select_all_model_name(self,event): … … 125 123 iy = 1 126 124 list=[] 125 # if len(self.page_finder)>0: 127 126 for page, value in page_finder.iteritems(): 128 127 try: … … 254 253 self.params.append(self.parser_helper(value)) 255 254 except: 256 raise255 #raise 257 256 wx.PostEvent(self.parent.Parent, StatusEvent(status="Constraint Error: %s" % sys.exc_value)) 258 257 #print "simfitpage: self.params",self.params 259 260 258 def new_parser_helper(self,value): 259 """ 260 @return param:a list containing the name of a model ,its parameters 261 value and name extracted from the constrainst controlbox 262 """ 263 from sans.guiframe import utils 264 mylist=["=","<",">","<=", ">="] 265 for item in mylist: 266 if utils.look_for_tag( value,str(item))[0]: 267 print "went here" 268 model_param = utils.split_text(str(item), value,1) 269 param_name = model_param[0] 270 param_value = model_param[1] 271 print "simpage",utils.look_for_tag(param_name,"\.")[0] 272 if utils.look_for_tag(param_name,"\.")[0]: 273 param_names = utils.split_text("\.",param_name,1) 274 model_name = param_names[0] 275 param_name = param_names[1] 276 ##### just added 277 print "simfitpage: param name",model_name,param_name 278 279 param=[str(model_name),param_name,str(param_value),"="] 280 #print "simfitpage: param",param 281 return param 282 else: 283 #raise ValueError,"cannot evaluate this expression" 284 wx.PostEvent(self.parent.Parent, 285 StatusEvent(status="cannot evaluate this expression")) 286 return 287 elif utils.look_for_tag( value,"<")[0]: 288 model_param = utils.split_text("<", value,2) 289 if len(model_param)== 2: 290 try: 291 param_name = str(model_param[0]) 292 param_value = float(model_param[1]) 293 param=[str(model_name),param_name,param_value,"<"] 294 #print "simfitpage: param",param 295 return param 296 except: 297 wx.PostEvent(self.parent.Parent, StatusEvent(status="\ 298 could read this expression%s" % sys.exc_value)) 299 return 300 else: 301 #raise ValueError,"Missing '=' in expression" 302 wx.PostEvent(self.parent.Parent, StatusEvent(status="Missing '=' in expression")) 303 304 261 305 262 306 def parser_helper(self,value): … … 283 327 return param 284 328 else: 285 raise ValueError,"cannot evaluate this expression" 329 #raise ValueError,"cannot evaluate this expression" 330 wx.PostEvent(self.parent.Parent, 331 StatusEvent(status="cannot evaluate this expression")) 286 332 return 287 333 else: 288 raise ValueError,"Missing '=' in expression" 334 #raise ValueError,"Missing '=' in expression" 335 wx.PostEvent(self.parent.Parent, StatusEvent(status="Missing '=' in expression")) 289 336 290 337
Note: See TracChangeset
for help on using the changeset viewer.