Changeset c8e1996 in sasview for src/sas/sasgui/perspectives/fitting/pagestate.py
- Timestamp:
- Oct 20, 2016 3:54:06 PM (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, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 880e845, cf1910f
- Parents:
- 8b645cc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/pagestate.py
r467202f rc8e1996 46 46 ["npts", "npts", "float"], 47 47 ["categorycombobox", "categorycombobox", "string"], 48 ["formfactorcombobox", "formfactorcombobox", "string"], 49 ["structurecombobox", "structurecombobox", "string"], 48 ["formfactorcombobox", "formfactorcombobox", 49 "string"], 50 ["structurecombobox", "structurecombobox", 51 "string"], 50 52 ["multi_factor", "multi_factor", "float"], 51 53 ["magnetic_on", "magnetic_on", "bool"], … … 65 67 ["smearer", "smearer", "float"], 66 68 ["smear_type", "smear_type", "string"], 67 ["dq_l", "dq_l", " string"],68 ["dq_r", "dq_r", " string"],69 ["dq_l", "dq_l", "float"], 70 ["dq_r", "dq_r", "float"], 69 71 ["dx_max", "dx_max", "float"], 70 72 ["dx_min", "dx_min", "float"], … … 80 82 ["str_parameters", "str_parameters"], 81 83 ["orientation_parameters", "orientation_params"], 82 ["dispersity_parameters", "orientation_params_disp"], 84 ["dispersity_parameters", 85 "orientation_params_disp"], 83 86 ["fixed_param", "fixed_param"], 84 87 ["fittable_param", "fittable_param"]] … … 120 123 try: 121 124 return node.get(item[0]).strip() == "True" 122 except :125 except Exception: 123 126 return None 124 127 else: 125 128 try: 126 129 return float(node.get(item[0])) 127 except :130 except Exception: 128 131 return None 129 132 … … 188 191 # page name 189 192 self.page_name = "" 190 # Contains link between model, allits parameters, and panel organization193 # Contains link between model, its parameters, and panel organization 191 194 self.parameters = [] 192 195 # String parameter list that can not be fitted … … 305 308 obj.fittable_param = copy.deepcopy(self.fittable_param) 306 309 obj.orientation_params = copy.deepcopy(self.orientation_params) 307 obj.orientation_params_disp = copy.deepcopy(self.orientation_params_disp) 310 obj.orientation_params_disp = \ 311 copy.deepcopy(self.orientation_params_disp) 308 312 obj.enable_disp = copy.deepcopy(self.enable_disp) 309 313 obj.disable_disp = copy.deepcopy(self.disable_disp) … … 397 401 rep += "data : %s\n" % str(self.data) 398 402 rep += "Plotting Range: min: %s, max: %s, steps: %s\n" % \ 399 (str(self.qmin), str(self.qmax), str(self.npts))403 (str(self.qmin), str(self.qmax), str(self.npts)) 400 404 rep += "Dispersion selection : %s\n" % str(self.disp_box) 401 405 rep += "Smearing enable : %s\n" % str(self.enable_smearer) … … 413 417 414 418 rep += "2D enable : %s\n" % str(self.enable2D) 415 rep += "All parameters checkbox selected: %s\n" % s tr(self.cb1)419 rep += "All parameters checkbox selected: %s\n" % self.cb1 416 420 rep += "Value of Chisqr : %s\n" % str(self.tcChi) 417 rep += "Smear object : %s\n" % s tr(self.smearer)418 rep += "Smear type : %s\n" % s tr(self.smear_type)421 rep += "Smear object : %s\n" % self.smearer 422 rep += "Smear type : %s\n" % self.smear_type 419 423 rep += "dq_l : %s\n" % self.dq_l 420 424 rep += "dq_r : %s\n" % self.dq_r … … 478 482 value = content[1] 479 483 except Exception: 480 msg = "Report string expected 'name: value' but got %r" %line484 msg = "Report string expected 'name: value' but got %r" % line 481 485 logging.error(msg) 482 486 if name.count("State created"): … … 493 497 if name == "value": 494 498 param_string += value + ',' 499 fixed_parameter = False 495 500 if name == "selected": 496 501 if value == u' False': 497 502 fixed_parameter = True 498 else:499 fixed_parameter = False500 503 if name == "error value": 501 504 if fixed_parameter: … … 617 620 dialog.Show() 618 621 619 def _to XML_helper(self, thelist, element, newdoc):622 def _to_xml_helper(self, thelist, element, newdoc): 620 623 """ 621 624 Helper method to create xml file for saving state … … 635 638 element.appendChild(sub_element) 636 639 637 def to XML(self, file="fitting_state.fitv", doc=None,638 entry_node=None, batch_fit_state=None):640 def to_xml(self, file="fitting_state.fitv", doc=None, 641 entry_node=None, batch_fit_state=None): 639 642 """ 640 643 Writes the state of the fit panel to file, as XML. … … 648 651 :param entry_node: XML node within the XML document at which we 649 652 will append the data [optional] 653 :param batch_fit_state: simultaneous fit state 650 654 """ 651 655 from xml.dom.minidom import getDOMImplementation … … 746 750 for item in LIST_OF_STATE_PARAMETERS: 747 751 element = newdoc.createElement(item[0]) 748 self._to XML_helper(thelist=getattr(self, item[1]),749 element=element, newdoc=newdoc)752 self._to_xml_helper(thelist=getattr(self, item[1]), 753 element=element, newdoc=newdoc) 750 754 inputs.appendChild(element) 751 755 … … 765 769 for constraint in batch_fit_state.constraints_list: 766 770 if constraint.model_cbox.GetValue() != "": 767 # model_cbox, param_cbox, egal_txt, constraint, btRemove, sizer 771 # model_cbox, param_cbox, egal_txt, constraint, 772 # btRemove, sizer 768 773 doc_cons = newdoc.createElement('constraint') 769 774 doc_cons.setAttribute('model_cbox', … … 808 813 return newdoc 809 814 810 def _from XML_helper(self, node, list):815 def _from_xml_helper(self, node, list): 811 816 """ 812 817 Helper function to write state to xml … … 858 863 [maximum_displayed, maximum_value], unit]) 859 864 860 def from XML(self, file=None, node=None):865 def from_xml(self, file=None, node=None): 861 866 """ 862 867 Load fitting state from a file … … 887 892 logging.error(msg) 888 893 889 # Parse fitting attributes890 entry = get_content('ns:Attributes', node)891 for item in LIST_OF_DATA_ATTRIBUTES:892 node = get_content('ns:%s' % item[0], entry)893 setattr(self, item[0], parse_entry_helper(node, item))894 895 894 if entry is not None: 895 # Parse fitting attributes 896 entry = get_content('ns:Attributes', node) 897 for item in LIST_OF_DATA_ATTRIBUTES: 898 node = get_content('ns:%s' % item[0], entry) 899 setattr(self, item[0], parse_entry_helper(node, item)) 900 896 901 for item in LIST_OF_STATE_ATTRIBUTES: 897 902 node = get_content('ns:%s' % item[0], entry) … … 900 905 for item in LIST_OF_STATE_PARAMETERS: 901 906 node = get_content("ns:%s" % item[0], entry) 902 self._fromXML_helper(node=node, list=getattr(self, item[1])) 907 self._from_xml_helper(node=node, 908 list=getattr(self, item[1])) 903 909 904 910 # Recover _disp_obj_dict from xml file … … 950 956 """ 951 957 images = [] 952 # some imports953 import wx954 958 955 959 # Reset memory … … 958 962 959 963 # For no figures in the list, prepare empty plot 960 if figs ==None or len(figs) == 0:964 if figs is None or len(figs) == 0: 961 965 figs = [None] 962 966 … … 965 969 self.imgRAM = wx.MemoryFSHandler() 966 970 for fig in figs: 967 if fig s !=None:971 if fig is not None: 968 972 ind = figs.index(fig) 969 973 canvas = canvases[ind] 970 974 971 # store the image in wx.FileSystem Object975 # store the image in wx.FileSystem Object 972 976 wx.FileSystem.AddHandler(wx.MemoryFSHandler()) 973 977 … … 975 979 ind = figs.index(fig) 976 980 977 # AddFile, image can be retrieved with 'memory:filename'981 # AddFile, image can be retrieved with 'memory:filename' 978 982 self.imgRAM.AddFile('img_fit%s.png' % ind, 979 983 canvas.bitmap, wx.BITMAP_TYPE_PNG) 980 984 981 # append figs985 # append figs 982 986 images.append(fig) 983 987 … … 989 993 Class to load a .fitv fitting file 990 994 """ 991 # #File type995 # File type 992 996 type_name = "Fitting" 993 997 994 # #Wildcards998 # Wildcards 995 999 type = ["Fitting files (*.fitv)|*.fitv" 996 1000 "SASView file (*.svs)|*.svs"] 997 # #List of allowed extensions1001 # List of allowed extensions 998 1002 ext = ['.fitv', '.FITV', '.svs', 'SVS'] 999 1003 … … 1009 1013 1010 1014 """ 1011 # #Call back method to be executed after a file is read1015 # Call back method to be executed after a file is read 1012 1016 self.call_back = call_back 1013 # #CanSAS format flag1017 # CanSAS format flag 1014 1018 self.cansas = cansas 1015 1019 self.state = None … … 1027 1031 1028 1032 """ 1029 if self.cansas == True:1033 if self.cansas: 1030 1034 return self._read_cansas(path) 1031 1035 … … 1061 1065 for item in datainfo.run: 1062 1066 runname = {} 1063 if datainfo.run_name.has_key(item)and \1067 if item in datainfo.run_name and \ 1064 1068 len(str(datainfo.run_name[item])) > 1: 1065 1069 runname = {'name': datainfo.run_name[item]} … … 1076 1080 root_node = doc.createElement(item[0]) 1077 1081 new_node.appendChild(root_node) 1078 temp_list = None1079 1082 temp_list = getattr(datainfo, item[1]) 1080 1083 … … 1113 1116 datainfo.sample.position.z, 1114 1117 {"unit": datainfo.sample.position_unit}) 1115 if written == True:1118 if written: 1116 1119 sample.appendChild(pos) 1117 1120 … … 1121 1124 written = written | write_node(doc, ori, "pitch", 1122 1125 datainfo.sample.orientation.y, 1123 {"unit": datainfo.sample.orientation_unit}) 1126 {"unit": 1127 datainfo.sample.orientation_unit}) 1124 1128 written = written | write_node(doc, ori, "yaw", 1125 1129 datainfo.sample.orientation.z, 1126 {"unit": datainfo.sample.orientation_unit}) 1127 if written == True: 1130 {"unit": 1131 datainfo.sample.orientation_unit}) 1132 if written: 1128 1133 sample.appendChild(ori) 1129 1134 … … 1153 1158 datainfo.source.beam_size.z, 1154 1159 {"unit": datainfo.source.beam_size_unit}) 1155 if written == True:1160 if written: 1156 1161 source.appendChild(size) 1157 1162 … … 1198 1203 written = written | write_node(doc, size, "z", apert.size.z, 1199 1204 {"unit": apert.size_unit}) 1200 if written == True:1205 if written: 1201 1206 ap.appendChild(size) 1202 1207 … … 1210 1215 item.slit_length, 1211 1216 {"unit": item.slit_length_unit}) 1212 if written == True:1217 if written: 1213 1218 instr.appendChild(det) 1214 1219 … … 1220 1225 written = written | write_node(doc, off, "z", item.offset.z, 1221 1226 {"unit": item.offset_unit}) 1222 if written == True:1227 if written: 1223 1228 det.appendChild(off) 1224 1229 … … 1232 1237 item.beam_center.z, 1233 1238 {"unit": item.beam_center_unit}) 1234 if written == True:1239 if written: 1235 1240 det.appendChild(center) 1236 1241 … … 1242 1247 written = written | write_node(doc, pix, "z", item.pixel_size.z, 1243 1248 {"unit": item.pixel_size_unit}) 1244 if written == True:1249 if written: 1245 1250 det.appendChild(pix) 1246 1251 … … 1253 1258 written = written | write_node(doc, ori, "yaw", item.orientation.z, 1254 1259 {"unit": item.orientation_unit}) 1255 if written == True:1260 if written: 1256 1261 det.appendChild(ori) 1257 1262 … … 1290 1295 # Create an empty state 1291 1296 state = PageState() 1292 state.from XML(node=nodes[0])1297 state.from_xml(node=nodes[0]) 1293 1298 1294 1299 except: … … 1314 1319 simfitstate_0 = simfitstate[0] 1315 1320 all = simfitstate_0.xpath('ns:select_all', 1316 namespaces={'ns': CANSAS_NS})1321 namespaces={'ns': CANSAS_NS}) 1317 1322 atts = all[0].attrib 1318 1323 checked = atts.get('checked') 1319 1324 sim_fit_state.select_all = bool(checked) 1320 1325 model_list = simfitstate_0.xpath('ns:model_list', 1321 namespaces={'ns': CANSAS_NS})1326 namespaces={'ns': CANSAS_NS}) 1322 1327 model_list_items = model_list[0].xpath('ns:model_list_item', 1323 namespaces={'ns': CANSAS_NS}) 1328 namespaces={'ns': 1329 CANSAS_NS}) 1324 1330 for model in model_list_items: 1325 1331 attrs = model.attrib … … 1368 1374 return return_value, _ 1369 1375 1370 # Parse 2D1376 # Parse 2D 1371 1377 data_info = Data2D() 1372 1378 … … 1590 1596 for entry in nodes: 1591 1597 for item in LIST_OF_DATA_2D_ATTR: 1592 # get node1598 # get node 1593 1599 node = get_content('ns:%s' % item[0], entry) 1594 1600 setattr(data_info, item[1], parse_entry_helper(node, item)) … … 1633 1639 entry_list = root.xpath('ns:SASentry', 1634 1640 namespaces={'ns': CANSAS_NS}) 1635 name_map = {}1636 1641 for entry in entry_list: 1637 1642 try: … … 1679 1684 state.data.is_data = state.is_data 1680 1685 if output[ind].run_name is not None\ 1681 and len(output[ind].run_name) != 0:1686 and len(output[ind].run_name) != 0: 1682 1687 if isinstance(output[ind].run_name, dict): 1683 1688 name = output[ind].run_name.keys()[0] … … 1715 1720 # Write the XML document 1716 1721 else: 1717 doc = fitstate.to XML(file=filename)1722 doc = fitstate.to_xml(file=filename) 1718 1723 1719 1724 # Save the document no matter the type … … 1749 1754 1750 1755 if state is not None: 1751 doc = state.to XML(doc=doc, file=data.filename, entry_node=sasentry,1752 batch_fit_state=self.batchfit_params)1756 doc = state.to_xml(doc=doc, file=data.filename, entry_node=sasentry, 1757 batch_fit_state=self.batchfit_params) 1753 1758 1754 1759 return doc
Note: See TracChangeset
for help on using the changeset viewer.