Changeset e89aed5 in sasview for src/sas/sasgui
- Timestamp:
- Oct 6, 2016 3:47:28 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:
- 1dbdb83
- Parents:
- ef3e09b
- Location:
- src/sas/sasgui/perspectives/fitting
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/fitting.py
rca4d985 re89aed5 593 593 : param datainfo: data 594 594 """ 595 #state = self.state_reader.get_state() 596 if state != None: 595 from pagestate import PageState 596 from simfitpage import SimFitPageState 597 if isinstance(state, PageState): 597 598 state = state.clone() 598 # store fitting state in temp_state599 599 self.temp_state.append(state) 600 elif isinstance(state, SimFitPageState): 601 state.load_from_save_state(self) 600 602 else: 601 603 self.temp_state = [] -
src/sas/sasgui/perspectives/fitting/pagestate.py
ra95ae9a re89aed5 860 860 :param file: .fitv file 861 861 :param node: node of a XML document to read from 862 863 862 """ 864 863 if file is not None: … … 867 866 raise RuntimeError, msg 868 867 869 if node.get('version') and node.get('version') == '1.0':868 if node.get('version') and node.get('version') == '1.0': 870 869 871 870 # Get file name … … 1272 1271 1273 1272 :param entry: XML node to read from 1274 1275 1273 :return: PageState object 1276 1274 """ … … 1281 1279 nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME, 1282 1280 namespaces={'ns': CANSAS_NS}) 1283 if nodes != []:1281 if nodes: 1284 1282 # Create an empty state 1285 1283 state = PageState() … … 1291 1289 1292 1290 return state 1291 1292 def _parse_simfit_state(self, entry): 1293 """ 1294 Parses the saved data for a simultaneous fit 1295 :param entry: XML object to read from 1296 :return: XML object for a simultaneous fit or None 1297 """ 1298 nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME, 1299 namespaces={'ns': CANSAS_NS}) 1300 if nodes: 1301 simfitstate = nodes[0].xpath('ns:simultaneous_fit', 1302 namespaces={'ns': CANSAS_NS}) 1303 if simfitstate: 1304 from simfitpage import SimFitPageState 1305 sim_fit_state = SimFitPageState() 1306 simfitstate_0 = simfitstate[0] 1307 all = simfitstate_0.xpath('ns:select_all', 1308 namespaces={'ns': CANSAS_NS}) 1309 atts = all[0].attrib 1310 checked = atts.get('checked') 1311 sim_fit_state.select_all = bool(checked) 1312 model_list = simfitstate_0.xpath('ns:model_list', 1313 namespaces={'ns': CANSAS_NS}) 1314 model_list_items = model_list[0].xpath('ns:model_list_item', 1315 namespaces={'ns': CANSAS_NS}) 1316 for model in model_list_items: 1317 attrs = model.attrib 1318 sim_fit_state.model_list.append(attrs) 1319 constraints = simfitstate_0.xpath('ns:constraints', 1320 namespaces={'ns': CANSAS_NS}) 1321 constraint_list = constraints[0].xpath('ns:constraint', 1322 namespaces={'ns': CANSAS_NS}) 1323 for constraint in constraint_list: 1324 attrs = constraint.attrib 1325 sim_fit_state.constraints_list.append(attrs) 1326 1327 return sim_fit_state 1328 else: 1329 return None 1293 1330 1294 1331 def _parse_save_state_entry(self, dom): … … 1552 1589 def _read_cansas(self, path): 1553 1590 """ 1554 Load data and P(r)information from a CanSAS XML file.1591 Load data and fitting information from a CanSAS XML file. 1555 1592 1556 1593 :param path: file path 1557 1558 1594 :return: Data1D object if a single SASentry was found, 1559 1595 or a list of Data1D objects if multiple entries were found, 1560 1596 or None of nothing was found 1561 1562 1597 :raise RuntimeError: when the file can't be opened 1563 1598 :raise ValueError: when the length of the data vectors are inconsistent 1564 1565 1599 """ 1566 1600 output = [] 1601 simfitstate = None 1567 1602 basename = os.path.basename(path) 1568 1603 root, extension = os.path.splitext(basename) … … 1584 1619 raise 1585 1620 fitstate = self._parse_state(entry) 1621 simfitstate = self._parse_simfit_state(entry) 1586 1622 1587 1623 # state could be None when .svs file is loaded … … 1591 1627 sas_entry.filename = fitstate.file 1592 1628 output.append(sas_entry) 1629 1593 1630 else: 1594 1631 self.call_back(format=ext) … … 1634 1671 datainfo=output[ind], format=ext) 1635 1672 self.state = state 1673 if simfitstate is not None: 1674 self.call_back(state=simfitstate) 1675 1636 1676 return output 1637 1677 except: -
src/sas/sasgui/perspectives/fitting/simfitpage.py
ra95ae9a re89aed5 768 768 """ 769 769 Show constraint fields 770 :param dict: dictionary mapping constraint values 770 771 """ 771 772 self.btAdd.Show(True) … … 871 872 def _on_select_model(self, event): 872 873 """ 873 fill combo xbox with list of parameters874 fill combo box with list of parameters 874 875 """ 875 876 if not self.constraints_list: … … 1041 1042 # List of constraints 1042 1043 self.constraints_list = [] 1044 1045 def load_from_save_state(self, fit): 1046 """ 1047 Load in a simultaneous/constrained fit from a save state 1048 :param fit: Fitpanel object 1049 :return: None 1050 """ 1051 1052 model_map = {} 1053 fit.fit_panel.add_sim_page() 1054 1055 # Process each model and associate old M# with new M# 1056 i = 0 1057 for model in fit.fit_panel.sim_page.model_list: 1058 model_id = self._format_id(model[1].keys()[0]) 1059 for saved_model in self.model_list: 1060 save_id = saved_model.pop('name') 1061 saved_model['name'] = save_id 1062 save_id = self._format_id(save_id) 1063 if save_id == model_id: 1064 model_map[saved_model.pop('fit_page_source')] = \ 1065 model[3].name 1066 check = bool(saved_model.pop('checked')) 1067 fit.fit_panel.sim_page.model_list[i][0].SetValue(check) 1068 continue 1069 i += 1 1070 fit.fit_panel.sim_page.check_model_name(None) 1071 1072 if len(self.constraints_list) > 0: 1073 fit.fit_panel.sim_page.hide_constraint.SetValue(False) 1074 fit.fit_panel.sim_page.show_constraint.SetValue(True) 1075 fit.fit_panel.sim_page._display_constraint(None) 1076 1077 for constraint in self.constraints_list: 1078 model_cbox = constraint.pop('model_cbox') 1079 constraint_value = constraint.pop('constraint') 1080 for key, value in model_map.iteritems(): 1081 model_cbox.replace(key, value) 1082 constraint_value.replace(key, value) 1083 1084 bt_remove = wx.Button(fit.fit_panel.sim_page, 1085 fit.fit_panel.sim_page._ids.next(), 'Remove') 1086 bt_remove.Bind(wx.EVT_BUTTON, fit.fit_panel.sim_page.on_remove, 1087 id=bt_remove.GetId()) 1088 bt_remove.SetToolTipString("Remove constraint.") 1089 param_cbox = wx.ComboBox(fit.fit_panel.sim_page, wx.ID_ANY, 1090 style=wx.CB_READONLY, size=(100, -1)) 1091 egal_txt = wx.StaticText(fit.fit_panel.sim_page, wx.ID_ANY, " = ") 1092 # Model list 1093 model_cbox_sizer = wx.ComboBox(fit.fit_panel.sim_page, 1094 wx.ID_ANY, style=wx.CB_READONLY) 1095 model_cbox_sizer.Clear() 1096 wx.EVT_COMBOBOX(model_cbox_sizer, wx.ID_ANY, 1097 fit.fit_panel.sim_page._on_select_model) 1098 constraint_sizer = wx.TextCtrl(fit.fit_panel.sim_page, wx.ID_ANY) 1099 sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) 1100 sizer_constraint.Add((5, -1)) 1101 sizer_constraint.Add(model_cbox_sizer, flag=wx.RIGHT | wx.EXPAND, 1102 border=10) 1103 sizer_constraint.Add(param_cbox, flag=wx.RIGHT | wx.EXPAND, 1104 border=5) 1105 sizer_constraint.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 1106 sizer_constraint.Add(constraint_sizer, flag=wx.RIGHT | wx.EXPAND, 1107 border=10) 1108 sizer_constraint.Add(bt_remove, flag=wx.RIGHT | wx.EXPAND, 1109 border=10) 1110 new_const = ConstraintLine(model_cbox=model_cbox_sizer, 1111 param_cbox=constraint.pop('param_cbox'), 1112 egal_txt=constraint.pop('egal_txt'), 1113 constraint=constraint_value, 1114 btRemove=bt_remove, 1115 sizer=sizer_constraint 1116 ) 1117 # ConstraintLine = namedtuple('ConstraintLine', 1118 # 'model_cbox param_cbox egal_txt constraint btRemove sizer') 1119 fit.fit_panel.sim_page.sizer_constraints.Insert( 1120 before=fit.fit_panel.sim_page.nb_constraint, 1121 item=sizer_constraint, flag=wx.TOP | wx.BOTTOM | wx.EXPAND, 1122 border=5) 1123 fit.fit_panel.sim_page.constraints_list.append(new_const) 1124 1125 def _format_id(self, original_id): 1126 original_id = original_id.rstrip('1234567890.') 1127 new_id_list = original_id.split() 1128 new_id = ' '.join(new_id_list) 1129 return new_id
Note: See TracChangeset
for help on using the changeset viewer.