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 | self.theory_data = None |
---|
16 | ## the current model |
---|
17 | self.model = None |
---|
18 | self.model_index = None |
---|
19 | ## if 1 this fit problem will be selected to fit , if 0 |
---|
20 | ## it will not be selected for fit |
---|
21 | self.schedule = 0 |
---|
22 | ##list containing parameter name and value |
---|
23 | self.list_param = [] |
---|
24 | ## smear object to smear or not data1D |
---|
25 | self.smearer = None |
---|
26 | self.fit_tab_caption = '' |
---|
27 | ## fitting range |
---|
28 | self.qmin = None |
---|
29 | self.qmax = None |
---|
30 | |
---|
31 | # 1D or 2D |
---|
32 | self.enable2D = False |
---|
33 | |
---|
34 | def clone(self): |
---|
35 | """ |
---|
36 | copy fitproblem |
---|
37 | """ |
---|
38 | |
---|
39 | obj = FitProblem() |
---|
40 | model= None |
---|
41 | if self.model!=None: |
---|
42 | model = self.model.clone() |
---|
43 | obj.model = model |
---|
44 | obj.fit_data = copy.deepcopy(self.fit_data) |
---|
45 | obj.theory_data = copy.deepcopy(self.theory_data) |
---|
46 | obj.model = copy.deepcopy(self.model) |
---|
47 | obj.schedule = copy.deepcopy(self.schedule) |
---|
48 | obj.list_param = copy.deepcopy(self.list_param) |
---|
49 | obj.smearer = copy.deepcopy(self.smearer) |
---|
50 | obj.plotted_data = copy.deepcopy(self.plotted_data) |
---|
51 | obj.qmin = copy.deepcopy(self.qmin) |
---|
52 | obj.qmax = copy.deepcopy(self.qmax) |
---|
53 | obj.enable2D = copy.deepcopy(self.enable2D) |
---|
54 | return obj |
---|
55 | |
---|
56 | def set_smearer(self, smearer): |
---|
57 | """ |
---|
58 | save reference of smear object on fitdata |
---|
59 | |
---|
60 | :param smear: smear object from DataLoader |
---|
61 | |
---|
62 | """ |
---|
63 | self.smearer= smearer |
---|
64 | |
---|
65 | def get_smearer(self): |
---|
66 | """ |
---|
67 | return smear object |
---|
68 | """ |
---|
69 | return self.smearer |
---|
70 | |
---|
71 | def save_model_name(self, name): |
---|
72 | """ |
---|
73 | """ |
---|
74 | self.name_per_page= name |
---|
75 | |
---|
76 | def get_name(self): |
---|
77 | """ |
---|
78 | """ |
---|
79 | return self.name_per_page |
---|
80 | |
---|
81 | def set_model(self,model): |
---|
82 | """ |
---|
83 | associates each model with its new created name |
---|
84 | |
---|
85 | :param model: model selected |
---|
86 | :param name: name created for model |
---|
87 | |
---|
88 | """ |
---|
89 | self.model= model |
---|
90 | |
---|
91 | def get_model(self): |
---|
92 | """ |
---|
93 | :return: saved model |
---|
94 | |
---|
95 | """ |
---|
96 | return self.model |
---|
97 | |
---|
98 | def set_index(self, index): |
---|
99 | """ |
---|
100 | set index of the model name |
---|
101 | """ |
---|
102 | self.model_index = index |
---|
103 | |
---|
104 | def get_index(self): |
---|
105 | """ |
---|
106 | get index of the model name |
---|
107 | """ |
---|
108 | return self.model_index |
---|
109 | |
---|
110 | def set_theory_data(self, data): |
---|
111 | """ |
---|
112 | save a copy of the data select to fit |
---|
113 | |
---|
114 | :param data: data selected |
---|
115 | |
---|
116 | """ |
---|
117 | self.theory_data = copy.deepcopy(data) |
---|
118 | |
---|
119 | def set_enable2D(self, enable2D): |
---|
120 | """ |
---|
121 | """ |
---|
122 | self.enable2D = enable2D |
---|
123 | |
---|
124 | def get_theory_data(self): |
---|
125 | """ |
---|
126 | :return: list of data dList |
---|
127 | |
---|
128 | """ |
---|
129 | return self.theory_data |
---|
130 | |
---|
131 | def set_fit_data(self,data): |
---|
132 | """ |
---|
133 | save a copy of the data select to fit |
---|
134 | |
---|
135 | :param data: data selected |
---|
136 | |
---|
137 | """ |
---|
138 | self.fit_data = data |
---|
139 | |
---|
140 | def get_fit_data(self): |
---|
141 | """ |
---|
142 | """ |
---|
143 | return self.fit_data |
---|
144 | |
---|
145 | def set_model_param(self,name,value=None): |
---|
146 | """ |
---|
147 | Store the name and value of a parameter of this fitproblem's model |
---|
148 | |
---|
149 | :param name: name of the given parameter |
---|
150 | :param value: value of that parameter |
---|
151 | |
---|
152 | """ |
---|
153 | self.list_param.append([name,value]) |
---|
154 | |
---|
155 | def get_model_param(self): |
---|
156 | """ |
---|
157 | return list of couple of parameter name and value |
---|
158 | """ |
---|
159 | return self.list_param |
---|
160 | |
---|
161 | def schedule_tofit(self, schedule=0): |
---|
162 | """ |
---|
163 | set schedule to true to decide if this fit must be performed |
---|
164 | """ |
---|
165 | self.schedule=schedule |
---|
166 | |
---|
167 | def get_scheduled(self): |
---|
168 | """ |
---|
169 | return true or false if a problem as being schedule for fitting |
---|
170 | """ |
---|
171 | return self.schedule |
---|
172 | |
---|
173 | def set_range(self, qmin=None, qmax=None): |
---|
174 | """ |
---|
175 | set fitting range |
---|
176 | """ |
---|
177 | self.qmin = qmin |
---|
178 | self.qmax = qmax |
---|
179 | |
---|
180 | def get_range(self): |
---|
181 | """ |
---|
182 | :return: fitting range |
---|
183 | |
---|
184 | """ |
---|
185 | return self.qmin, self.qmax |
---|
186 | |
---|
187 | def clear_model_param(self): |
---|
188 | """ |
---|
189 | clear constraint info |
---|
190 | """ |
---|
191 | self.list_param=[] |
---|
192 | |
---|
193 | def set_fit_tab_caption(self, caption): |
---|
194 | """ |
---|
195 | """ |
---|
196 | self.fit_tab_caption = str(caption) |
---|
197 | |
---|
198 | def get_fit_tab_caption(self): |
---|
199 | """ |
---|
200 | """ |
---|
201 | return self.fit_tab_caption |
---|
202 | |
---|
203 | def get_enable2D(self): |
---|
204 | """ |
---|
205 | """ |
---|
206 | return self.enable2D |
---|
207 | |
---|