[792db7d5] | 1 | """ |
---|
| 2 | @organization: Class Fit contains ScipyFit and ParkFit methods declaration |
---|
| 3 | allows to create instance of type ScipyFit or ParkFit to perform either |
---|
| 4 | a park fit or a scipy fit. |
---|
| 5 | """ |
---|
[5fcfca4] | 6 | #from sans.guitools.plottables import Data1D |
---|
[61cb28d] | 7 | #from danse.common.plottools.plottables import Data1D |
---|
| 8 | #from Loader import Load |
---|
[7705306] | 9 | from scipy import optimize |
---|
| 10 | from ScipyFitting import ScipyFit |
---|
| 11 | from ParkFitting import ParkFit |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | class Fit: |
---|
| 15 | """ |
---|
[792db7d5] | 16 | Wrap class that allows to select the fitting type.this class |
---|
| 17 | can be used as follow : |
---|
| 18 | |
---|
| 19 | from sans.fit.Fitting import Fit |
---|
| 20 | fitter= Fit() |
---|
| 21 | fitter.fit_engine('scipy') or fitter.fit_engine('park') |
---|
| 22 | engine = fitter.returnEngine() |
---|
| 23 | engine.set_data(data,Uid) |
---|
| 24 | engine.set_param( model,model.name, pars) |
---|
| 25 | engine.set_model(model,Uid) |
---|
| 26 | |
---|
| 27 | chisqr1, out1, cov1=engine.fit(pars,qmin,qmax) |
---|
[7705306] | 28 | """ |
---|
[93f0a586] | 29 | def __init__(self, engine='scipy'): |
---|
[792db7d5] | 30 | """ |
---|
| 31 | self._engine will contain an instance of ScipyFit or ParkFit |
---|
| 32 | """ |
---|
[7705306] | 33 | self._engine=None |
---|
[93f0a586] | 34 | self.set_engine(engine) |
---|
[7705306] | 35 | |
---|
[93f0a586] | 36 | def set_engine(self,word): |
---|
[7705306] | 37 | """ |
---|
| 38 | Select the type of Fit |
---|
| 39 | @param word: the keyword to select the fit type |
---|
[792db7d5] | 40 | @raise: if the user does not enter 'scipy' or 'park', |
---|
| 41 | a valueError is rase |
---|
[7705306] | 42 | """ |
---|
| 43 | if word=="scipy": |
---|
| 44 | self._engine=ScipyFit() |
---|
| 45 | elif word=="park": |
---|
| 46 | self._engine=ParkFit() |
---|
| 47 | else: |
---|
| 48 | raise ValueError, "enter the keyword scipy or park" |
---|
[ca6d914] | 49 | |
---|
[7705306] | 50 | def returnEngine(self): |
---|
[792db7d5] | 51 | """ @return self._engine""" |
---|
[7705306] | 52 | return self._engine |
---|
| 53 | |
---|
[a2b6c05f] | 54 | def fit(self,handler=None): |
---|
[792db7d5] | 55 | """Perform the fit """ |
---|
[681f0dc] | 56 | |
---|
[a2b6c05f] | 57 | return self._engine.fit(handler) |
---|
[ca6d914] | 58 | |
---|
| 59 | def set_model(self,model,Uid,pars=[]): |
---|
| 60 | self._engine.set_model(model,Uid,pars) |
---|
[48882d1] | 61 | |
---|
[a2b6c05f] | 62 | def set_data(self,data,Uid,smearer=None,qmin=None, qmax=None,ymin=None, ymax=None): |
---|
| 63 | self._engine.set_data(data,Uid,smearer,qmin,qmax,ymin,ymax) |
---|
[ca6d914] | 64 | |
---|
[7705306] | 65 | def get_model(self,Uid): |
---|
| 66 | """ return list of data""" |
---|
[4dd63eb] | 67 | self._engine.get_model(Uid) |
---|
[9855699] | 68 | |
---|
[4dd63eb] | 69 | def remove_Fit_Problem(self,Uid): |
---|
| 70 | """remove fitarrange in Uid""" |
---|
| 71 | self._engine.remove_Fit_Problem(Uid) |
---|
[ca6d914] | 72 | |
---|
[a9e04aa] | 73 | def select_problem_for_fit(self,Uid,value): |
---|
| 74 | """ |
---|
| 75 | select a couple of model and data at the Uid position in dictionary |
---|
| 76 | and set in self.selected value to value |
---|
| 77 | @param value: the value to allow fitting. can only have the value one or zero |
---|
| 78 | """ |
---|
| 79 | self._engine.select_problem_for_fit(Uid,value) |
---|
[ca6d914] | 80 | |
---|
[a9e04aa] | 81 | def get_problem_to_fit(self,Uid): |
---|
| 82 | """ |
---|
| 83 | return the self.selected value of the fit problem of Uid |
---|
| 84 | @param Uid: the Uid of the problem |
---|
| 85 | """ |
---|
| 86 | return self._engine.get_problem_to_fit(Uid) |
---|