Changeset ef8b580 in sasview
- Timestamp:
- Feb 12, 2009 12:11:08 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:
- 7983c731
- Parents:
- 3b909b7
- Location:
- sansview/perspectives/fitting
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fitpage1D.py
r1309e919 ref8b580 4 4 import numpy,math 5 5 import copy 6 import sans.models.dispersion_models 6 7 7 from sans.guicomm.events import StatusEvent 8 8 from sans.guiframe.utils import format_number … … 78 78 #---------sizer 1 draw-------------------------------- 79 79 self.DataSource =wx.StaticText(self, -1,str(data.name)) 80 self.smearer_box = wx.ComboBox(self, -1)81 wx.EVT_COMBOBOX( self.smearer_box,-1, self.onSmear )82 self.smeares= sans.models.dispersion_models.models83 i=084 self.smearer_box.SetValue(str(None))85 self.smearer_box.Insert(str(None),i)86 87 for k,v in self.smeares.iteritems():88 if str(v)=="GaussianModel":89 self.smearer_box.Insert("Gaussian Resolution",i)90 else:91 self.smearer_box.Insert(str(v),i)92 i+=193 94 80 #Filing the sizer containing data related fields 95 81 ix = 0 … … 102 88 103 89 #---------sizer 2 draw-------------------------------- 104 ix = 0105 iy = 1106 90 #set maximum range for x in linear scale 107 91 if not hasattr(self.data,"data"): #Display only for 1D data fit 92 ix = 0 93 iy = 1 108 94 # Minimum value of data 109 95 self.data_min = wx.StaticText(self, -1,str(format_number(numpy.min(data.x)))) … … 126 112 127 113 #----sizer 3 draw-------------------------------- 114 self.disable_smearer = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) 115 self.enable_smearer = wx.RadioButton(self, -1, 'Yes', (10, 30)) 116 self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.disable_smearer.GetId()) 117 self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.enable_smearer.GetId()) 128 118 ix = 0 129 119 iy = 1 … … 131 121 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 132 122 ix += 1 133 self.sizer3.Add(self.smearer_box,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 123 self.sizer3.Add(self.enable_smearer,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 124 ix += 1 125 self.sizer3.Add(self.disable_smearer,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 134 126 ix =0 135 127 iy+=1 … … 570 562 571 563 def onSmear(self, event): 572 if event.GetString()=="None": 573 self.manager.set_smearer(None) 574 575 576 if event.GetString()=="Gaussian Resolution": 564 #print "in smearer",self.enable_smearer.GetValue() 565 smear =None 566 if self.enable_smearer.GetValue(): 577 567 from DataLoader.qsmearing import smear_selection 578 568 smear =smear_selection( self.data ) 579 self.manager.set_smearer(smear) 580 # print "on smearing" 569 if smear ==None: 570 wx.PostEvent(self.manager.parent, StatusEvent(status=\ 571 "Data contains no smearing information")) 572 else: 573 wx.PostEvent(self.manager.parent, StatusEvent(status=\ 574 "Data contains smearing information")) 575 self.manager.set_smearer(smear) 576 577 578 581 579 -
sansview/perspectives/fitting/fitpanel.py
rfee6059 ref8b580 102 102 except: 103 103 name = 'Fit' 104 104 105 if self.fit_page_name != name: 105 print"went here"106 #self.count +=1107 108 106 #self.about_page.Disable() 109 107 from fitpage1D import FitPage1D 110 108 panel = FitPage1D(self,data, -1) 111 109 panel.name=name 112 m_name= "M"+str(self.count)110 #m_name= "M"+str(self.count) 113 111 panel.set_manager(self.manager) 114 112 panel.set_owner(self.event_owner) … … 118 116 self.fit_page_name = name 119 117 EVT_FIT_PAGE 120 return panel ,m_name118 return panel #,m_name 121 119 else: 122 return None , None120 return None #, None 123 121 124 122 def _help_add_model_page(self,model,description,page_title, qmin=0, qmax=0.1, npts=50): … … 137 135 self.AddPage(page=panel,caption="Model",select=True) 138 136 panel.populate_box( self.model_list_box) 139 panel.name =page_title137 panel.name = page_title 140 138 self.draw_model_name=page_title 141 139 self.model_page_number=self.GetSelection() … … 166 164 """ 167 165 print "self.draw_model_name none",self.draw_model_name 168 if self.draw_model_name ==None: 169 print "self.draw_model_name none" 170 self._help_add_model_page(model,description,page_title, qmin=qmin, qmax=qmax, npts=npts) 171 elif topmenu==True: 172 self.model_page.select_model(model, page_title) 166 if topmenu==True: 167 if self.draw_model_name ==None: 168 print "self.draw_model_name none" 169 self._help_add_model_page(model,description,page_title, qmin=qmin, qmax=qmax, npts=npts) 170 else: 171 #self.model_page.name=page_title 172 #self.draw_model_name=page_title 173 #print "wnent here self.draw_model_name ",self.draw_model_name,self.model_page.name,self.model_page 174 175 self.model_page.select_model(model, page_title) 173 176 174 177 def get_current_page(self): … … 211 214 #Delete the page from notebook 212 215 page_number = self.GetSelection() 213 print selected_page.name,self.GetPageText(page_number),self.draw_model_name216 print "on close",selected_page.name,self.GetPageText(page_number),self.draw_model_name 214 217 if selected_page.name== self.draw_model_name: 215 218 print "went here" -
sansview/perspectives/fitting/fitting.py
r2268d10 ref8b580 206 206 try: 207 207 208 page, model_name = self.fit_panel.add_fit_page(item) 208 page = self.fit_panel.add_fit_page(item) 209 #page, model_name = self.fit_panel.add_fit_page(item) 209 210 # add data associated to the page created 210 211 … … 212 213 #create a fitproblem storing all link to data,model,page creation 213 214 self.page_finder[page]= FitProblem() 214 self.page_finder[page].save_model_name(model_name)215 #self.page_finder[page].save_model_name(model_name) 215 216 self.page_finder[page].add_data(item) 216 217 wx.PostEvent(self.parent, StatusEvent(status="Page Created")) … … 310 311 311 312 cpage.onsetValues(result.fitness, result.pvec,result.stderr) 313 #title="Fitted model 2D " 312 314 self.plot_helper(currpage=cpage,qmin=qmin,qmax=qmax, 313 315 ymin=ymin, ymax=ymax, 314 xmin=xmin, xmax=xmax,title= "Fitted model 2D ")316 xmin=xmin, xmax=xmax,title=None) 315 317 except: 316 318 #raise … … 547 549 if current_pg != sim_page: 548 550 current_pg.set_panel(model) 549 model.name = self.page_finder[current_pg].get_name() 551 #model.name = self.page_finder[current_pg].get_name() 552 #print "model name", model.name 553 model.name="M"+str(self.index_model) 550 554 try: 551 555 metadata=self.page_finder[current_pg].get_data() 552 #M_name=model.name+"= "+name+"("+metadata.group_id+")" 553 M_name=model.name+"= "+name+"("+metadata.id+")" 556 M_name=model.name+"= "+name+"("+metadata.group_id+")" 554 557 except: 555 M_name=model.name+"= "+name+"("+metadata.group_id+")" 556 model.name="M"+str(self.index_model) 558 M_name=model.name+"= "+name 557 559 self.index_model += 1 560 561 558 562 # save model name 559 563 … … 598 602 theory.name = model.name 599 603 theory.group_id = data.group_id 604 """ 600 605 if hasattr(data, "id"): 601 606 import string … … 605 610 self.index_theory +=1 606 611 else: 607 theory.id = "Model" 612 """ 613 theory.id = "Model" 608 614 609 615 x_name, x_units = data.get_xaxis() -
sansview/perspectives/fitting/modelpage.py
r10c43a5 ref8b580 102 102 self.sizer4.Add(self.model_view,(iy,ix),(1,1),\ 103 103 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 104 self.model_view.Enable() 104 105 self.model_view.SetFocus() 106 105 107 #----------sizer6------------------------------------------------- 106 108 self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) … … 194 196 self.fixed_param=[] 195 197 self.fittable_param=[] 198 self.polydisp= {} 196 199 #contains link between a model and selected parameters to fit 197 200 self.param_toFit=[] … … 298 301 # set up the combox box 299 302 id = 0 303 import sans.models.dispersion_models 304 self.polydisp= sans.models.dispersion_models.models 300 305 self.disp_box = wx.ComboBox(self, -1) 301 self.disp_box.SetValue("Gaussian") 302 self.disp_box.Insert("Gaussian",int(id)) 306 self.disp_box.SetValue("GaussianModel") 307 for k,v in self.polydisp.iteritems(): 308 self.disp_box.Insert(str(v),id) 309 id+=1 303 310 wx.EVT_COMBOBOX(self.disp_box,-1, self._on_select_Disp) 304 311 self.sizer7.Add(self.disp_box,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) … … 379 386 @param model: model object 380 387 """ 381 self.model= model 382 print "select_model", model.__class__ 388 self.model = model 389 self.parent.model_page.name = name 390 self.parent.draw_model_name = name 391 392 print "select_model", self.name,model.__class__ 383 393 self.set_panel(model) 384 394 self._draw_model(name) … … 388 398 for i in range(len(items)): 389 399 print "model name",items[i],model.name, model.__class__.__name__ 390 #if items[i]==model.__class__.__name__:391 400 if items[i]==name: 392 401 self.modelbox.SetSelection(i) … … 398 407 self.disp_list should change type later .now only gaussian 399 408 """ 400 type = "Gaussian" 401 if type ==event.GetString(): 402 self.set_panel_dispers( self.disp_list,type ) 409 type =event.GetString() 410 self.set_panel_dispers( self.disp_list,type ) 403 411 404 412 def _on_select_model(self,event): … … 423 431 self.set_panel(model) 424 432 self.name= name 433 434 self.parent.model_page.name=name 435 self.parent.draw_model_name=name 425 436 #self.manager.draw_model(model, name) 426 self.enable2D=False427 self.model_view.Enable()437 #self.enable2D=False 438 #self.model_view.Enable() 428 439 self._draw_model(name) 429 440 … … 557 568 self.Layout() 558 569 self.parent.GetSizer().Layout() 559 560 561 def set_panel_dispers(self, disp_list, type="Gaussian" ): 570 def _selectDlg(self): 571 import os 572 dlg = wx.FileDialog(self, "Choose a weight file", os.getcwd(), "", "*.*", wx.OPEN) 573 path = None 574 if dlg.ShowModal() == wx.ID_OK: 575 path = dlg.GetPath() 576 dlg.Destroy() 577 return path 578 def read_file(self, path): 579 try: 580 input_f = open(path, 'r') 581 buff = input_f.read() 582 lines = buff.split('\n') 583 584 angles = [] 585 weights=[] 586 for line in lines: 587 toks = line.split() 588 if len(toks)==2: 589 try: 590 angle = float(toks[0]) 591 weight = float(toks[1]) 592 except: 593 # Skip non-data lines 594 pass 595 angles.append(angle) 596 weights.append(weight) 597 return numpy.array(angles), numpy.array(weights) 598 except: 599 raise 600 601 def set_panel_dispers(self, disp_list, type="GaussianModel" ): 562 602 563 603 self.fittable_param=[] … … 566 606 ix=0 567 607 iy=1 568 ### this will become a separate method 569 if type== "Gaussian" : 608 ### this will become a separate method 609 if type== "MyModel": 610 611 self.sizer8.Clear(True) 612 path = self._selectDlg() 613 dispersion=None 614 for key, value in self.polydisp.iteritems(): 615 if value =="MyModel": 616 dispersion= key() 617 break 618 values,weights = self.read_file(path) 619 dispersion.set_weights( values, weights) 620 print "sipersion model", dispersion.value 621 for param in self.model.dispersion.keys(): 622 print 623 print "on MyModel disp",dispersion,param, self.model.set_dispersion(param, dispersion) 624 625 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 626 " Selected Distribution: %s"%path)) 627 628 if type== "GaussianModel" : 570 629 print "went here" 630 571 631 self.sizer8.Clear(True) 572 632 disp = wx.StaticText(self, -1, 'Dispersion') … … 589 649 590 650 disp_list.sort() 591 #print disp_list,self.model.fixed,self.model.dispersion651 print disp_list,self.model.dispersion 592 652 for item in self.model.dispersion.keys(): 593 653 name1=item+".width" … … 644 704 self.sizer8.Add(Tctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 645 705 self.fixed_param.append([name3, Tctl]) 646 706 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 707 " Selected Distribution: Gaussian")) 647 708 ix =0 648 709 iy +=1 … … 652 713 self.Layout() 653 714 self.parent.GetSizer().Layout() 715 654 716 655 717 … … 747 809 qstep= self.num_points, 748 810 enable2D=self.enable2D) 749 """ 750 self.manager.draw_model(self.model, self.model.name, 751 qmin=self.qmin, qmax=self.qmax, 752 qstep= self.num_points, 753 enable2D=self.enable2D) 754 """ 811 755 812 def select_param(self,event): 756 813 pass … … 773 830 list= [item[0],item[1],item[2],item[3]] 774 831 self.param_toFit.append(list ) 775 776 if not (len(self.param_toFit ) >0):777 self.qmin.Disable()778 self.qmax.Disable()779 else:780 self.qmin.Enable()781 self.qmax.Enable()782 832 else: 783 833 for item in self.parameters: … … 786 836 item[0].SetValue(False) 787 837 self.param_toFit=[] 788 789 self.qmin.Disable() 790 self.qmax.Disable() 791 838 839 840
Note: See TracChangeset
for help on using the changeset viewer.