Changeset 6c382da in sasview
- 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
- Location:
- src/sas/sasgui/perspectives/fitting
- Files:
-
- 3 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): -
src/sas/sasgui/perspectives/fitting/fitpage.py
ree4b3cb r6c382da 10 10 import math 11 11 import time 12 import traceback 12 13 13 14 from sasmodels.weights import MODELS as POLYDISPERSITY_MODELS … … 2058 2059 msg = "Error: This model state has missing or outdated " 2059 2060 msg += "information.\n" 2060 msg += "%s" % (sys.exc_value)2061 msg += traceback.format_exc() 2061 2062 wx.PostEvent(self._manager.parent, 2062 2063 StatusEvent(status=msg, info="error")) -
src/sas/sasgui/perspectives/fitting/pagestate.py
r654e8e0 r6c382da 24 24 from xml.dom.minidom import parseString 25 25 from lxml import etree 26 27 import sasmodels.weights 26 28 27 29 import sas.sascalc.dataloader … … 474 476 value = content[1] 475 477 except Exception: 476 logging.error(traceback.format_exc()) 478 msg = "Report string expected 'name: value' but got %r"%line 479 logging.error(msg) 477 480 if name.count("State created"): 478 481 repo_time = "" + value … … 516 519 title_name = HEADER % title 517 520 except Exception: 518 logging.error(traceback.format_exc()) 521 msg = "While parsing 'data: ...'\n" 522 logging.error(msg + traceback.format_exc()) 519 523 if name == "model name ": 520 524 try: … … 531 535 q_range = CENTRE % q_name 532 536 except Exception: 533 logging.error(traceback.format_exc()) 537 msg = "While parsing 'Plotting Range: ...'\n" 538 logging.error(msg + traceback.format_exc()) 534 539 paramval = "" 535 540 for lines in param_string.split(":"): … … 711 716 # For self.values ={ disp_param_name: [vals,...],...} 712 717 # and for self.weights ={ disp_param_name: [weights,...],...} 713 value_list = {}714 718 for item in LIST_OF_MODEL_ATTRIBUTES: 715 719 element = newdoc.createElement(item[0]) … … 725 729 726 730 # Create doc for the dictionary of self._disp_obj_dic 727 for item in DISPERSION_LIST: 728 element = newdoc.createElement(item[0]) 729 value_list = getattr(self, item[1]) 730 for key, val in value_list.iteritems(): 731 value = repr(val) 731 for tagname, varname, tagtype in DISPERSION_LIST: 732 element = newdoc.createElement(tagname) 733 value_list = getattr(self, varname) 734 for key, value in value_list.iteritems(): 732 735 sub_element = newdoc.createElement(key) 733 736 sub_element.setAttribute('name', str(key)) … … 847 850 # Recover _disp_obj_dict from xml file 848 851 self._disp_obj_dict = {} 849 for item in DISPERSION_LIST: 850 # Get node 851 node = get_content("ns:%s" % item[0], entry) 852 for tagname, varname, tagtype in DISPERSION_LIST: 853 node = get_content("ns:%s" % tagname, entry) 852 854 for attr in node: 853 name = str(attr.get('name')) 854 val = attr.get('value') 855 value = val.split(" instance")[0] 856 disp_name = value.split("<")[1] 857 try: 858 # Try to recover disp_model object from strings 859 com = "from sas.models.dispersion_models " 860 com += "import %s as disp" 861 com_name = disp_name.split(".")[3] 862 exec com % com_name 863 disp_model = disp() 864 attribute = getattr(self, item[1]) 865 attribute[name] = com_name 866 except Exception: 867 logging.error(traceback.format_exc()) 855 parameter = str(attr.get('name')) 856 value = attr.get('value') 857 if value.startswith("<"): 858 try: 859 # <path.to.NamedDistribution object/instance...> 860 cls_name = value[1:].split()[0].split('.')[-1] 861 cls = getattr(sasmodels.weights, cls_name) 862 value = cls.type 863 except Exception: 864 logging.error("unable to load distribution %r for %s" 865 % (value, parameter)) 866 continue 867 _disp_obj_dict = getattr(self, varname) 868 _disp_obj_dict[parameter] = value 868 869 869 870 # get self.values and self.weights dic. if exists 870 for itemin LIST_OF_MODEL_ATTRIBUTES:871 node = get_content("ns:%s" % item[0], entry)871 for tagname, varname in LIST_OF_MODEL_ATTRIBUTES: 872 node = get_content("ns:%s" % tagname, entry) 872 873 dic = {} 873 874 value_list = [] 874 875 for par in node: 875 876 name = par.get('name') 876 values = par.text.split( '\n')877 values = par.text.split() 877 878 # Get lines only with numbers 878 879 for line in values: … … 882 883 except Exception: 883 884 # pass if line is empty (it happens) 884 logging.error(traceback.format_exc()) 885 msg = ("Error reading %r from %s %s\n" 886 % (line, tagname, name)) 887 logging.error(msg + traceback.format_exc()) 885 888 dic[name] = numpy.array(value_list) 886 setattr(self, item[1], dic)889 setattr(self, varname, dic) 887 890 888 891 def set_plot_state(self, figs, canvases): … … 1231 1234 1232 1235 except: 1233 logging.info("XML document does not contain fitting information.\n %s" % sys.exc_value) 1236 logging.info("XML document does not contain fitting information.\n" 1237 + traceback.format_exc()) 1234 1238 1235 1239 return state
Note: See TracChangeset
for help on using the changeset viewer.