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 sans.fit.ScipyFitting import ScipyFit |
---|
9 | from sans.fit.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,id) |
---|
22 | engine.set_param( model,model.name, pars) |
---|
23 | engine.set_model(model,id) |
---|
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, |
---|
53 | curr_thread=None, |
---|
54 | ftol=1.49012e-8, |
---|
55 | reset_flag=False): |
---|
56 | """Perform the fit """ |
---|
57 | return self._engine.fit(q, handler, curr_thread=curr_thread, |
---|
58 | ftol=ftol, reset_flag=reset_flag) |
---|
59 | |
---|
60 | def set_model(self, model, id, pars=[], constraints=[], data=None): |
---|
61 | """ |
---|
62 | store a model model to fit at the position id of the fit engine |
---|
63 | """ |
---|
64 | self._engine.set_model(model, id, pars, constraints, data=data) |
---|
65 | |
---|
66 | def set_data(self, data, id, smearer=None, qmin=None, qmax=None): |
---|
67 | """ |
---|
68 | Store data to fit at the psotion id of the fit engine |
---|
69 | |
---|
70 | :param data: data to fit |
---|
71 | :param smearer: smearerobject to smear data |
---|
72 | :param qmin: the minimum q range to fit |
---|
73 | :param qmax: the minimum q range to fit |
---|
74 | |
---|
75 | """ |
---|
76 | self._engine.set_data(data, id, smearer, qmin, qmax) |
---|
77 | |
---|
78 | def get_model(self, id): |
---|
79 | """ return list of data""" |
---|
80 | self._engine.get_model(id) |
---|
81 | |
---|
82 | |
---|
83 | def remove_fit_problem(self, id): |
---|
84 | """remove fitarrange in id""" |
---|
85 | self._engine.remove_fit_problem(id) |
---|
86 | |
---|
87 | def select_problem_for_fit(self, id, value): |
---|
88 | """ |
---|
89 | select a couple of model and data at the id position in dictionary |
---|
90 | and set in self.selected value to value |
---|
91 | |
---|
92 | :param value: the value to allow fitting. |
---|
93 | can only have the value one or zero |
---|
94 | """ |
---|
95 | self._engine.select_problem_for_fit(id, value) |
---|
96 | |
---|
97 | def get_problem_to_fit(self, id): |
---|
98 | """ |
---|
99 | return the self.selected value of the fit problem of id |
---|
100 | |
---|
101 | :param id: the id of the problem |
---|
102 | |
---|
103 | """ |
---|
104 | return self._engine.get_problem_to_fit(id) |
---|