Changeset b1e609c in sasview
- Timestamp:
- Mar 6, 2015 4:01:40 PM (10 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:
- 239c890, 66f21cd
- Parents:
- 8b21fa7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/fitting/pagestate.py
r2f4b430 rb1e609c 2 2 Class that holds a fit page state 3 3 """ 4 #TODO: Refactor code so we don't need to use getattr/setattr 4 5 ################################################################################ 5 6 #This software was developed by the University of Tennessee as part of the … … 35 36 CANSAS_NS = "cansas1d/1.0" 36 37 37 list_of_data_attributes= [["is_data", "is_data", "bool"],38 ["group_id", "data_group_id", "string"],39 ["data_name", "data_name", "string"],40 ["data_id", "data_id", "string"],41 ["name", "name", "string"],42 ["data_name", "data_name", "string"]]43 list_of_state_attributes= [["engine_type", "engine_type", "string"],44 ["qmin", "qmin", "float"],45 ["qmax", "qmax", "float"],46 ["npts", "npts", "float"],47 ["categorycombobox", "categorycombobox", "string"],48 ["formfactorcombobox", "formfactorcombobox", "string"],49 ["structurecombobox", "structurecombobox", "string"],50 ["multi_factor", "multi_factor", "float"],51 ["magnetic_on", "magnetic_on", "bool"],52 ["enable_smearer", "enable_smearer", "bool"],53 ["disable_smearer", "disable_smearer", "bool"],54 ["pinhole_smearer", "pinhole_smearer", "bool"],55 ["slit_smearer", "slit_smearer", "bool"],56 ["enable_disp", "enable_disp", "bool"],57 ["disable_disp", "disable_disp", "bool"],58 ["dI_noweight", "dI_noweight", "bool"],59 ["dI_didata", "dI_didata", "bool"],60 ["dI_sqrdata", "dI_sqrdata", "bool"],61 ["dI_idata", "dI_idata", "bool"],62 ["enable2D", "enable2D", "bool"],63 ["cb1", "cb1", "bool"],64 ["tcChi", "tcChi", "float"],65 ["smearer", "smearer", "float"],66 ["smear_type", "smear_type", "string"],67 ["dq_l", "dq_l", "string"],68 ["dq_r", "dq_r", "string"],69 ["dx_max", "dx_max", "float"],70 ["dx_min", "dx_min", "float"],71 ["dxl", "dxl", "float"],72 ["dxw", "dxw", "float"]]73 74 list_of_model_attributes= [["values", "values"],38 LIST_OF_DATA_ATTRIBUTES = [["is_data", "is_data", "bool"], 39 ["group_id", "data_group_id", "string"], 40 ["data_name", "data_name", "string"], 41 ["data_id", "data_id", "string"], 42 ["name", "name", "string"], 43 ["data_name", "data_name", "string"]] 44 LIST_OF_STATE_ATTRIBUTES = [["engine_type", "engine_type", "string"], 45 ["qmin", "qmin", "float"], 46 ["qmax", "qmax", "float"], 47 ["npts", "npts", "float"], 48 ["categorycombobox", "categorycombobox", "string"], 49 ["formfactorcombobox", "formfactorcombobox", "string"], 50 ["structurecombobox", "structurecombobox", "string"], 51 ["multi_factor", "multi_factor", "float"], 52 ["magnetic_on", "magnetic_on", "bool"], 53 ["enable_smearer", "enable_smearer", "bool"], 54 ["disable_smearer", "disable_smearer", "bool"], 55 ["pinhole_smearer", "pinhole_smearer", "bool"], 56 ["slit_smearer", "slit_smearer", "bool"], 57 ["enable_disp", "enable_disp", "bool"], 58 ["disable_disp", "disable_disp", "bool"], 59 ["dI_noweight", "dI_noweight", "bool"], 60 ["dI_didata", "dI_didata", "bool"], 61 ["dI_sqrdata", "dI_sqrdata", "bool"], 62 ["dI_idata", "dI_idata", "bool"], 63 ["enable2D", "enable2D", "bool"], 64 ["cb1", "cb1", "bool"], 65 ["tcChi", "tcChi", "float"], 66 ["smearer", "smearer", "float"], 67 ["smear_type", "smear_type", "string"], 68 ["dq_l", "dq_l", "string"], 69 ["dq_r", "dq_r", "string"], 70 ["dx_max", "dx_max", "float"], 71 ["dx_min", "dx_min", "float"], 72 ["dxl", "dxl", "float"], 73 ["dxw", "dxw", "float"]] 74 75 LIST_OF_MODEL_ATTRIBUTES = [["values", "values"], 75 76 ["weights", "weights"]] 76 77 77 list_of_obj_dic= [["disp_obj_dict", "_disp_obj_dict", "string"]]78 79 list_of_state_parameters= [["parameters", "parameters"],78 DISPERSION_LIST = [["disp_obj_dict", "_disp_obj_dict", "string"]] 79 80 LIST_OF_STATE_PARAMETERS = [["parameters", "parameters"], 80 81 ["str_parameters", "str_parameters"], 81 82 ["orientation_parameters", "orientation_params"], … … 83 84 ["fixed_param", "fixed_param"], 84 85 ["fittable_param", "fittable_param"]] 85 list_of_data_2d_attr= [["xmin", "xmin", "float"],86 LIST_OF_DATA_2D_ATTR = [["xmin", "xmin", "float"], 86 87 ["xmax", "xmax", "float"], 87 88 ["ymin", "ymin", "float"], … … 93 94 ["_zaxis", "_zaxis", "string"], 94 95 ["_zunit", "_zunit", "string"]] 95 list_of_data2d_values= [["qx_data", "qx_data", "float"],96 ["qy_data", "qy_data", "float"],97 ["dqx_data", "dqx_data", "float"],98 ["dqy_data", "dqy_data", "float"],99 ["data", "data", "float"],100 ["q_data", "q_data", "float"],101 ["err_data", "err_data", "float"],102 ["mask", "mask", "bool"]]96 LIST_OF_DATA_2D_VALUES = [["qx_data", "qx_data", "float"], 97 ["qy_data", "qy_data", "float"], 98 ["dqx_data", "dqx_data", "float"], 99 ["dqy_data", "dqy_data", "float"], 100 ["data", "data", "float"], 101 ["q_data", "q_data", "float"], 102 ["err_data", "err_data", "float"], 103 ["mask", "mask", "bool"]] 103 104 104 105 … … 393 394 else: 394 395 rep += "model name : None\n" 395 #rep += "model type (form factor) selected: %s\n" % self.shape_rbutton396 396 rep += "multi_factor : %s\n" % str(self.multi_factor) 397 397 rep += "magnetic_on : %s\n" % str(self.magnetic_on) 398 398 rep += "model type (Category) selected: %s\n" % self.categorycombobox 399 #rep += "model type (shape independent) selected: %s\n" % self.shape_indep_rbutton400 #rep += "model type (structure factor) selected: %s\n" % self.struct_rbutton401 #rep += "model type (plug-in ) selected: %s\n" % self.plugin_rbutton402 399 rep += "data : %s\n" % str(self.data) 403 400 rep += "Plotting Range: min: %s, max: %s, steps: %s\n" % (str(self.qmin), 404 str(self.qmax), str(self.npts))401 str(self.qmax), str(self.npts)) 405 402 rep += "Dispersion selection : %s\n" % str(self.disp_box) 406 403 rep += "Smearing enable : %s\n" % str(self.enable_smearer) … … 453 450 rep += "number fittable_param(self.fittable_param): %s\n" % len(temp_fittable_param) 454 451 rep = self._repr_helper(list=temp_fittable_param, rep=rep) 455 """456 if is_2D:457 rep += "number orientation parameters"458 rep += "(self.orientation_params): %s\n"%len(self.orientation_params)459 rep = self._repr_helper( list=self.orientation_params, rep=rep)460 rep += "number dispersity parameters"461 rep += "(self.orientation_params_disp): %s\n"%len(self.orientation_params_disp)462 rep = self._repr_helper( list=self.orientation_params_disp, rep=rep)463 """464 452 return rep 465 453 … … 477 465 paramval_string = "" 478 466 chi2_string = "" 479 multi_factor_string = ""480 467 q_range = "" 481 468 strings = self.__repr__() … … 490 477 value = content[1] 491 478 except: 492 pass479 logging.error(sys.exc_value) 493 480 if name.count("State created"): 494 481 repo_time = "" + value … … 504 491 if name == "value": 505 492 param_string += value + ',' 506 507 508 509 510 493 if name == "selected": 494 if value == u' False': 495 fixed_parameter = True 496 else: 497 fixed_parameter = False 511 498 if name == "error value": 512 513 514 499 if fixed_parameter: 500 param_string += '(fixed),' 501 else: 515 502 param_string += value + ',' 516 503 if name == "parameter unit": … … 519 506 chi2 = ("Chi2/Npts = " + value) 520 507 chi2_string = CENTRE % chi2 521 if name == "multi_factor ":522 muti_factor = ("muti_factor = " + value)523 muti_factor_string = CENTRE % muti_factor524 if name == "magentic_on ":525 magentic_on = ("magentic_on = " + value)526 if string(value) == 'True':527 magentic_on_string = CENTRE % magentic_on528 508 if name == "Title": 529 509 if len(value.strip()) == 0: … … 533 513 if name == "data ": 534 514 try: 535 file = ("File name:" + content[2])536 file_name = CENTRE % file 515 file_value = ("File name:" + content[2]) 516 file_name = CENTRE % file_value 537 517 if len(title) == 0: 538 518 title = content[2] + " [" + repo_time + "]" 539 519 title_name = HEADER % title 540 520 except: 541 pass521 logging.error(sys.exc_value) 542 522 if name == "model name ": 543 523 try: … … 554 534 q_range = CENTRE % q_name 555 535 except: 556 pass536 logging.error(sys.exc_value) 557 537 paramval = "" 558 538 for lines in param_string.split(":"): … … 725 705 self.data_id = self.data.id 726 706 727 for item in list_of_data_attributes:707 for item in LIST_OF_DATA_ATTRIBUTES: 728 708 element = newdoc.createElement(item[0]) 729 e xec "element.setAttribute(item[0], str(self.%s))" % (item[1])709 element.setAttribute(item[0], str(getattr(self, item[1]))) 730 710 inputs.appendChild(element) 731 711 732 for item in list_of_state_attributes:712 for item in LIST_OF_STATE_ATTRIBUTES: 733 713 element = newdoc.createElement(item[0]) 734 e xec "element.setAttribute(item[0], str(self.%s))" % (item[1])714 element.setAttribute(item[0], str(getattr(self, item[1]))) 735 715 inputs.appendChild(element) 736 716 737 717 # For self.values ={ disp_param_name: [vals,...],...} 738 718 # and for self.weights ={ disp_param_name: [weights,...],...} 739 list = {}740 for item in list_of_model_attributes:719 value_list = {} 720 for item in LIST_OF_MODEL_ATTRIBUTES: 741 721 element = newdoc.createElement(item[0]) 742 exec "list = self.%s" % item[1]743 for key, value in list.iteritems():722 value_list = getattr(self, item[1]) 723 for key, value in value_list.iteritems(): 744 724 sub_element = newdoc.createElement(key) 745 725 sub_element.setAttribute('name', str(key)) 746 726 for val in value: 747 com = "sub_element.appendChild" 748 com += "(newdoc.createTextNode(str(%s)))" 749 exec com % val 727 sub_element.appendChild(newdoc.createTextNode(str(val))) 750 728 751 729 element.appendChild(sub_element) … … 753 731 754 732 # Create doc for the dictionary of self._disp_obj_dic 755 for item in list_of_obj_dic:733 for item in DISPERSION_LIST: 756 734 element = newdoc.createElement(item[0]) 757 exec "list = self.%s" % item[1]758 for key, val in list.iteritems():735 value_list = getattr(self, item[1]) 736 for key, val in value_list.iteritems(): 759 737 value = repr(val) 760 738 sub_element = newdoc.createElement(key) … … 764 742 inputs.appendChild(element) 765 743 766 for item in list_of_state_parameters:744 for item in LIST_OF_STATE_PARAMETERS: 767 745 element = newdoc.createElement(item[0]) 768 com = "self._toXML_helper(thelist=self.%s," 769 com += " element=element, newdoc=newdoc)" 770 exec com % item[1] 746 self._toXML_helper(thelist=getattr(self, item[1]), element=element, newdoc=newdoc) 771 747 inputs.appendChild(element) 772 748 … … 862 838 # Parse fitting attributes 863 839 entry = get_content('ns:Attributes', node) 864 for item in list_of_data_attributes:840 for item in LIST_OF_DATA_ATTRIBUTES: 865 841 node = get_content('ns:%s' % item[0], entry) 866 try: 867 exec "self.%s = parse_entry_helper(node, item)" % item[0] 868 869 except: 870 raise 842 setattr(self, item[0], parse_entry_helper(node, item)) 871 843 872 844 if entry is not None: 873 874 for item in list_of_state_attributes: 845 for item in LIST_OF_STATE_ATTRIBUTES: 875 846 node = get_content('ns:%s' % item[0], entry) 876 try: 877 exec "self.%s = parse_entry_helper(node, item)" % \ 878 str(item[0]) 879 except: 880 raise 881 882 for item in list_of_state_parameters: 847 setattr(self, item[0], parse_entry_helper(node, item)) 848 849 for item in LIST_OF_STATE_PARAMETERS: 883 850 node = get_content("ns:%s" % item[0], entry) 884 exec "self._fromXML_helper(node=node, list=self.%s)" % \ 885 item[1] 851 self._fromXML_helper(node=node, list=getattr(self, item[1])) 886 852 887 853 # Recover _disp_obj_dict from xml file 888 854 self._disp_obj_dict = {} 889 disp_model = None 890 for item in list_of_obj_dic: 855 for item in DISPERSION_LIST: 891 856 # Get node 892 857 node = get_content("ns:%s" % item[0], entry) 893 858 for attr in node: 894 name = attr.get('name')859 name = str(attr.get('name')) 895 860 val = attr.get('value') 896 861 value = val.split(" instance")[0] … … 903 868 exec com % com_name 904 869 disp_model = disp() 905 exec "self.%s['%s'] = com_name" % (item[1], name) 870 attribute = getattr(self, item[1]) 871 attribute[name] = com_name 906 872 except: 907 pass873 logging.error(sys.exc_value) 908 874 909 875 # get self.values and self.weights dic. if exists 910 for item in list_of_model_attributes:876 for item in LIST_OF_MODEL_ATTRIBUTES: 911 877 node = get_content("ns:%s" % item[0], entry) 912 878 dic = {} 913 list = []879 value_list = [] 914 880 for par in node: 915 881 name = par.get('name') … … 919 885 try: 920 886 val = float(line) 921 list.append(val)887 value_list.append(val) 922 888 except: 923 889 # pass if line is empty (it happens) 924 pass925 dic[name] = numpy.array( list)926 exec "self.%s = dic" % item[1]890 logging.error(sys.exc_value) 891 dic[name] = numpy.array(value_list) 892 setattr(self, item[1], dic) 927 893 928 894 def set_plot_state(self, figs, canvases): … … 952 918 canvas = canvases[ind] 953 919 954 #store the image in wx.FileSystem Object 920 #store the image in wx.FileSystem Object 955 921 wx.FileSystem.AddHandler(wx.MemoryFSHandler()) 956 922 … … 1026 992 main_node.setAttribute("xmlns", "cansas1d/%s" % self.version) 1027 993 main_node.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance") 1028 main_node.setAttribute("xsi:schemaLocation", "cansas1d/%s http://svn.smallangles.net/svn/canSAS/1dwg/trunk/cansas1d.xsd" % self.version) 994 main_node.setAttribute("xsi:schemaLocation", 995 "cansas1d/%s http://svn.smallangles.net/svn/canSAS/1dwg/trunk/cansas1d.xsd" % self.version) 1029 996 1030 997 doc.appendChild(main_node) … … 1039 1006 runname = {} 1040 1007 if datainfo.run_name.has_key(item) and len(str(datainfo.run_name[item])) > 1: 1041 runname = {'name': datainfo.run_name[item] 1008 runname = {'name': datainfo.run_name[item]} 1042 1009 write_node(doc, entry_node, "Run", item, runname) 1043 1010 # Data info 1044 1011 new_node = doc.createElement("SASdata") 1045 1012 entry_node.appendChild(new_node) 1046 for item in list_of_data_2d_attr:1013 for item in LIST_OF_DATA_2D_ATTR: 1047 1014 element = doc.createElement(item[0]) 1048 e xec "element.setAttribute(item[0], str(datainfo.%s))" % (item[1])1015 element.setAttribute(item[0], str(getattr(datainfo, item[1]))) 1049 1016 new_node.appendChild(element) 1050 1017 1051 for item in list_of_data2d_values:1018 for item in LIST_OF_DATA_2D_VALUES: 1052 1019 root_node = doc.createElement(item[0]) 1053 1020 new_node.appendChild(root_node) 1054 1021 temp_list = None 1055 exec "temp_list = datainfo.%s" % item[1]1022 temp_list = getattr(datainfo, item[1]) 1056 1023 1057 1024 if temp_list is None or len(temp_list) == 0: 1058 1025 element = doc.createElement(item[0]) 1059 e xec "element.appendChild(doc.createTextNode(str(%s)))" % temp_list1026 element.appendChild(doc.createTextNode(str(temp_list))) 1060 1027 root_node.appendChild(element) 1061 1028 else: 1062 1029 for value in temp_list: 1063 1030 element = doc.createElement(item[0]) 1064 e xec "element.setAttribute(item[0], str(%s))" % value1031 element.setAttribute(item[0], str(value)) 1065 1032 root_node.appendChild(element) 1066 1033 … … 1342 1309 data_info.sample.name = entry.get('name') 1343 1310 1344 self._store_content('ns:SASsample/ns:ID', 1345 dom, 'ID', data_info.sample) 1346 self._store_float('ns:SASsample/ns:thickness', 1347 dom, 'thickness', data_info.sample) 1348 self._store_float('ns:SASsample/ns:transmission', 1349 dom, 'transmission', data_info.sample) 1350 self._store_float('ns:SASsample/ns:temperature', 1351 dom, 'temperature', data_info.sample) 1352 1353 nodes = dom.xpath('ns:SASsample/ns:details', 1354 namespaces={'ns': CANSAS_NS}) 1311 self._store_content('ns:SASsample/ns:ID', dom, 'ID', data_info.sample) 1312 self._store_float('ns:SASsample/ns:thickness', dom, 'thickness', data_info.sample) 1313 self._store_float('ns:SASsample/ns:transmission', dom, 'transmission', data_info.sample) 1314 self._store_float('ns:SASsample/ns:temperature', dom, 'temperature', data_info.sample) 1315 1316 nodes = dom.xpath('ns:SASsample/ns:details', namespaces={'ns': CANSAS_NS}) 1355 1317 for item in nodes: 1356 1318 try: … … 1365 1327 1366 1328 # Position (as a vector) 1367 self._store_float('ns:SASsample/ns:position/ns:x', 1368 dom, 'position.x', data_info.sample) 1369 self._store_float('ns:SASsample/ns:position/ns:y', 1370 dom, 'position.y', data_info.sample) 1371 self._store_float('ns:SASsample/ns:position/ns:z', 1372 dom, 'position.z', data_info.sample) 1329 self._store_float('ns:SASsample/ns:position/ns:x', dom, 'position.x', data_info.sample) 1330 self._store_float('ns:SASsample/ns:position/ns:y', dom, 'position.y', data_info.sample) 1331 self._store_float('ns:SASsample/ns:position/ns:z', dom, 'position.z', data_info.sample) 1373 1332 1374 1333 # Orientation (as a vector) 1375 1334 self._store_float('ns:SASsample/ns:orientation/ns:roll', 1376 dom, 'orientation.x', data_info.sample)1335 dom, 'orientation.x', data_info.sample) 1377 1336 self._store_float('ns:SASsample/ns:orientation/ns:pitch', 1378 dom, 'orientation.y', data_info.sample)1337 dom, 'orientation.y', data_info.sample) 1379 1338 self._store_float('ns:SASsample/ns:orientation/ns:yaw', 1380 dom, 'orientation.z', data_info.sample)1339 dom, 'orientation.z', data_info.sample) 1381 1340 1382 1341 # Source info ################### … … 1386 1345 1387 1346 self._store_content('ns:SASinstrument/ns:SASsource/ns:radiation', 1388 dom, 'radiation', data_info.source)1347 dom, 'radiation', data_info.source) 1389 1348 self._store_content('ns:SASinstrument/ns:SASsource/ns:beam_shape', 1390 dom, 'beam_shape', data_info.source)1349 dom, 'beam_shape', data_info.source) 1391 1350 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength', 1392 dom, 'wavelength', data_info.source)1351 dom, 'wavelength', data_info.source) 1393 1352 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_min', 1394 dom, 'wavelength_min', data_info.source)1353 dom, 'wavelength_min', data_info.source) 1395 1354 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_max', 1396 dom, 'wavelength_max', data_info.source)1355 dom, 'wavelength_max', data_info.source) 1397 1356 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_spread', 1398 dom, 'wavelength_spread', data_info.source)1357 dom, 'wavelength_spread', data_info.source) 1399 1358 1400 1359 # Beam size (as a vector) … … 1404 1363 1405 1364 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:x', 1406 dom, 'beam_size.x', data_info.source)1365 dom, 'beam_size.x', data_info.source) 1407 1366 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:y', 1408 dom, 'beam_size.y', data_info.source)1367 dom, 'beam_size.y', data_info.source) 1409 1368 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:z', 1410 dom, 'beam_size.z', data_info.source)1369 dom, 'beam_size.z', data_info.source) 1411 1370 1412 1371 # Collimation info ################### … … 1522 1481 1523 1482 for entry in nodes: 1524 for item in list_of_data_2d_attr:1483 for item in LIST_OF_DATA_2D_ATTR: 1525 1484 #get node 1526 1485 node = get_content('ns:%s' % item[0], entry) 1527 exec "data_info.%s = parse_entry_helper(node, item)" % item[1]1528 1529 for item in list_of_data2d_values:1486 setattr(data_info, item[1], parse_entry_helper(node, item)) 1487 1488 for item in LIST_OF_DATA_2D_VALUES: 1530 1489 field = get_content('ns:%s' % item[0], entry) 1531 list = []1490 value_list = [] 1532 1491 if field is not None: 1533 list = [parse_entry_helper(node, item) for node in field]1534 if len( list) < 2:1535 exec "data_info.%s = None" % item[0]1492 value_list = [parse_entry_helper(node, item) for node in field] 1493 if len(value_list) < 2: 1494 setattr(data_info, item[0], None) 1536 1495 else: 1537 exec "data_info.%s = numpy.array(list)" % item[0]1496 setattr(data_info, item[0], numpy.array(value_list)) 1538 1497 1539 1498 return data_info … … 1606 1565 1607 1566 if state is not None and state.is_data is not None: 1608 exec 'output[%d].is_data = state.is_data' % ind1567 output[ind].is_data = state.is_data 1609 1568 1610 1569 output[ind].filename = state.file … … 1625 1584 self.state = state 1626 1585 return output 1627 1628 1586 except: 1629 1587 self.call_back(format=ext) 1630 #self.state= state1631 1588 raise 1632 1589
Note: See TracChangeset
for help on using the changeset viewer.