Changeset 6d20b46 in sasview for park_integration
- Timestamp:
- Jan 20, 2010 3:54:52 PM (15 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:
- 662da312
- Parents:
- e6b9723
- Location:
- park_integration
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/AbstractFitEngine.py
r027e8f2 r6d20b46 1 1 import logging, sys 2 import copy 3 from copy import deepcopy 2 4 import park,numpy,math, copy 3 5 from DataLoader.data_info import Data1D … … 79 81 self.pars=[] 80 82 81 83 def clone(self): 84 model = self.model.clone() 85 model.name = self.model.name 86 return Model(model) 82 87 def getParams(self,fitparams): 83 88 """ … … 337 342 Sans Assembly class a class wrapper to be call in optimizer.leastsq method 338 343 """ 339 def __init__(self,paramlist, Model=None , Data=None, curr_thread= None):340 """ 341 @param Model: the model wrapper frosans -model342 @param Data: the data wrapper for sans data343 """ 344 self.model = Model345 self.data = Data346 self.paramlist =paramlist344 def __init__(self,paramlist,model=None , data=None, curr_thread= None): 345 """ 346 @param model: the model wrapper for sans -model 347 @param data: the data wrapper for sans data 348 """ 349 self.model = model.clone() 350 self.data = deepcopy(data) 351 self.paramlist = deepcopy(paramlist) 347 352 self.curr_thread= curr_thread 348 353 self.res=[] … … 457 462 if model == None: 458 463 raise ValueError, "AbstractFitEngine: Need to set model to fit" 459 460 new_model= model 461 if not issubclass(model.__class__, Model): 462 new_model= Model(model) 464 #print "set_model",model.name 465 #new_model= deepcopy(model) 466 new_model = model.clone() 467 new_model.name = model.name 468 if not issubclass(new_model.__class__, Model): 469 new_model= Model(new_model) 463 470 464 471 if len(constraints)>0: … … 506 513 @param Uid: unique key corresponding to a fitArrange object with data 507 514 """ 515 #print "set_data",data.__class__.__name__ 508 516 if data.__class__.__name__=='Data2D': 509 517 fitdata=FitData2D(sans_data2d=data, data=data.data, err_data= data.err_data) 510 518 else: 511 519 fitdata=FitData1D(x=data.x, y=data.y , dx= data.dx,dy=data.dy,smearer=smearer) 512 520 513 521 fitdata.setFitRange(qmin=qmin,qmax=qmax) 514 522 #A fitArrange is already created but contains model only at Uid … … 578 586 """ 579 587 self.model = model 588 self.model.name = model.name 580 589 581 590 def add_data(self,data): -
park_integration/Fitting.py
rfd6b789 r6d20b46 22 22 engine.set_param( model,model.name, pars) 23 23 engine.set_model(model,Uid) 24 24 engine.select_problem_for_fit(Uid,value) 25 25 chisqr1, out1, cov1=engine.fit(pars,qmin,qmax) 26 26 """ -
park_integration/ScipyFitting.py
rfd6b789 r6d20b46 56 56 with Uid as keys 57 57 """ 58 self.fitArrangeDict ={}59 self.paramList =[]58 self.fitArrangeDict = {} 59 self.paramList = [] 60 60 #def fit(self, *args, **kw): 61 61 # return profile(self._fit, *args, **kw) 62 63 def fit(self ,q=None,handler=None,curr_thread= None): 64 65 fitproblem=[] 66 for id ,fproblem in self.fitArrangeDict.iteritems(): 67 if fproblem.get_to_fit()==1: 68 fitproblem.append(fproblem) 69 if len(fitproblem)>1 : 62 def createFunctor(self): 63 fitproblem=None 64 fit_count = 0 65 #print " self.fitArrangeDict", self.fitArrangeDict 66 for id, fproblem in self.fitArrangeDict.iteritems(): 67 if fproblem.get_to_fit() == 1: 68 fitproblem = fproblem 69 fit_count += 1 70 if fit_count > 1 : 70 71 raise RuntimeError, "Scipy can't fit more than a single fit problem at a time." 71 72 return 72 elif len(fitproblem)==0 :73 elif fit_count == 0 : 73 74 raise RuntimeError, "No Assembly scheduled for Scipy fitting." 74 75 return 75 76 76 listdata=[] 77 model = fitproblem[0].get_model() 78 listdata = fitproblem[0].get_data() 77 listdata = [] 78 model = fitproblem.get_model().clone() 79 data = fitproblem.get_data() 80 79 81 # Concatenate dList set (contains one or more data)before fitting 80 82 #data=self._concatenateData( listdata) 81 data=listdata82 self.curr_thread= curr_thread83 #data = listdata 84 #self.curr_thread= curr_thread 83 85 84 86 #try: 85 functor= SansAssembly(self.paramList,model,data, curr_thread= self.curr_thread) 86 out, cov_x, info, mesg, success = optimize.leastsq(functor,model.getParams(self.paramList), full_output=1, warning=True) 87 functor = SansAssembly(self.paramList, model, data)#, curr_thread= curr_thread) 88 return functor , model 89 90 def fit(self, q=None, handler=None, curr_thread=None): 91 92 functor , model = self.createFunctor() 93 94 out, cov_x, info, mesg, success = optimize.leastsq(functor, 95 model.getParams(self.paramList), 96 full_output=1, warning=True) 87 97 88 98 chisqr = functor.chisq(out) … … 98 108 result.pvec = out 99 109 result.success = success 100 if q !=None:110 if q is not None: 101 111 print "went here" 102 112 q.put(result) … … 105 115 return result 106 116 else: 107 raise ValueError, "SVD did not converge" +str(success)117 raise ValueError, "SVD did not converge" + str(success) 108 118 #except FitAbort: 109 119 ## fit engine is stop
Note: See TracChangeset
for help on using the changeset viewer.