Changeset 6c382da in sasview for src/sas/sasgui/perspectives/fitting/basepage.py
- Timestamp:
- Sep 28, 2016 9:45:13 AM (8 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:
- 9bbc074
- Parents:
- ae08f14
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/basepage.py
ra0373d5 r6c382da 933 933 if len(self._disp_obj_dict) > 0: 934 934 for k, v in self._disp_obj_dict.iteritems(): 935 self.state._disp_obj_dict[k] = v 935 self.state._disp_obj_dict[k] = v.type 936 936 937 937 self.state.values = copy.deepcopy(self.values) … … 1010 1010 if len(self._disp_obj_dict) > 0: 1011 1011 for k, v in self._disp_obj_dict.iteritems(): 1012 self.state._disp_obj_dict[k] = v 1012 self.state._disp_obj_dict[k] = v.type 1013 1013 1014 1014 self.state.values = copy.deepcopy(self.values) … … 1379 1379 self.weights = copy.deepcopy(state.weights) 1380 1380 1381 for key, disp in state._disp_obj_dict.iteritems(): 1382 # From saved file, disp_model can not be sent in model obj. 1383 # it will be sent as a string here, then converted to model object. 1384 if disp.__class__.__name__ == 'str': 1385 disp_model = None 1386 com_str = "from sasmodels.weights " 1387 com_str += "import %s as disp_func \ndisp_model = disp_func()" 1388 exec com_str % disp 1389 else: 1390 disp_model = disp 1381 for key, disp_type in state._disp_obj_dict.iteritems(): 1382 #disp_model = disp 1383 disp_model = POLYDISPERSITY_MODELS[disp_type]() 1391 1384 self._disp_obj_dict[key] = disp_model 1392 1385 param_name = key.split('.')[0] … … 2520 2513 self._disp_obj_dict[name1] = disp_model 2521 2514 self.model.set_dispersion(param_name, disp_model) 2522 self.state._disp_obj_dict[name1] = disp_model 2515 self.state._disp_obj_dict[name1] = disp_model.type 2523 2516 2524 2517 value1 = str(format_number(self.model.getParam(name1), True)) … … 2543 2536 item[0].Enable() 2544 2537 item[2].Enable() 2538 item[3].Show(True) 2539 item[4].Show(True) 2545 2540 item[5].Enable() 2546 2541 item[6].Enable() … … 2635 2630 self._disp_obj_dict[name] = disp 2636 2631 self.model.set_dispersion(name.split('.')[0], disp) 2637 self.state._disp_obj_dict[name] = disp 2632 self.state._disp_obj_dict[name] = disp.type 2638 2633 self.values[name] = values 2639 2634 self.weights[name] = weights … … 3296 3291 pd = content[name][1] 3297 3292 if name.count('.') > 0: 3293 # If this is parameter.width, then pd may be a floating 3294 # point value or it may be an array distribution. 3295 # Nothing to do for parameter.npts or parameter.nsigmas. 3298 3296 try: 3299 3297 float(pd) 3300 except: 3298 if name.endswith('.npts'): 3299 pd = int(pd) 3300 except Exception: 3301 3301 #continue 3302 3302 if not pd and pd != '': … … 3306 3306 # Only array func has pd == '' case. 3307 3307 item[2].Enable(False) 3308 else: 3309 item[2].Enable(True) 3308 3310 if item[2].__class__.__name__ == "ComboBox": 3309 3311 if content[name][1] in self.model.fun_list: … … 3332 3334 pd = value[0] 3333 3335 if name.count('.') > 0: 3336 # If this is parameter.width, then pd may be a floating 3337 # point value or it may be an array distribution. 3338 # Nothing to do for parameter.npts or parameter.nsigmas. 3334 3339 try: 3335 3340 pd = float(pd) 3341 if name.endswith('.npts'): 3342 pd = int(pd) 3336 3343 except: 3337 3344 #continue … … 3342 3349 # Only array func has pd == '' case. 3343 3350 item[2].Enable(False) 3351 else: 3352 item[2].Enable(True) 3344 3353 if item[2].__class__.__name__ == "ComboBox": 3345 3354 if value[0] in self.model.fun_list: … … 3361 3370 Helps get paste for poly function 3362 3371 3363 :param item: Gui param items 3364 :param value: the values for parameter ctrols 3365 """ 3366 is_array = False 3367 if len(value[1]) > 0: 3368 # Only for dispersion func.s 3369 try: 3370 item[7].SetValue(value[1]) 3371 selection = item[7].GetCurrentSelection() 3372 name = item[7].Name 3373 param_name = name.split('.')[0] 3374 dispersity = item[7].GetClientData(selection) 3375 disp_model = dispersity() 3376 # Only for array disp 3377 try: 3378 pd_vals = numpy.array(value[2]) 3379 pd_weights = numpy.array(value[3]) 3380 if len(pd_vals) > 0 and len(pd_vals) > 0: 3381 if len(pd_vals) == len(pd_weights): 3382 self._set_disp_array_cb(item=item) 3383 self._set_array_disp_model(name=name, 3384 disp=disp_model, 3385 values=pd_vals, 3386 weights=pd_weights) 3387 is_array = True 3388 except Exception: 3389 logging.error(traceback.format_exc()) 3390 if not is_array: 3391 self._disp_obj_dict[name] = disp_model 3392 self.model.set_dispersion(name, 3393 disp_model) 3394 self.state._disp_obj_dict[name] = \ 3395 disp_model 3396 self.model.set_dispersion(param_name, disp_model) 3397 self.state.values = self.values 3398 self.state.weights = self.weights 3399 self.model._persistency_dict[param_name] = \ 3400 [self.state.values, 3401 self.state.weights] 3402 3403 except Exception: 3404 logging.error(traceback.format_exc()) 3405 print "Error in BasePage._paste_poly_help: %s" % \ 3406 sys.exc_info()[1] 3407 3408 def _set_disp_array_cb(self, item): 3372 *item* is the parameter name 3373 3374 *value* depends on which parameter is being processed, and whether it 3375 has array polydispersity. 3376 3377 For parameters without array polydispersity: 3378 3379 parameter => ['FLOAT', ''] 3380 parameter.width => ['FLOAT', 'DISTRIBUTION', ''] 3381 parameter.npts => ['FLOAT', ''] 3382 parameter.nsigmas => ['FLOAT', ''] 3383 3384 For parameters with array polydispersity: 3385 3386 parameter => ['FLOAT', ''] 3387 parameter.width => ['FILENAME', 'array', [x1, ...], [w1, ...]] 3388 parameter.npts => ['FLOAT', ''] 3389 parameter.nsigmas => ['FLOAT', ''] 3390 """ 3391 # Do nothing if not setting polydispersity 3392 if len(value[1]) == 0: 3393 return 3394 3395 try: 3396 name = item[7].Name 3397 param_name = name.split('.')[0] 3398 item[7].SetValue(value[1]) 3399 selection = item[7].GetCurrentSelection() 3400 dispersity = item[7].GetClientData(selection) 3401 disp_model = dispersity() 3402 3403 if value[1] == 'array': 3404 pd_vals = numpy.array(value[2]) 3405 pd_weights = numpy.array(value[3]) 3406 if len(pd_vals) == 0 or len(pd_vals) != len(pd_weights): 3407 msg = ("bad array distribution parameters for %s" 3408 % param_name) 3409 raise ValueError(msg) 3410 self._set_disp_cb(True, item=item) 3411 self._set_array_disp_model(name=name, 3412 disp=disp_model, 3413 values=pd_vals, 3414 weights=pd_weights) 3415 else: 3416 self._set_disp_cb(False, item=item) 3417 self._disp_obj_dict[name] = disp_model 3418 self.model.set_dispersion(param_name, disp_model) 3419 self.state._disp_obj_dict[name] = disp_model.type 3420 # TODO: It's not an array, why update values and weights? 3421 self.model._persistency_dict[param_name] = \ 3422 [self.values, self.weights] 3423 self.state.values = self.values 3424 self.state.weights = self.weights 3425 3426 except Exception: 3427 logging.error(traceback.format_exc()) 3428 print "Error in BasePage._paste_poly_help: %s" % \ 3429 sys.exc_info()[1] 3430 3431 def _set_disp_cb(self, isarray, item): 3409 3432 """ 3410 3433 Set cb for array disp 3411 3434 """ 3412 item[0].SetValue(False) 3413 item[0].Enable(False) 3414 item[2].Enable(False) 3415 item[3].Show(False) 3416 item[4].Show(False) 3417 item[5].SetValue('') 3418 item[5].Enable(False) 3419 item[6].SetValue('') 3420 item[6].Enable(False) 3435 if isarray: 3436 item[0].SetValue(False) 3437 item[0].Enable(False) 3438 item[2].Enable(False) 3439 item[3].Show(False) 3440 item[4].Show(False) 3441 item[5].SetValue('') 3442 item[5].Enable(False) 3443 item[6].SetValue('') 3444 item[6].Enable(False) 3445 else: 3446 item[0].Enable() 3447 item[2].Enable() 3448 item[3].Show(True) 3449 item[4].Show(True) 3450 item[5].Enable() 3451 item[6].Enable() 3421 3452 3422 3453 def update_pinhole_smear(self):
Note: See TracChangeset
for help on using the changeset viewer.