Changeset 67e258c in sasview
- Timestamp:
- Oct 21, 2010 12:25:55 PM (14 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:
- 4628e31
- Parents:
- b2f25dc5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fitting.py
rfb59ed9 r67e258c 495 495 ## redraw the model with data smeared 496 496 497 smear = self.page_finder[self.current_pg].get_smearer()498 if model != None:499 self.draw_model( model=model, data= data, smearer=smear,500 qmin= qmin, qmax=qmax)501 502 def draw_model(self, model, data= None,smearer=None,503 enable1D= True, enable2D=False,504 qmin= DEFAULT_QMIN, qmax= DEFAULT_QMAX, qstep=DEFAULT_NPTS):497 smear = self.page_finder[self.current_pg].get_smearer() 498 if model != None: 499 self.draw_model(model=model, data=data, smearer=smear, 500 qmin=qmin, qmax=qmax) 501 502 def draw_model(self, model, data=None, smearer=None, 503 enable1D=True, enable2D=False, 504 qmin=DEFAULT_QMIN, qmax=DEFAULT_QMAX, qstep=DEFAULT_NPTS): 505 505 """ 506 506 Draw model. … … 517 517 518 518 """ 519 if data.__class__.__name__ != "Data2D":519 if data.__class__.__name__ != "Data2D": 520 520 ## draw model 1D with no loaded data 521 self._draw_model1D( model= model, data= data, 522 enable1D=enable1D, 523 smearer= smearer, 524 qmin= qmin, qmax= qmax, qstep= qstep ) 521 self._draw_model1D(model=model, 522 data=data, 523 enable1D=enable1D, 524 smearer=smearer, 525 qmin=qmin, 526 qmax=qmax, 527 qstep=qstep) 525 528 else: 526 529 ## draw model 2D with no initial data 527 530 self._draw_model2D(model=model, 528 data =data,529 enable2D=enable2D,530 smearer=smearer,531 532 533 531 data=data, 532 enable2D=enable2D, 533 smearer=smearer, 534 qmin=qmin, 535 qmax=qmax, 536 qstep=qstep) 534 537 535 538 def onFit(self): … … 538 541 """ 539 542 ## count the number of fitproblem schedule to fit 540 fitproblem_count = 0543 fitproblem_count = 0 541 544 for value in self.page_finder.itervalues(): 542 if value.get_scheduled() ==1:545 if value.get_scheduled() == 1: 543 546 fitproblem_count += 1 544 547 545 548 ## if simultaneous fit change automatically the engine to park 546 if fitproblem_count > 1:549 if fitproblem_count > 1: 547 550 self._on_change_engine(engine='park') 548 551 … … 550 553 551 554 from sans.fit.Fitting import Fit 552 self.fitter = Fit(self._fit_engine)553 554 if self._fit_engine =="park":555 engineType ="Simultaneous Fit"555 self.fitter = Fit(self._fit_engine) 556 557 if self._fit_engine == "park": 558 engineType = "Simultaneous Fit" 556 559 else: 557 engineType ="Single Fit"560 engineType = "Single Fit" 558 561 559 562 fproblemId = 0 560 self.current_pg =None563 self.current_pg = None 561 564 for page, value in self.page_finder.iteritems(): 562 565 try: 563 if value.get_scheduled() ==1:566 if value.get_scheduled() == 1: 564 567 #Get list of parameters name to fit 565 568 pars = [] … … 570 573 pars.append(name) 571 574 #Set Engine (model , data) related to the page on 572 self._fit_helper( value=value,pars=pars,573 id=fproblemId, title= engineType)575 self._fit_helper(value=value, pars=pars, 576 id=fproblemId, title=engineType) 574 577 fproblemId += 1 575 self.current_pg = page578 self.current_pg = page 576 579 except: 577 msg= "%s error: %s" % (engineType, sys.exc_value)580 msg= "%s error: %s" % (engineType, sys.exc_value) 578 581 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", 579 582 type="stop")) … … 586 589 ## perform single fit 587 590 if fitproblem_count == 1: 588 calc_fit =FitThread(parent=self.parent,591 calc_fit = FitThread(parent=self.parent, 589 592 handler = handler, 590 fn= 593 fn=self.fitter, 591 594 cpage=self.current_pg, 592 pars= 595 pars=pars, 593 596 updatefn=handler.update_fit, 594 completefn= 597 completefn=self._single_fit_completed) 595 598 else: 596 599 ## Perform more than 1 fit at the time 597 calc_fit =FitThread(parent=self.parent,600 calc_fit = FitThread(parent=self.parent, 598 601 handler=handler, 599 602 fn= self.fitter, … … 797 800 fitproblem.schedule_tofit(value) 798 801 799 def _fit_helper(self, pars,value, id, title="Single Fit " ):802 def _fit_helper(self, pars, value, id, title="Single Fit " ): 800 803 """ 801 804 helper for fitting … … 804 807 model = value.get_model() 805 808 smearer = value.get_smearer() 806 qmin 807 self.fit_id = id809 qmin, qmax = value.get_range() 810 self.fit_id = id 808 811 #Create list of parameters for fitting used 809 templist =[]812 templist = [] 810 813 811 814 try: 812 815 #Extra list of parameters and their constraints 813 listOfConstraint = []816 listOfConstraint = [] 814 817 815 818 param = value.get_model_param() 816 if len(param) >0:819 if len(param) > 0: 817 820 for item in param: 818 821 ## check if constraint 819 if item[0] != None and item[1] != None:822 if item[0] != None and item[1] != None: 820 823 listOfConstraint.append((item[0],item[1])) 821 824 822 825 #Do the single fit 823 826 self.fitter.set_model(model, self.fit_id, 824 pars, constraints =listOfConstraint)825 print "listOfConstraint",listOfConstraint826 self.fitter.set_data(data=metadata, Uid=self.fit_id,827 smearer=smearer, qmin= qmin,qmax=qmax)827 pars, constraints=listOfConstraint) 828 829 self.fitter.set_data(data=metadata, id=self.fit_id, 830 smearer=smearer, qmin=qmin, qmax=qmax) 828 831 829 self.fitter.select_problem_for_fit( Uid=self.fit_id,830 value= 832 self.fitter.select_problem_for_fit(id=self.fit_id, 833 value=value.get_scheduled()) 831 834 value.clear_model_param() 832 835 except: 833 msg= title +" error: %s" % sys.exc_value 834 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 835 return 836 836 msg = title + " error: %s" % sys.exc_value 837 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 838 837 839 def _onSelect(self,event): 838 840 """ … … 841 843 """ 842 844 self.panel = event.GetEventObject() 843 Plugin.on_perspective(self, event=event)845 Plugin.on_perspective(self, event=event) 844 846 for plottable in self.panel.graph.plottables: 845 847 if plottable.__class__.__name__ in ["Data1D", "Theory1D"]: … … 869 871 type="stop")) 870 872 return 871 if not numpy.isfinite(result.fitness) or numpy.any(result.pvec ==None )or not numpy.all(numpy.isfinite(result.pvec) ): 872 msg= "Single Fitting did not converge!!!" 873 wx.PostEvent(self.parent, StatusEvent(status=msg,type="stop")) 873 if not numpy.isfinite(result.fitness) or \ 874 numpy.any(result.pvec == None) or \ 875 not numpy.all(numpy.isfinite(result.pvec)): 876 msg = "Single Fitting did not converge!!!" 877 wx.PostEvent(self.parent, 878 StatusEvent(status=msg, type="stop")) 874 879 return 875 880 for page, value in self.page_finder.iteritems(): 876 if page ==cpage :877 model = value.get_model()881 if page == cpage : 882 model = value.get_model() 878 883 break 879 884 param_name = [] … … 882 887 param_name.append(name) 883 888 884 cpage.onsetValues(result.fitness,param_name, result.pvec,result.stderr) 889 cpage.onsetValues(result.fitness, 890 param_name, result.pvec,result.stderr) 885 891 886 892 except: 887 msg= "Single Fit completed but Following error occurred:%s"% sys.exc_value 893 msg = "Single Fit completed but Following" 894 msg += " error occurred:%s" % sys.exc_value 888 895 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", 889 896 type="stop")) 890 897 return 891 898 892 def _simul_fit_completed(self, result,pars=None,cpage=None, elapsed=None):899 def _simul_fit_completed(self, result, pars=None, cpage=None, elapsed=None): 893 900 """ 894 901 Parameter estimation completed, … … 971 978 #self.menu3.Append(event_id, new_panel.window_caption, 972 979 # "Show %s plot panel" % new_panel.window_caption) 973 # Set UIDto allow us to reference the panel later980 # Set id to allow us to reference the panel later 974 981 975 982 new_panel.uid = event_id … … 1269 1276 theory.detector= data.detector 1270 1277 theory.source= data.source 1271 theory.is_data = False1278 theory.is_data = False 1272 1279 theory.qx_data = data.qx_data 1273 1280 theory.qy_data = data.qy_data … … 1349 1356 1350 1357 except: 1351 msg= " Error occurred when drawing %s Model 2D: "%model.name 1352 msg+= " %s"%sys.exc_value 1353 wx.PostEvent( self.parent, StatusEvent(status= msg )) 1354 1355 def _draw_model1D(self, model, data=None, smearer= None, 1356 qmin=DEFAULT_QMIN, qmax=DEFAULT_QMAX, qstep= DEFAULT_NPTS,enable1D= True): 1358 msg= " Error occurred when drawing %s Model 2D: " % model.name 1359 msg+= " %s" % sys.exc_value 1360 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1361 1362 def _draw_model1D(self, model, data=None, smearer=None, 1363 qmin=DEFAULT_QMIN, qmax=DEFAULT_QMAX, 1364 qstep=DEFAULT_NPTS, enable1D=True): 1357 1365 """ 1358 1366 Draw model 1D from loaded data1D
Note: See TracChangeset
for help on using the changeset viewer.