Changeset ba8d326 in sasview for src/sas/sascalc/fit
- Timestamp:
- Jun 23, 2017 4:16:29 PM (7 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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 98e3f24
- Parents:
- 81b35396
- git-author:
- Paul Kienzle <pkienzle@…> (06/21/17 12:38:48)
- git-committer:
- Paul Kienzle <pkienzle@…> (06/23/17 16:16:29)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/fit/pagestate.py
r81b35396 rba8d326 1 1 """ 2 2 Class that holds a fit page state 3 3 """ 4 4 # TODO: Refactor code so we don't need to use getattr/setattr … … 40 40 # Information to read/write state as xml 41 41 FITTING_NODE_NAME = 'fitting_plug_in' 42 CANSAS_NS = "cansas1d/1.0"42 CANSAS_NS = {"ns": "cansas1d/1.0"} 43 43 44 44 CUSTOM_MODEL = 'Plugin Models' … … 83 83 ["weights", "weights"]] 84 84 85 DISPERSION_LIST = [["disp_obj_dict", " _disp_obj_dict", "string"]]85 DISPERSION_LIST = [["disp_obj_dict", "disp_obj_dict", "string"]] 86 86 87 87 LIST_OF_STATE_PARAMETERS = [["parameters", "parameters"], … … 154 154 self.timestamp = time.time() 155 155 # Data member to store the dispersion object created 156 self. _disp_obj_dict = {}156 self.disp_obj_dict = {} 157 157 # ------------------------ 158 158 # Data used for fitting … … 271 271 # store value of chisqr 272 272 self.tcChi = None 273 self.version = (1, 0,0)273 self.version = (1, 0, 0) 274 274 275 275 def clone(self): … … 315 315 obj.tcChi = self.tcChi 316 316 317 if len(self. _disp_obj_dict) > 0:318 for k, v in self. _disp_obj_dict.iteritems():319 obj. _disp_obj_dict[k] = v317 if len(self.disp_obj_dict) > 0: 318 for k, v in self.disp_obj_dict.iteritems(): 319 obj.disp_obj_dict[k] = v 320 320 if len(self.disp_cb_dict) > 0: 321 321 for k, v in self.disp_cb_dict.iteritems(): … … 847 847 inputs.appendChild(element) 848 848 849 # Create doc for the dictionary of self. _disp_obj_dic849 # Create doc for the dictionary of self.disp_obj_dic 850 850 for tagname, varname, tagtype in DISPERSION_LIST: 851 851 element = newdoc.createElement(tagname) … … 928 928 """ 929 929 for item in node: 930 try: 931 name = item.get('name') 932 except: 933 name = None 934 try: 935 value = item.get('value') 936 except: 937 value = None 938 try: 939 selected_to_fit = (item.get('selected_to_fit') == "True") 940 except: 941 selected_to_fit = None 942 try: 943 error_displayed = (item.get('error_displayed') == "True") 944 except: 945 error_displayed = None 946 try: 947 error_value = item.get('error_value') 948 except: 949 error_value = None 950 try: 951 minimum_displayed = (item.get('minimum_displayed') == "True") 952 except: 953 minimum_displayed = None 954 try: 955 minimum_value = item.get('minimum_value') 956 except: 957 minimum_value = None 958 try: 959 maximum_displayed = (item.get('maximum_displayed') == "True") 960 except: 961 maximum_displayed = None 962 try: 963 maximum_value = item.get('maximum_value') 964 except: 965 maximum_value = None 966 try: 967 unit = item.get('unit') 968 except: 969 unit = None 930 name = item.get('name') 931 value = item.get('value') 932 selected_to_fit = (item.get('selected_to_fit') == "True") 933 error_displayed = (item.get('error_displayed') == "True") 934 error_value = item.get('error_value') 935 minimum_displayed = (item.get('minimum_displayed') == "True") 936 minimum_value = item.get('minimum_value') 937 maximum_displayed = (item.get('maximum_displayed') == "True") 938 maximum_value = item.get('maximum_value') 939 unit = item.get('unit') 970 940 list.append([selected_to_fit, name, value, "+/-", 971 941 [error_displayed, error_value], … … 1033 1003 list=getattr(self, item[1])) 1034 1004 1035 # Recover _disp_obj_dict from xml file1036 self. _disp_obj_dict = {}1005 # Recover disp_obj_dict from xml file 1006 self.disp_obj_dict = {} 1037 1007 for tagname, varname, tagtype in DISPERSION_LIST: 1038 1008 node = get_content("ns:%s" % tagname, entry) … … 1048 1018 except Exception: 1049 1019 base = "unable to load distribution %r for %s" 1050 logger.error(base % (value, parameter))1020 logger.error(base, value, parameter) 1051 1021 continue 1052 _disp_obj_dict = getattr(self, varname)1053 _disp_obj_dict[parameter] = value1022 disp_obj_dict = getattr(self, varname) 1023 disp_obj_dict[parameter] = value 1054 1024 1055 1025 # get self.values and self.weights dic. if exists … … 1074 1044 setattr(self, varname, dic) 1075 1045 1076 class SimFitPageState :1046 class SimFitPageState(object): 1077 1047 """ 1078 1048 State of the simultaneous fit page for saving purposes … … 1095 1065 self.constraints_list = [] 1096 1066 1067 def __repr__(self): 1068 # TODO: should use __str__, not __repr__ (similarly for PageState) 1069 # TODO: could use a nicer representation 1070 repr = """\ 1071 fit page number : %(fit_page_no)s 1072 select all : %(select_all)s 1073 model_list : %(model_list)s 1074 model to fit : %(model_to_fit)s 1075 number of construsts : %(no_constraint)s 1076 constraint dict : %(constraint_dict)s 1077 constraints list : %(constraints_list)s 1078 """%self.__dict__ 1079 return repr 1080 1097 1081 class Reader(CansasReader): 1098 1082 """ … … 1152 1136 try: 1153 1137 nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME, 1154 namespaces= {'ns': CANSAS_NS})1138 namespaces=CANSAS_NS) 1155 1139 if nodes: 1156 1140 # Create an empty state … … 1158 1142 state.from_xml(node=nodes[0]) 1159 1143 1160 except :1144 except Exception: 1161 1145 logger.info("XML document does not contain fitting information.\n" 1162 1146 + traceback.format_exc()) 1163 1147 1164 1148 return state … … 1171 1155 """ 1172 1156 nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME, 1173 namespaces= {'ns': CANSAS_NS})1157 namespaces=CANSAS_NS) 1174 1158 if nodes: 1175 1159 simfitstate = nodes[0].xpath('ns:simultaneous_fit', 1176 namespaces= {'ns': CANSAS_NS})1160 namespaces=CANSAS_NS) 1177 1161 if simfitstate: 1178 1162 sim_fit_state = SimFitPageState() 1179 1163 simfitstate_0 = simfitstate[0] 1180 1164 all = simfitstate_0.xpath('ns:select_all', 1181 namespaces= {'ns': CANSAS_NS})1165 namespaces=CANSAS_NS) 1182 1166 atts = all[0].attrib 1183 1167 checked = atts.get('checked') 1184 1168 sim_fit_state.select_all = bool(checked) 1185 1169 model_list = simfitstate_0.xpath('ns:model_list', 1186 namespaces= {'ns': CANSAS_NS})1170 namespaces=CANSAS_NS) 1187 1171 model_list_items = model_list[0].xpath('ns:model_list_item', 1188 namespaces={'ns': 1189 CANSAS_NS}) 1172 namespaces=CANSAS_NS) 1190 1173 for model in model_list_items: 1191 1174 attrs = model.attrib … … 1193 1176 1194 1177 constraints = simfitstate_0.xpath('ns:constraints', 1195 namespaces={'ns': CANSAS_NS})1178 namespaces=CANSAS_NS) 1196 1179 constraint_list = constraints[0].xpath('ns:constraint', 1197 namespaces={'ns': CANSAS_NS})1180 namespaces=CANSAS_NS) 1198 1181 for constraint in constraint_list: 1199 1182 attrs = constraint.attrib … … 1213 1196 1214 1197 """ 1215 node = dom.xpath('ns:data_class', namespaces= {'ns': CANSAS_NS})1198 node = dom.xpath('ns:data_class', namespaces=CANSAS_NS) 1216 1199 return_value, _ = self._parse_entry(dom) 1217 1200 return return_value, _ … … 1242 1225 root = tree.getroot() 1243 1226 entry_list = root.xpath('ns:SASentry', 1244 namespaces= {'ns': CANSAS_NS})1227 namespaces=CANSAS_NS) 1245 1228 for entry in entry_list: 1246 1229 try: … … 1266 1249 return None 1267 1250 else: 1268 for ind in range(len(output)):1251 for data in output: 1269 1252 # Call back to post the new state 1270 state = output[ind].meta_data['fitstate']1253 state = data.meta_data['fitstate'] 1271 1254 t = time.localtime(state.timestamp) 1272 1255 time_str = time.strftime("%b %d %H:%M", t) … … 1279 1262 1280 1263 if state is not None and state.is_data is not None: 1281 output[ind].is_data = state.is_data1282 1283 output[ind].filename = state.file1284 state.data = output[ind]1285 state.data.name = output[ind].filename # state.data_name1264 data.is_data = state.is_data 1265 1266 data.filename = state.file 1267 state.data = data 1268 state.data.name = data.filename # state.data_name 1286 1269 state.data.id = state.data_id 1287 1270 if state.is_data is not None: 1288 1271 state.data.is_data = state.is_data 1289 if output[ind].run_name is not None\1290 and len(output[ind].run_name) != 0:1291 if isinstance(output[ind].run_name, dict):1292 name = output[ind].run_name.keys()[0]1272 if data.run_name is not None and len(data.run_name) != 0: 1273 if isinstance(data.run_name, dict): 1274 # Note: key order in dict is not guaranteed, so sort 1275 name = data.run_name.keys()[0] 1293 1276 else: 1294 name = output[ind].run_name1277 name = data.run_name 1295 1278 else: 1296 1279 name = original_fname … … 1298 1281 state.version = fitstate.version 1299 1282 # store state in fitting 1300 self.call_back(state=state, 1301 datainfo=output[ind], format=ext) 1283 self.call_back(state=state, datainfo=data, format=ext) 1302 1284 self.state = state 1303 1285 simfitstate = self._parse_simfit_state(entry)
Note: See TracChangeset
for help on using the changeset viewer.