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