1 | """ |
---|
2 | 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 | """ |
---|
6 | |
---|
7 | #from scipy import optimize |
---|
8 | from ScipyFitting import ScipyFit |
---|
9 | from ParkFitting import ParkFit |
---|
10 | |
---|
11 | |
---|
12 | class Fit: |
---|
13 | """ |
---|
14 | Wrap class that allows to select the fitting type.this class |
---|
15 | can be used as follow : :: |
---|
16 | |
---|
17 | from sans.fit.Fitting import Fit |
---|
18 | fitter= Fit() |
---|
19 | fitter.fit_engine('scipy') or fitter.fit_engine('park') |
---|
20 | engine = fitter.returnEngine() |
---|
21 | engine.set_data(data,Uid) |
---|
22 | engine.set_param( model,model.name, pars) |
---|
23 | engine.set_model(model,Uid) |
---|
24 | |
---|
25 | chisqr1, out1, cov1=engine.fit(pars,qmin,qmax) |
---|
26 | |
---|
27 | """ |
---|
28 | def __init__(self, engine='scipy'): |
---|
29 | """ |
---|
30 | """ |
---|
31 | #self._engine will contain an instance of ScipyFit or ParkFit |
---|
32 | self._engine = None |
---|
33 | self.set_engine(engine) |
---|
34 | |
---|
35 | def set_engine(self, word): |
---|
36 | """ |
---|
37 | Select the type of Fit |
---|
38 | |
---|
39 | :param word: the keyword to select the fit type |
---|
40 | |
---|
41 | :raise: if the user does not enter 'scipy' or 'park', |
---|
42 | a valueError is raised |
---|
43 | |
---|
44 | """ |
---|
45 | if word == "scipy": |
---|
46 | self._engine = ScipyFit() |
---|
47 | elif word == "park": |
---|
48 | self._engine=ParkFit() |
---|
49 | else: |
---|
50 | raise ValueError, "enter the keyword scipy or park" |
---|
51 | |
---|
52 | def fit(self, q=None, handler=None, curr_thread=None): |
---|
53 | """Perform the fit """ |
---|
54 | try: |
---|
55 | return self._engine.fit(q,handler, curr_thread=curr_thread) |
---|
56 | except: |
---|
57 | raise |
---|
58 | |
---|
59 | def set_model(self, model, Uid, pars=[], constraints=[]): |
---|
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, constraints) |
---|
64 | |
---|
65 | def set_data(self, data, Uid, smearer=None, qmin=None, qmax=None): |
---|
66 | """ |
---|
67 | Store data to fit at the psotion Uid of the fit engine |
---|
68 | |
---|
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 | """ |
---|
75 | self._engine.set_data(data, Uid, smearer, qmin, qmax) |
---|
76 | |
---|
77 | def get_model(self, Uid): |
---|
78 | """ return list of data""" |
---|
79 | self._engine.get_model(Uid) |
---|
80 | |
---|
81 | |
---|
82 | def remove_Fit_Problem(self, Uid): |
---|
83 | """remove fitarrange in Uid""" |
---|
84 | self._engine.remove_Fit_Problem(Uid) |
---|
85 | |
---|
86 | def select_problem_for_fit(self, Uid, value): |
---|
87 | """ |
---|
88 | select a couple of model and data at the Uid position in dictionary |
---|
89 | and set in self.selected value to value |
---|
90 | |
---|
91 | :param value: the value to allow fitting. |
---|
92 | can only have the value one or zero |
---|
93 | """ |
---|
94 | self._engine.select_problem_for_fit(Uid, value) |
---|
95 | |
---|
96 | def get_problem_to_fit(self, Uid): |
---|
97 | """ |
---|
98 | return the self.selected value of the fit problem of Uid |
---|
99 | |
---|
100 | :param Uid: the Uid of the problem |
---|
101 | |
---|
102 | """ |
---|
103 | return self._engine.get_problem_to_fit(Uid) |
---|