[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 | """ |
---|
[20d30e9] | 33 | self._engine = None |
---|
[93f0a586] | 34 | self.set_engine(engine) |
---|
[7705306] | 35 | |
---|
[20d30e9] | 36 | |
---|
[93f0a586] | 37 | def set_engine(self,word): |
---|
[7705306] | 38 | """ |
---|
| 39 | Select the type of Fit |
---|
| 40 | @param word: the keyword to select the fit type |
---|
[792db7d5] | 41 | @raise: if the user does not enter 'scipy' or 'park', |
---|
| 42 | a valueError is rase |
---|
[7705306] | 43 | """ |
---|
| 44 | if word=="scipy": |
---|
| 45 | self._engine=ScipyFit() |
---|
| 46 | elif word=="park": |
---|
| 47 | self._engine=ParkFit() |
---|
| 48 | else: |
---|
| 49 | raise ValueError, "enter the keyword scipy or park" |
---|
[ca6d914] | 50 | |
---|
[20d30e9] | 51 | |
---|
[7705306] | 52 | |
---|
[4bd557d] | 53 | def fit(self,handler=None, curr_thread=None): |
---|
[792db7d5] | 54 | """Perform the fit """ |
---|
[681f0dc] | 55 | |
---|
[4bd557d] | 56 | return self._engine.fit(handler, curr_thread= curr_thread) |
---|
[ca6d914] | 57 | |
---|
[20d30e9] | 58 | |
---|
[ca6d914] | 59 | def set_model(self,model,Uid,pars=[]): |
---|
[20d30e9] | 60 | """ |
---|
| 61 | store a model model to fit at the position Uid of the fit engine |
---|
| 62 | """ |
---|
| 63 | self._engine.set_model(model,Uid,pars) |
---|
| 64 | |
---|
[48882d1] | 65 | |
---|
[20d30e9] | 66 | def set_data(self,data,Uid,smearer=None,qmin=None, qmax=None): |
---|
| 67 | """ |
---|
| 68 | Store data to fit at the psotion Uid of the fit engine |
---|
| 69 | @param data: data to fit |
---|
| 70 | @param smearer: smearerobject to smear data |
---|
| 71 | @param qmin: the minimum q range to fit |
---|
| 72 | @param qmax: the minimum q range to fit |
---|
| 73 | """ |
---|
| 74 | self._engine.set_data(data,Uid,smearer,qmin, qmax) |
---|
| 75 | |
---|
[ca6d914] | 76 | |
---|
[7705306] | 77 | def get_model(self,Uid): |
---|
| 78 | """ return list of data""" |
---|
[4dd63eb] | 79 | self._engine.get_model(Uid) |
---|
[9855699] | 80 | |
---|
[20d30e9] | 81 | |
---|
[4dd63eb] | 82 | def remove_Fit_Problem(self,Uid): |
---|
| 83 | """remove fitarrange in Uid""" |
---|
| 84 | self._engine.remove_Fit_Problem(Uid) |
---|
[ca6d914] | 85 | |
---|
[20d30e9] | 86 | |
---|
[a9e04aa] | 87 | def select_problem_for_fit(self,Uid,value): |
---|
| 88 | """ |
---|
| 89 | select a couple of model and data at the Uid position in dictionary |
---|
| 90 | and set in self.selected value to value |
---|
| 91 | @param value: the value to allow fitting. can only have the value one or zero |
---|
| 92 | """ |
---|
| 93 | self._engine.select_problem_for_fit(Uid,value) |
---|
[ca6d914] | 94 | |
---|
[20d30e9] | 95 | |
---|
[a9e04aa] | 96 | def get_problem_to_fit(self,Uid): |
---|
| 97 | """ |
---|
| 98 | return the self.selected value of the fit problem of Uid |
---|
| 99 | @param Uid: the Uid of the problem |
---|
| 100 | """ |
---|
| 101 | return self._engine.get_problem_to_fit(Uid) |
---|