Changeset 3e3ab46 in sasview for fittingview/src/sans/perspectives
- Timestamp:
- Aug 26, 2011 9:43:14 AM (13 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 2dbffcc
- Parents:
- aefc09f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fittingview/src/sans/perspectives/fitting/fitproblem.py
r49c69de r3e3ab46 1 ################################################################################ 2 #This software was developed by the University of Tennessee as part of the 3 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 #project funded by the US National Science Foundation. 5 # 6 #See the license text in license.txt 7 # 8 #copyright 2009, University of Tennessee 9 ################################################################################ 1 10 import copy 11 from sans.models.qsmearing import smear_selection 2 12 3 class FitProblem: 13 14 class FitProblemComponent(object): 15 """ 16 Inferface containing information to store data, model, range of data, etc... 17 and retreive this information. This is an inferface 18 for a fitProblem i.e relationship between data and model. 19 """ 20 def enable_smearing(self, flag=False): 21 """ 22 :param flag: bool.When flag is 1 get the computer smear value. When 23 flag is 0 ingore smear value. 24 """ 25 def get_smearer(self): 26 """ 27 return smear object 28 """ 29 def save_model_name(self, name): 30 """ 31 """ 32 def get_name(self): 33 """ 34 """ 35 def set_model(self, model): 36 """ 37 associates each model with its new created name 38 :param model: model selected 39 :param name: name created for model 40 """ 41 def get_model(self): 42 """ 43 :return: saved model 44 """ 45 def set_theory_data(self, data): 46 """ 47 save a copy of the data select to fit 48 :param data: data selected 49 """ 50 def get_theory_data(self): 51 """ 52 :return: list of data dList 53 """ 54 def set_fit_data(self, data): 55 """ 56 Store of list of data and create by create new fitproblem of each data 57 id , if there was existing information about model, this information 58 get copy to the new fitproblem 59 :param data: list of data selected 60 """ 61 def get_fit_data(self): 62 """ 63 """ 64 def set_model_param(self, name, value=None): 65 """ 66 Store the name and value of a parameter of this fitproblem's model 67 :param name: name of the given parameter 68 :param value: value of that parameter 69 """ 70 def get_model_param(self): 71 """ 72 return list of couple of parameter name and value 73 """ 74 def schedule_tofit(self, schedule=0): 75 """ 76 set schedule to true to decide if this fit must be performed 77 """ 78 def get_scheduled(self): 79 """ 80 return true or false if a problem as being schedule for fitting 81 """ 82 def set_range(self, qmin=None, qmax=None): 83 """ 84 set fitting range 85 """ 86 def get_range(self): 87 """ 88 :return: fitting range 89 """ 90 def clear_model_param(self): 91 """ 92 clear constraint info 93 """ 94 def set_fit_tab_caption(self, caption): 95 """ 96 store the caption of the page associated with object 97 """ 98 def get_fit_tab_caption(self): 99 """ 100 Return the caption of the page associated with object 101 """ 102 103 104 class FitProblemDictionary(FitProblemComponent, dict): 105 """ 106 This module implements a dictionary of fitproblem objects 107 """ 108 def __init__(self): 109 FitProblemComponent.__init__(self) 110 dict.__init__(self) 111 ## the current model 112 self.model = None 113 ## if 1 this fit problem will be selected to fit , if 0 114 ## it will not be selected for fit 115 self.schedule = 0 116 ##list containing parameter name and value 117 self.list_param = [] 118 ## fitting range 119 self.qmin = None 120 self.qmax = None 121 self._smear_on = False 122 self.scheduled = 0 123 self.fit_tab_caption = '' 124 125 def enable_smearing(self, flag=False, fid=None): 126 """ 127 :param flag: bool.When flag is 1 get the computer smear value. When 128 flag is 0 ingore smear value. 129 """ 130 self._smear_on = flag 131 if fid is None: 132 for value in self.itervalues(): 133 value.enable_smearing(flag) 134 else: 135 if fid in self.iterkeys(): 136 self[fid].enable_smearing(flag) 137 138 def set_smearer(self, smearer, fid=None): 139 """ 140 save reference of smear object on fitdata 141 :param smear: smear object from DataLoader 142 """ 143 if fid is None: 144 for value in self.itervalues(): 145 value.set_smearer(smearer) 146 else: 147 if fid in self.iterkeys(): 148 self[fid].set_smearer(smearer) 149 150 def get_smearer(self, fid=None): 151 """ 152 return smear object 153 """ 154 result = [] 155 if fid is None: 156 for value in self.itervalues(): 157 result.append(value.get_smearer()) 158 else: 159 if fid in self.iterkeys(): 160 result.append(self[fid].get_smearer()) 161 return result 162 163 def save_model_name(self, name, fid=None): 164 """ 165 """ 166 if fid is None: 167 for value in self.itervalues(): 168 value.save_model_name(name) 169 else: 170 if fid in self.iterkeys(): 171 self[fid].save_model_name(name) 172 173 def get_name(self, fid=None): 174 """ 175 """ 176 result = [] 177 if fid is None: 178 for value in self.itervalues(): 179 result.append(value.get_name()) 180 else: 181 if fid in self.iterkeys(): 182 result.append(self[fid].get_name()) 183 return result 184 185 def set_model(self, model, fid=None): 186 """ 187 associates each model with its new created name 188 :param model: model selected 189 :param name: name created for model 190 """ 191 self.model = model 192 if fid is None: 193 for value in self.itervalues(): 194 value.set_model(self.model) 195 else: 196 if fid in self.iterkeys(): 197 self[fid].set_model(self.model) 198 199 def get_model(self, fid): 200 """ 201 :return: saved model 202 """ 203 if fid in self.iterkeys(): 204 self[fid].get_model() 205 206 def set_fit_tab_caption(self, caption): 207 """ 208 store the caption of the page associated with object 209 """ 210 self.fit_tab_caption = caption 211 212 def get_fit_tab_caption(self): 213 """ 214 Return the caption of the page associated with object 215 """ 216 return self.fit_tab_caption 217 218 def set_theory_data(self, fid, data=None): 219 """ 220 save a copy of the data select to fit 221 :param data: data selected 222 """ 223 if fid in self.iterkeys(): 224 self[fid].set_theory_data(data) 225 226 def get_theory_data(self, fid): 227 """ 228 :return: list of data dList 229 """ 230 if fid in self.iterkeys(): 231 return self[fid].get_theory_data() 232 233 def add_data(self, data): 234 """ 235 Add data to the current dictionary of fitproblem. if data id does not 236 exist create a new fit problem. 237 :note: only data changes in the fit problem 238 """ 239 if data.id not in self.iterkeys(): 240 self[data.id] = FitProblem() 241 self[data.id].set_fit_data(data) 242 243 def set_fit_data(self, data): 244 """ 245 save a copy of the data select to fit 246 :param data: data selected 247 248 """ 249 self.clear() 250 if data is None: 251 data = [] 252 for d in data: 253 if (d is not None): 254 if (d.id not in self.iterkeys()): 255 self[d.id] = FitProblem() 256 self[d.id].set_fit_data(d) 257 self[d.id].set_model(self.model) 258 self[d.id].set_range(self.qmin, self.qmax) 259 260 def get_fit_data(self, fid): 261 """ 262 263 return data for the given fitproblem id 264 :param fid: is key representing a fitproblem. usually extract from data 265 id 266 """ 267 if fid in self.iterkeys(): 268 return self[fid].get_fit_data() 269 270 def set_model_param(self, name, value=None, fid=None): 271 """ 272 Store the name and value of a parameter of this fitproblem's model 273 :param name: name of the given parameter 274 :param value: value of that parameter 275 """ 276 if fid is None: 277 for value in self.itervalues(): 278 value.set_model_param(name, value) 279 else: 280 if fid in self.iterkeys(): 281 self[fid].set_model_param(name, value) 282 283 def get_model_param(self, fid): 284 """ 285 return list of couple of parameter name and value 286 """ 287 if fid in self.iterkeys(): 288 return self[fid].get_model_param() 289 290 def schedule_tofit(self, schedule=0): 291 """ 292 set schedule to true to decide if this fit must be performed 293 """ 294 self.scheduled = schedule 295 for value in self.itervalues(): 296 value.schedule_tofit(schedule) 297 298 def get_scheduled(self): 299 """ 300 return true or false if a problem as being schedule for fitting 301 """ 302 return self.scheduled 303 304 def set_range(self, qmin=None, qmax=None, fid=None): 305 """ 306 set fitting range 307 """ 308 self.qmin = qmin 309 self.qmax = qmax 310 if fid is None: 311 for value in self.itervalues(): 312 value.set_range(self.qmin, self.qmax) 313 else: 314 if fid in self.iterkeys(): 315 self[fid].value.set_range(self.qmin, self.qmax) 316 317 def get_range(self, fid): 318 """ 319 :return: fitting range 320 """ 321 if fid in self.iterkeys(): 322 return self[fid].get_range() 323 324 325 def clear_model_param(self, fid=None): 326 """ 327 clear constraint info 328 """ 329 if fid is None: 330 for value in self.itervalues(): 331 value.clear_model_param() 332 else: 333 if fid in self.iterkeys(): 334 self[fid].clear_model_param() 335 336 def get_fit_problem(self): 337 """ 338 return fitproblem contained in this dictionary 339 """ 340 return self.itervalues() 341 342 def set_result(self, result): 343 """ 344 set a list of result 345 """ 346 self.result = result 347 348 def get_result(self): 349 """ 350 get result 351 """ 352 return self.result 353 354 355 class FitProblem(FitProblemComponent): 4 356 """ 5 357 FitProblem class allows to link a model with the new name created in _on_model, … … 8 360 """ 9 361 def __init__(self): 362 FitProblemComponent.__init__(self) 10 363 """ 11 364 contains information about data and model to fit … … 13 366 ## data used for fitting 14 367 self.fit_data = None 15 #list of data in case of batch mode16 self.data_list = []17 #dictionary of data id and location to corresponding fitproblem18 self.fitproblem_pointers = {}19 368 self.theory_data = None 20 369 ## the current model 21 370 self.model = None 22 self.model_index = None23 371 ## if 1 this fit problem will be selected to fit , if 0 24 372 ## it will not be selected for fit … … 27 375 self.list_param = [] 28 376 ## smear object to smear or not data1D 29 self.smearer = None 30 self.fit_tab_caption = '' 377 self.smearer_compute_count = 0 378 self.smearer_enable = False 379 self.smearer_computer_value = None 31 380 ## fitting range 32 381 self.qmin = None 33 382 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 383 384 385 def enable_smearing(self, flag=False): 386 """ 387 :param flag: bool.When flag is 1 get the computer smear value. When 388 flag is 0 ingore smear value. 389 """ 390 self.smearer_enable = flag 60 391 61 392 def set_smearer(self, smearer): … … 66 397 67 398 """ 68 self.smearer = smearer399 self.smearer_computer_value = smearer 69 400 70 401 def get_smearer(self): … … 72 403 return smear object 73 404 """ 74 return self.smearer 405 if not self.smearer_enable: 406 return None 407 if self.smearer_computer_value is None and \ 408 self.smearer_compute_count > 1: 409 #smeari_selection should be call only once per fitproblem 410 self.smearer_computer_value = smear_selection(self.fit_data, 411 self.model) 412 self.smearer_compute_count += 1 413 return self.smearer_computer_value 75 414 76 415 def save_model_name(self, name): … … 87 426 """ 88 427 associates each model with its new created name 89 90 428 :param model: model selected 91 429 :param name: name created for model 92 93 430 """ 94 431 self.model= model … … 97 434 """ 98 435 :return: saved model 99 100 436 """ 101 437 return self.model 102 438 103 def set_index(self, index):104 """105 set index of the model name106 """107 self.model_index = index108 109 def get_index(self):110 """111 get index of the model name112 """113 return self.model_index114 115 439 def set_theory_data(self, data): 116 440 """ … … 122 446 self.theory_data = copy.deepcopy(data) 123 447 124 def set_enable2D(self, enable2D): 125 """ 126 """ 127 self.enable2D = enable2D 448 128 449 129 450 def get_theory_data(self): 130 451 """ 131 :return: list of data dList 132 452 :return: theory generated with the current model and data of this class 133 453 """ 134 454 return self.theory_data 135 455 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 456 def set_fit_data(self, data): 457 """ 458 Store data associated with this class 459 :param data: list of data selected 142 460 """ 143 461 self.fit_data = data … … 145 463 def get_fit_data(self): 146 464 """ 465 :return: data associate with this class 147 466 """ 148 467 return self.fit_data 149 468 150 def set_fit_data_list(self, data_list):151 """152 save a copy of a list of data153 154 :param data_list: list of data155 156 """157 self.data_list = data_list158 159 def get_fit_data_list(self):160 """161 """162 return self.data_list163 164 469 def set_model_param(self,name,value=None): 165 470 """ 166 471 Store the name and value of a parameter of this fitproblem's model 167 168 472 :param name: name of the given parameter 169 473 :param value: value of that parameter 170 171 474 """ 172 475 self.list_param.append([name,value]) … … 182 485 set schedule to true to decide if this fit must be performed 183 486 """ 184 self.schedule =schedule487 self.schedule = schedule 185 488 186 489 def get_scheduled(self): … … 192 495 def set_range(self, qmin=None, qmax=None): 193 496 """ 194 set fitting range 497 set fitting range 498 :param qmin: minimum value to consider for the fit range 499 :param qmax: maximum value to consider for the fit range 195 500 """ 196 501 self.qmin = qmin … … 208 513 clear constraint info 209 514 """ 210 self.list_param =[]515 self.list_param = [] 211 516 212 517 def set_fit_tab_caption(self, caption): … … 220 525 return self.fit_tab_caption 221 526 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 527 250 528
Note: See TracChangeset
for help on using the changeset viewer.