1 | import copy |
---|
2 | |
---|
3 | class FitProblem: |
---|
4 | """ |
---|
5 | FitProblem class allows to link a model with the new name created in _on_model, |
---|
6 | a name theory created with that model and the data fitted with the model. |
---|
7 | FitProblem is mostly used as value of the dictionary by fitting module. |
---|
8 | """ |
---|
9 | def __init__(self): |
---|
10 | """ |
---|
11 | contains information about data and model to fit |
---|
12 | """ |
---|
13 | ## data used for fitting |
---|
14 | self.fit_data = None |
---|
15 | #list of data in case of batch mode |
---|
16 | self.data_list = [] |
---|
17 | #dictionary of data id and location to corresponding fitproblem |
---|
18 | self.fitproblem_pointers = {} |
---|
19 | self.theory_data = None |
---|
20 | ## the current model |
---|
21 | self.model = None |
---|
22 | self.model_index = None |
---|
23 | ## if 1 this fit problem will be selected to fit , if 0 |
---|
24 | ## it will not be selected for fit |
---|
25 | self.schedule = 0 |
---|
26 | ##list containing parameter name and value |
---|
27 | self.list_param = [] |
---|
28 | ## smear object to smear or not data1D |
---|
29 | self.smearer = None |
---|
30 | self.fit_tab_caption = '' |
---|
31 | ## fitting range |
---|
32 | self.qmin = None |
---|
33 | self.qmax = None |
---|
34 | self.result = [] |
---|
35 | |
---|
36 | # 1D or 2D |
---|
37 | self.enable2D = False |
---|
38 | |
---|
39 | def clone(self): |
---|
40 | """ |
---|
41 | copy fitproblem |
---|
42 | """ |
---|
43 | |
---|
44 | obj = FitProblem() |
---|
45 | model= None |
---|
46 | if self.model!=None: |
---|
47 | model = self.model.clone() |
---|
48 | obj.model = model |
---|
49 | obj.fit_data = copy.deepcopy(self.fit_data) |
---|
50 | obj.theory_data = copy.deepcopy(self.theory_data) |
---|
51 | obj.model = copy.deepcopy(self.model) |
---|
52 | obj.schedule = copy.deepcopy(self.schedule) |
---|
53 | obj.list_param = copy.deepcopy(self.list_param) |
---|
54 | obj.smearer = copy.deepcopy(self.smearer) |
---|
55 | obj.plotted_data = copy.deepcopy(self.plotted_data) |
---|
56 | obj.qmin = copy.deepcopy(self.qmin) |
---|
57 | obj.qmax = copy.deepcopy(self.qmax) |
---|
58 | obj.enable2D = copy.deepcopy(self.enable2D) |
---|
59 | return obj |
---|
60 | |
---|
61 | def set_smearer(self, smearer): |
---|
62 | """ |
---|
63 | save reference of smear object on fitdata |
---|
64 | |
---|
65 | :param smear: smear object from DataLoader |
---|
66 | |
---|
67 | """ |
---|
68 | self.smearer= smearer |
---|
69 | |
---|
70 | def get_smearer(self): |
---|
71 | """ |
---|
72 | return smear object |
---|
73 | """ |
---|
74 | return self.smearer |
---|
75 | |
---|
76 | def save_model_name(self, name): |
---|
77 | """ |
---|
78 | """ |
---|
79 | self.name_per_page= name |
---|
80 | |
---|
81 | def get_name(self): |
---|
82 | """ |
---|
83 | """ |
---|
84 | return self.name_per_page |
---|
85 | |
---|
86 | def set_model(self,model): |
---|
87 | """ |
---|
88 | associates each model with its new created name |
---|
89 | |
---|
90 | :param model: model selected |
---|
91 | :param name: name created for model |
---|
92 | |
---|
93 | """ |
---|
94 | self.model= model |
---|
95 | |
---|
96 | def get_model(self): |
---|
97 | """ |
---|
98 | :return: saved model |
---|
99 | |
---|
100 | """ |
---|
101 | return self.model |
---|
102 | |
---|
103 | def set_index(self, index): |
---|
104 | """ |
---|
105 | set index of the model name |
---|
106 | """ |
---|
107 | self.model_index = index |
---|
108 | |
---|
109 | def get_index(self): |
---|
110 | """ |
---|
111 | get index of the model name |
---|
112 | """ |
---|
113 | return self.model_index |
---|
114 | |
---|
115 | def set_theory_data(self, data): |
---|
116 | """ |
---|
117 | save a copy of the data select to fit |
---|
118 | |
---|
119 | :param data: data selected |
---|
120 | |
---|
121 | """ |
---|
122 | self.theory_data = copy.deepcopy(data) |
---|
123 | |
---|
124 | def set_enable2D(self, enable2D): |
---|
125 | """ |
---|
126 | """ |
---|
127 | self.enable2D = enable2D |
---|
128 | |
---|
129 | def get_theory_data(self): |
---|
130 | """ |
---|
131 | :return: list of data dList |
---|
132 | |
---|
133 | """ |
---|
134 | return self.theory_data |
---|
135 | |
---|
136 | def set_fit_data(self,data): |
---|
137 | """ |
---|
138 | save a copy of the data select to fit |
---|
139 | |
---|
140 | :param data: data selected |
---|
141 | |
---|
142 | """ |
---|
143 | self.fit_data = data |
---|
144 | |
---|
145 | def get_fit_data(self): |
---|
146 | """ |
---|
147 | """ |
---|
148 | return self.fit_data |
---|
149 | |
---|
150 | def set_fit_data_list(self, data_list): |
---|
151 | """ |
---|
152 | save a copy of a list of data |
---|
153 | |
---|
154 | :param data_list: list of data |
---|
155 | |
---|
156 | """ |
---|
157 | self.data_list = data_list |
---|
158 | |
---|
159 | def get_fit_data_list(self): |
---|
160 | """ |
---|
161 | """ |
---|
162 | return self.data_list |
---|
163 | |
---|
164 | def set_model_param(self,name,value=None): |
---|
165 | """ |
---|
166 | Store the name and value of a parameter of this fitproblem's model |
---|
167 | |
---|
168 | :param name: name of the given parameter |
---|
169 | :param value: value of that parameter |
---|
170 | |
---|
171 | """ |
---|
172 | self.list_param.append([name,value]) |
---|
173 | |
---|
174 | def get_model_param(self): |
---|
175 | """ |
---|
176 | return list of couple of parameter name and value |
---|
177 | """ |
---|
178 | return self.list_param |
---|
179 | |
---|
180 | def schedule_tofit(self, schedule=0): |
---|
181 | """ |
---|
182 | set schedule to true to decide if this fit must be performed |
---|
183 | """ |
---|
184 | self.schedule=schedule |
---|
185 | |
---|
186 | def get_scheduled(self): |
---|
187 | """ |
---|
188 | return true or false if a problem as being schedule for fitting |
---|
189 | """ |
---|
190 | return self.schedule |
---|
191 | |
---|
192 | def set_range(self, qmin=None, qmax=None): |
---|
193 | """ |
---|
194 | set fitting range |
---|
195 | """ |
---|
196 | self.qmin = qmin |
---|
197 | self.qmax = qmax |
---|
198 | |
---|
199 | def get_range(self): |
---|
200 | """ |
---|
201 | :return: fitting range |
---|
202 | |
---|
203 | """ |
---|
204 | return self.qmin, self.qmax |
---|
205 | |
---|
206 | def clear_model_param(self): |
---|
207 | """ |
---|
208 | clear constraint info |
---|
209 | """ |
---|
210 | self.list_param=[] |
---|
211 | |
---|
212 | def set_fit_tab_caption(self, caption): |
---|
213 | """ |
---|
214 | """ |
---|
215 | self.fit_tab_caption = str(caption) |
---|
216 | |
---|
217 | def get_fit_tab_caption(self): |
---|
218 | """ |
---|
219 | """ |
---|
220 | return self.fit_tab_caption |
---|
221 | |
---|
222 | def get_enable2D(self): |
---|
223 | """ |
---|
224 | """ |
---|
225 | return self.enable2D |
---|
226 | |
---|
227 | def get_pointer_to_fitproblem(self): |
---|
228 | """ |
---|
229 | return dictionary of id of fitproblem |
---|
230 | """ |
---|
231 | return self.fitproblem_pointers |
---|
232 | |
---|
233 | def set_pointer_to_fitproblem(self, data_id, page_id): |
---|
234 | """ |
---|
235 | """ |
---|
236 | self.fitproblem_pointers[data_id] = page_id |
---|
237 | |
---|
238 | def set_result(self, result): |
---|
239 | """ |
---|
240 | set a list of result |
---|
241 | """ |
---|
242 | self.result = result |
---|
243 | |
---|
244 | def get_result(self): |
---|
245 | """ |
---|
246 | get result |
---|
247 | """ |
---|
248 | return self.result |
---|
249 | |
---|
250 | |
---|