Changeset ed2ea6a in sasview
- Timestamp:
- Feb 27, 2009 8:53: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:
- b491d6e
- Parents:
- 6d920cd
- Location:
- sansview/perspectives/fitting
- Files:
-
- 1 added
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fit_thread.py
rc138160 red2ea6a 8 8 DEFAULT_BEAM = 0.005 9 9 import time 10 11 import thread12 print "main",thread.get_ident()13 14 10 15 11 class ConsoleUpdate(FitHandler): … … 53 49 54 50 wx.PostEvent(self.parent, StatusEvent(status=\ 55 "%d%% complete ..."%(p) ))51 "%d%% complete ..."%(p),type="update")) 56 52 57 53 # Update percent complete … … 61 57 if dt > self.progress_delta: 62 58 if 1 <= dp <= 2: 63 print "%d%% complete"%p64 59 self.progress_percent = p 65 60 self.progress_time = t 66 61 wx.PostEvent(self.parent, StatusEvent(status=\ 67 "%d%% complete ..."%(p) ))62 "%d%% complete ..."%(p),type="update")) 68 63 69 64 elif 2 < dp <= 5: 70 65 if p//5 != self.progress_percent//5: 71 print "%d%% complete"%(5*(p//5))72 66 wx.PostEvent(self.parent, StatusEvent(status=\ 73 "%d%% complete ..."%(5*(p//5)) ))67 "%d%% complete ..."%(5*(p//5)),type="update")) 74 68 self.progress_percent = p 75 69 self.progress_time = t 76 70 else: 77 71 if p//10 != self.progress_percent//10: 78 print "%d%% complete"%(10*(p//10))79 80 72 self.progress_percent = p 81 73 self.progress_time = t 82 74 wx.PostEvent(self.parent, StatusEvent(status=\ 83 "%d%% complete ..."%(10*(p//10)) ))75 "%d%% complete ..."%(10*(p//10)),type="update")) 84 76 85 77 def improvement(self): … … 107 99 108 100 class FitThread(CalcThread): 109 """ Compute 2D data"""101 """Thread performing the fit """ 110 102 111 103 def __init__(self,parent, fn,pars=None,cpage=None, qmin=None,qmax=None,ymin=None, ymax=None, … … 135 127 "Start the computation ",curr_thread=self,type="start")) 136 128 def isquit(self): 129 """ 130 @raise KeyboardInterrupt: when the thread is interrupted 131 """ 137 132 try: 138 133 CalcThread.isquit(self) 139 134 except KeyboardInterrupt: 140 #printEVT("Calc %s interrupted" % self.model.name)141 135 wx.PostEvent(self.parent, StatusEvent(status=\ 142 "Calc %g interrupted" % time.time())) 143 136 "Calc %g interrupted")) 144 137 raise KeyboardInterrupt 145 138 146 139 def update(self): 147 print "updatting" 148 elapsed = time.time()-self.starttime 140 """ 141 Is called when values of result are available 142 """ 149 143 wx.PostEvent(self.parent, StatusEvent(status="Computing \ 150 144 ... " ,curr_thread=self,type="update")) 151 145 152 146 def compute(self): 147 """ 148 Perform a fit 149 """ 153 150 try: 154 151 self.starttime = time.time() 152 #Sending a progess message to the status bar 155 153 wx.PostEvent(self.parent, StatusEvent(status=\ 156 154 "Computing . ...",curr_thread=self,type="progress")) 155 #Handler used for park engine displayed message 157 156 handler= ConsoleUpdate(parent= self.parent,improvement_delta=0.1) 157 #Result from the fit 158 158 result = self.fitter.fit(handler= handler) 159 print "result", result 160 161 print "in my compute function" 159 162 160 elapsed = time.time()-self.starttime 163 161 self.complete(result= result, … … 174 172 # Thread was interrupted, just proceed and re-raise. 175 173 # Real code should not print, but this is an example... 176 print "Thread stopped. "177 174 raise 178 175 except: -
sansview/perspectives/fitting/fitpage1D.py
r169fb5f red2ea6a 41 41 #panel interface 42 42 self.vbox = wx.BoxSizer(wx.VERTICAL) 43 #self.sizer10 = wx.GridBagSizer(5,5)43 44 44 self.sizer9 = wx.GridBagSizer(5,5) 45 45 self.sizer8 = wx.GridBagSizer(5,5) … … 253 253 iy+=1 254 254 self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 255 #----------sizer 10 draw------------------------------------------------------ 256 """ 257 id = wx.NewId() 258 self.btClose =wx.Button(self,id,'Close') 259 self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id) 260 self.btClose.SetToolTipString("Close page.") 261 262 ix= 3 263 iy= 1 264 self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 265 ix +=1 266 self.sizer10.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 267 ix =0 268 iy+=1 269 self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 270 """ 255 271 256 # contains link between model ,all its parameters, and panel organization 272 257 self.parameters=[] … … 349 334 350 335 flag=self.checkFitRange() 351 print "flag", flag336 #print "flag", flag 352 337 if flag== True: 353 338 try: -
sansview/perspectives/fitting/fitpanel.py
r3199b59 red2ea6a 64 64 def onClosePage(self, event): 65 65 """ 66 self.ToggleWindowStyle(wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)67 #print "went here",self.get_current_page(), self.GetPage(0)68 #event.Skip()69 if self.GetPageCount() <= 2:70 #print "wente here"71 72 # Prevent last tab from being closed73 self.ToggleWindowStyle(~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)74 66 """ 75 67 selected_page = self.GetPage(self.GetSelection()) … … 93 85 94 86 if selected_page.name== self.draw_model_name: 95 print "went here"87 #print "went here" 96 88 self.draw_model_name=None 97 89 self.model_page=None … … 234 226 selected on that page. remove its reference into page_finder (fitting module) 235 227 """ 236 print "model page", page_number, page, self.draw_model_name228 #print "model page", page_number, page, self.draw_model_name 237 229 if page!=None and page_number!=None: 238 230 i=self.DeletePage(page_number) … … 242 234 self.model_page=None 243 235 self.draw_model_name=None 244 print"self.draw_model_name",self.draw_model_name236 #print"self.draw_model_name",self.draw_model_name 245 237 return 246 238 try: -
sansview/perspectives/fitting/fitting.py
rc98b1d5 red2ea6a 4 4 5 5 from copy import deepcopy 6 from danse.common.plottools.plottables import Data1D, Theory1D,Data2D 7 from danse.common.plottools.PlotPanel import PlotPanel 6 from danse.common.plottools.plottables import Theory1D,Data2D 8 7 from sans.guicomm.events import NewPlotEvent, StatusEvent 9 from sans.guicomm.events import EVT_SLICER_PANEL,E VT_MODEL2D_PANEL,ERR_DATA10 11 from sans.fit.AbstractFitEngine import Model ,FitData1D,FitData2D#,Data,8 from sans.guicomm.events import EVT_SLICER_PANEL,ERR_DATA 9 10 from sans.fit.AbstractFitEngine import Model 12 11 from fitproblem import FitProblem 13 12 from fitpanel import FitPanel 14 13 from fit_thread import FitThread 15 import models #,modelpage14 import models 16 15 import fitpage1D 17 #import park 16 18 17 DEFAULT_BEAM = 0.005 19 18 DEFAULT_QMIN = 0.0 20 19 DEFAULT_QMAX = 0.1 21 20 DEFAULT_NPTS = 50 22 import time23 import thread24 print "main",thread.get_ident()25 21 26 22 class Plugin: … … 34 30 ## Reference to the parent window 35 31 self.parent = None 32 #Provide list of models existing in the application 36 33 self.menu_mng = models.ModelManager() 37 34 ## List of panels for the simulation perspective (names) 38 35 self.perspective = [] 36 #list of panel to send to guiframe 39 37 self.mypanels=[] 38 # reference to the current running thread 40 39 self.calc_thread = None 41 self.done = False42 40 # Start with a good default 43 41 self.elapsed = 0.022 42 # the type of optimizer selected, park or scipy 44 43 self.fitter = None 45 46 #Flag to let the plug-in know that it is running standalone 44 #Flag to let the plug-in know that it is running stand alone 47 45 self.standalone=True 48 46 ## Fit engine 49 47 self._fit_engine = 'scipy' 50 self.enable_model2D=False 51 # list of selcted data 48 #List of selected data 52 49 self.selected_data_list=[] 53 50 # Log startup … … 55 52 # model 2D view 56 53 self.model2D_id=None 54 #keep reference of the simultaneous fit page 57 55 self.sim_page=None 56 #dictionary containing data name and error on dy of that data 58 57 self.err_dy={} 59 58 60 59 def _on_data_error(self, event): 60 """ 61 receives and event from plotting plu-gins to store the data name and 62 their errors of y coordinates for 1Data hide and show error 63 """ 61 64 self.err_dy= event.err_dy 62 65 … … 68 71 @ return : list of information to populate the main menu 69 72 """ 70 self.parent.Bind(EVT_MODEL2D_PANEL, self._on_model2D_show)71 73 #Menu for fitting 72 74 self.menu1 = wx.Menu() … … 94 96 95 97 def on_add_sim_page(self, event): 98 """ 99 """ 96 100 self.sim_page= self.fit_panel.add_sim_page() 97 101 self.sim_page.add_model(self.page_finder) … … 113 117 114 118 115 116 117 119 def get_context_menu(self, graph=None): 118 120 """ … … 160 162 self.mypanels.append(self.fit_panel) 161 163 return self.mypanels 162 163 164 def _on_model2D_show(self, event ): 165 print "model2D get the id ", event.id 166 164 167 165 168 166 def _on_slicer_event(self, event): 169 print "fitting:slicer event ", event.panel 167 """ 168 """ 169 #print "fitting:slicer event ", event.panel 170 170 if event.panel!=None: 171 171 new_panel = event.panel … … 178 178 new_panel 179 179 self.mypanels.append(new_panel) 180 return 180 return 181 182 181 183 def _on_show_panel(self, event): 182 184 print "_on_show_panel: fitting" 183 185 186 184 187 def get_perspective(self): 185 188 """ … … 205 208 self.parent.set_perspective(self.perspective) 206 209 210 207 211 def copy_data(self, item, dy): 212 """ 213 """ 208 214 detector=None 209 215 source=None … … 224 230 data.source= source 225 231 return data 232 226 233 227 234 def _onSelect(self,event): … … 253 260 item.__class__.__name__ is "Data2D": 254 261 #find a name for the page created for notebook 255 print "fitting", self.panel262 #print "fitting", self.panel 256 263 try: 257 264 … … 273 280 wx.PostEvent(self.parent, StatusEvent(status="Page was already Created")) 274 281 except: 275 raise 276 #wx.PostEvent(self.parent, StatusEvent(status="Creating Fit page: %s"\ 277 #%sys.exc_value)) 282 #raise 283 wx.PostEvent(self.parent, StatusEvent(status="Creating Fit page: %s"\ 284 %sys.exc_value)) 285 return 278 286 279 287 … … 311 319 list=value.get_model() 312 320 model=list[0] 313 print "fitting",model.name,modelname, values321 #print "fitting",model.name,modelname, values 314 322 if model.name== modelname: 315 323 value.set_model_param(names,values) … … 360 368 model.setParam(name,result.pvec) 361 369 else: 362 print "fitting result : chisqr",result.fitness363 print "fitting result : pvec",result.pvec364 print "fitting result : stderr",result.stderr370 #print "fitting result : chisqr",result.fitness 371 #print "fitting result : pvec",result.pvec 372 #print "fitting result : stderr",result.stderr 365 373 #model.setParam(name,result.pvec[i]) 366 374 # print "fitting: single fit", name, result.pvec[i] … … 374 382 xmin=xmin, xmax=xmax,title=None) 375 383 except: 376 raise 377 #wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value)) 378 #return 384 #raise 385 wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value)) 386 return 387 379 388 380 389 def _simul_fit_completed(self,result,qmin,qmax, elapsed,pars=None,cpage=None, … … 394 403 wx.PostEvent(self.parent, StatusEvent(status="Simultaneous fit \ 395 404 complete ", type="stop")) 396 print "result",cpage,str(result),result.parameters,result.fitness,result.stderr405 #print "result",cpage,str(result),result.parameters,result.fitness,result.stderr 397 406 398 407 try: … … 426 435 wx.PostEvent(self.parent, StatusEvent(status="Simultaneous Fitting error: %s" % sys.exc_value)) 427 436 return 437 438 428 439 def stop_fit(self): 440 """ 441 """ 429 442 if self.calc_thread != None and self.calc_thread.isrunning(): 430 443 #self.calc_thread.interrupt() 431 444 self.calc_thread.stop() 432 445 wx.PostEvent(self.parent, StatusEvent(status="Fitting \ 433 is cancelled" , type="stop")) 446 is cancelled" , type="stop")) 447 448 434 449 def _on_single_fit(self,id=None,qmin=None, qmax=None,ymin=None, ymax=None,xmin=None,xmax=None): 435 450 """ … … 526 541 self.calc_thread.queue() 527 542 self.calc_thread.ready(2.5) 528 #while not self.done: 529 #print "when here" 530 # time.sleep(1) 531 532 543 533 544 except: 534 545 wx.PostEvent(self.parent, StatusEvent(status="Single Fit error: %s" % sys.exc_value)) … … 585 596 586 597 self.fitter.set_model(new_model, self.fit_id, pars) 587 print "sim-->model",metadata,model,self.fit_id, pars598 #print "sim-->model",metadata,model,self.fit_id, pars 588 599 dy=[] 589 600 x=[] … … 603 614 metadata.x=x 604 615 self.fitter.set_data(metadata,self.fit_id,qmin,qmax,ymin,ymax) 605 print "sim---->value of problem",value.get_scheduled()616 #print "sim---->value of problem",value.get_scheduled() 606 617 self.fitter.select_problem_for_fit(Uid=self.fit_id,value=value.get_scheduled()) 607 618 self.fit_id += 1 … … 646 657 647 658 def _onset_engine(self,event): 648 """ set engine to scipy""" 659 """ 660 set engine to scipy 661 """ 649 662 if self._fit_engine== 'park': 650 663 self._on_change_engine('scipy') … … 670 683 name = evt.name 671 684 672 print "name fitting", name685 #print "name fitting", name 673 686 #sim_page=self.fit_panel.GetPage(1) 674 687 sim_page=self.sim_page … … 695 708 self.sim_page.add_model(self.page_finder) 696 709 697 def set_smearer(self,smearer): 698 current_pg=self.fit_panel.get_current_page() 699 self.page_finder[current_pg].set_smearer(smearer) 710 def set_smearer(self,smearer): 711 """ 712 713 """ 714 current_pg=self.fit_panel.get_current_page() 715 self.page_finder[current_pg].set_smearer(smearer) 700 716 701 717 def redraw_model(self,qmin= None,qmax= None): … … 725 741 model=list[0] 726 742 break 727 print "model in fitting",model743 #print "model in fitting",model 728 744 if data!=None and data.__class__.__name__ != 'Data2D': 729 745 theory = Theory1D(x=[], y=[]) 730 746 theory.name = model.name 731 747 theory.group_id = data.group_id 732 """733 if hasattr(data, "id"):734 import string735 if string.find("Model",data.id )!=None:736 #allow plotting on the same panel737 theory.id =str(data.id )+" "+str(self.index_theory)738 self.index_theory +=1739 else:740 """741 748 theory.id = "Model" 742 749 … … 777 784 wx.PostEvent(self.parent, StatusEvent(status="fitting \ 778 785 skipping point x %g %s" %(qmin, sys.exc_value)) ) 786 779 787 wx.PostEvent(self.parent, NewPlotEvent(plot=theory, 780 788 title=str(data.name))) … … 841 849 if hasattr(evt.model, "name"): 842 850 name = evt.model.name 843 print "on model menu", name851 #print "on model menu", name 844 852 model=evt.model() 845 853 description=model.description … … 869 877 def _draw_model1D(self,model,name,description=None, enable1D=True, 870 878 qmin=DEFAULT_QMIN, qmax=DEFAULT_QMAX, qstep=DEFAULT_NPTS): 879 """ 880 881 """ 871 882 872 883 if enable1D: … … 894 905 wx.PostEvent(self.parent, StatusEvent(status="Draw model 1D error: %s" % sys.exc_value)) 895 906 #raise 907 return 896 908 else: 897 909 for i in range(xlen): … … 899 911 try: 900 912 new_plot = Theory1D(x, y) 901 print "draw model 1D", name913 #print "draw model 1D", name 902 914 new_plot.name = name 903 915 new_plot.xaxis("\\rm{Q}", 'A^{-1}') … … 914 926 #raise 915 927 wx.PostEvent(self.parent, StatusEvent(status="Draw model 1D error: %s" % sys.exc_value)) 928 return 929 930 931 916 932 def update(self, output,time): 933 """ 934 """ 917 935 pass 918 936 919 937 def complete(self, output, elapsed, model, qmin, qmax,qstep=DEFAULT_NPTS): 920 938 """ 939 """ 921 940 wx.PostEvent(self.parent, StatusEvent(status="Calc \ 922 941 complete !" , type="stop")) … … 1007 1026 try: 1008 1027 from sans.guiframe.model_thread import Calc2D 1009 print "in draw model 2d ",self.model1028 # print "in draw model 2d ",self.model 1010 1029 self.calc_thread = Calc2D(parent =self.parent,x=x, 1011 1030 y=y,model= self.model, -
sansview/perspectives/fitting/modelpage.py
r7d680c7 red2ea6a 738 738 angle= self.phi_cb.GetLabelText() 739 739 n=0 740 print "hello1",self.model.runXY([0.01,0.01])740 #print "hello1",self.model.runXY([0.01,0.01]) 741 741 self.disp_list=self.model.getDispParamList() 742 742 name= "phi" … … 748 748 #self.model.dispersion[param]['npts'] = len(values) 749 749 n+=1 750 print "model dispers list",self.model.getDispParamList()750 #print "model dispers list",self.model.getDispParamList() 751 751 if n ==0: 752 752 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 753 753 " Model contains no %s distribution"%name)) 754 754 else: 755 print "hello2",self.model.runXY([0.01,0.01])755 #print "hello2",self.model.runXY([0.01,0.01]) 756 756 #self._draw_model() 757 757 qmin=self.qmin_x … … 775 775 value = self.model.runXY([x[i_x], y[i_y]]) 776 776 output[i_x] [i_y]=value 777 print"modelpage", output777 #print"modelpage", output 778 778 self.manager.complete( output=output, elapsed=None, model=self.model, qmin=qmin, qmax=qmax,qstep=qstep) 779 779 #self._draw_model() … … 782 782 783 783 def set_panel_dispers(self, disp_list, type="GaussianModel" ): 784 """ 785 """ 784 786 785 787 self.fittable_param=[] … … 958 960 959 961 def set_model_parameter(self): 962 """ 963 """ 960 964 if len(self.parameters) !=0 and self.model !=None: 961 965 # Flag to register when a parameter has changed. … … 975 979 976 980 except: 977 raise981 #raise 978 982 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 979 983 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 984 return 985 980 986 981 987 for item in self.fixed_param: … … 1009 1015 self.model.setParam(name,value) 1010 1016 is_modified = True 1011 """ 1012 #if self.checkFitValues(item[4], item[5]): 1013 # if param_min.lstrip().rstrip()== "-inf": 1014 param_min=None 1015 else: 1016 param_min=float(param_min) 1017 if param_max.lstrip().rstrip() =="+inf": 1018 param_max=None 1019 else: 1020 param_max=float(param_max) 1021 if param_min != self.model.details[name][1]: 1022 self.model.details[name][1]= param_min 1023 is_modified = True 1024 if param_max != self.model.details[name][2]: 1025 self.model.details[name][2]= param_max 1026 is_modified = True 1027 """ 1017 1028 1018 except: 1029 #print item[4].GetValue(),item[5].GetValue() 1030 raise 1031 #wx.PostEvent(self.parent.parent, StatusEvent(status=\ 1032 # "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 1033 1019 #raise 1020 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 1021 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 1022 return 1023 1024 1034 1025 # Here we should check whether the boundaries have been modified. 1035 1026 # If qmin and qmax have been modified, update qmin and qmax and … … 1067 1058 1068 1059 def select_param(self,event): 1060 """ 1061 1062 """ 1069 1063 pass 1070 1064 def select_all_param(self,event): 1065 """ 1066 1067 """ 1071 1068 pass 1072 1069 def select_all_param_helper(self): -
sansview/perspectives/fitting/simfitpage.py
r51d47b5 red2ea6a 265 265 for item in mylist: 266 266 if utils.look_for_tag( value,str(item))[0]: 267 print "went here"267 #print "went here" 268 268 model_param = utils.split_text(str(item), value,1) 269 269 param_name = model_param[0] 270 270 param_value = model_param[1] 271 print "simpage",utils.look_for_tag(param_name,"\.")[0]271 #print "simpage",utils.look_for_tag(param_name,"\.")[0] 272 272 if utils.look_for_tag(param_name,"\.")[0]: 273 273 param_names = utils.split_text("\.",param_name,1) … … 275 275 param_name = param_names[1] 276 276 ##### just added 277 print "simfitpage: param name",model_name,param_name277 #print "simfitpage: param name",model_name,param_name 278 278 279 279 param=[str(model_name),param_name,str(param_value),"="] … … 301 301 #raise ValueError,"Missing '=' in expression" 302 302 wx.PostEvent(self.parent.Parent, StatusEvent(status="Missing '=' in expression")) 303 303 304 304 305 305 … … 334 334 #raise ValueError,"Missing '=' in expression" 335 335 wx.PostEvent(self.parent.Parent, StatusEvent(status="Missing '=' in expression")) 336 336 337 337 338 338
Note: See TracChangeset
for help on using the changeset viewer.