- Timestamp:
- Aug 6, 2010 7:36:07 PM (14 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:
- 028a0e8
- Parents:
- a93f525
- Location:
- sansview/perspectives/fitting
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fitting.py
r4f81342 rb35d3d1 257 257 loader = Loader() 258 258 loader.associate_file_reader(".fitv", self.state_reader) 259 loader.associate_file_reader(".svs", self.state_reader) 259 260 #Send the fitting panel to guiframe 260 261 self.mypanels.append(self.fit_panel) -
sansview/perspectives/fitting/pagestate.py
r3c44c66 rb35d3d1 603 603 604 604 ## Wildcards 605 type = ["Fitting files (*.fitv)|*.fitv"] 605 type = ["Fitting files (*.fitv)|*.fitv" 606 "SANSView file (*.svs)|*.svs"] 606 607 ## List of allowed extensions 607 ext=['.fitv', '.FITV' ]608 ext=['.fitv', '.FITV', '.svs', 'SVS'] 608 609 609 610 def __init__(self, call_back=None, cansas=True): … … 834 835 """ 835 836 # Create an empty state 836 state = PageState()837 state = None 837 838 # Locate the P(r) node 838 839 try: 839 840 nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME, namespaces={'ns': CANSAS_NS}) 840 state.fromXML(node=nodes[0]) 841 if nodes !=[]: 842 # Create an empty state 843 state = PageState() 844 state.fromXML(node=nodes[0]) 841 845 except: 842 846 logging.info("XML document does not contain fitting information.\n %s" % sys.exc_value) … … 1106 1110 root = tree.getroot() 1107 1111 entry_list = root.xpath('ns:SASentry', namespaces={'ns': CANSAS_NS}) 1108 for entry in entry_list: 1112 for entry in entry_list: 1109 1113 try: 1110 1114 sas_entry = self._parse_entry(entry) … … 1112 1116 raise 1113 1117 fitstate = self._parse_state(entry) 1114 sas_entry.meta_data['fitstate'] = fitstate 1115 sas_entry.filename = fitstate.file 1116 output.append(sas_entry) 1118 1119 #state could be None when .svs file is loaded 1120 #in this case, skip appending to output 1121 if fitstate != None: 1122 sas_entry.meta_data['fitstate'] = fitstate 1123 sas_entry.filename = fitstate.file 1124 output.append(sas_entry) 1117 1125 else: 1118 1126 raise RuntimeError, "%s is not a file" % path 1119 1127 1120 1128 # Return output consistent with the loader's api 1121 1129 if len(output)==0: 1122 1130 return None 1123 elif len(output)==1: 1124 # Call back to post the new state 1125 state = output[0].meta_data['fitstate'] 1126 t = time.localtime(state.timestamp) 1127 time_str = time.strftime("%b %d %H:%M", t) 1128 # Check that no time stamp is already appended 1129 max_char = state.file.find("[") 1130 if max_char < 0: 1131 max_char = len(state.file) 1132 state.file = state.file[0:max_char] +' [' + time_str + ']' 1133 1134 1135 if state is not None and state.is_data is not None: 1136 exec 'output[0].is_data = state.is_data' 1137 1138 output[0].filename = state.file 1139 state.data = output[0] 1140 state.data.name = output[0].filename #state.data_name 1141 state.data.id = state.data_id 1142 state.data.id = state.data_id 1143 if state.is_data is not None: 1144 state.data.is_data = state.is_data 1145 state.data.group_id = output[0].filename 1131 else: 1132 for ind in range(len(output)): 1133 # Call back to post the new state 1134 state = output[ind].meta_data['fitstate'] 1135 t = time.localtime(state.timestamp) 1136 time_str = time.strftime("%b %d %H:%M", t) 1137 # Check that no time stamp is already appended 1138 max_char = state.file.find("[") 1139 if max_char < 0: 1140 max_char = len(state.file) 1141 state.file = state.file[0:max_char] +' [' + time_str + ']' 1142 1143 1144 if state is not None and state.is_data is not None: 1145 exec 'output[%d].is_data = state.is_data'% ind 1146 1147 output[ind].filename = state.file 1148 state.data = output[ind] 1149 state.data.name = output[ind].filename #state.data_name 1150 state.data.id = state.data_id 1151 state.data.id = state.data_id 1152 if state.is_data is not None: 1153 state.data.is_data = state.is_data 1154 state.data.group_id = output[ind].filename 1155 1156 # make sure to put run name if none 1157 #if output[ind].run == None or output[ind].run ==[]: 1158 # exec 'output[%d].run = [output[%d].filename]'% (ind,ind) 1159 self.call_back(state=state, datainfo=output[ind]) 1160 return output[ind] 1146 1161 1147 self.call_back(state=state, datainfo=output[0])1148 return output[0]1149 else:1150 return output1151 1162 except: 1152 1163 raise … … 1154 1165 def write(self, filename, datainfo=None, fitstate=None): 1155 1166 """ 1156 Write the content of a Data1D as a CanSAS XML file 1167 Write the content of a Data1D as a CanSAS XML file only for standalone 1157 1168 1158 1169 :param filename: name of the file to write … … 1165 1176 1166 1177 # Add fitting information to the XML document 1167 if fitstate is not None: 1168 if fitstate.data is None: 1169 data = DataLoader.data_info.Data1D(x=[], y=[]) 1170 elif issubclass(fitstate.data.__class__, DataLoader.data_info.Data1D): 1171 data = fitstate.data 1172 doc, sasentry = self._to_xml_doc(data) 1173 else: 1174 data = fitstate.data 1175 doc, sasentry = self._data2d_to_xml_doc(data) 1176 fitstate.toXML(doc=doc, file=data.name, entry_node=sasentry) 1178 self.write_toXML(datainfo, fitstate) 1177 1179 # Write the XML document 1178 1180 fd = open(filename, 'w') … … 1182 1184 fitstate.toXML(file=filename) 1183 1185 1184 1186 def write_toXML(self, datainfo=None, state=None): 1187 """ 1188 Write toXML, a helper for write() , could be used by guimanager._on_save() 1189 1190 : return: xml doc 1191 """ 1192 1193 if state.data is None: 1194 data = DataLoader.data_info.Data1D(x=[], y=[]) 1195 else: 1196 #make sure title and data run is filled up. 1197 #if state.data.title == None or state.data.title=='': state.data.title = state.data.name 1198 #if state.data.run_name == None or state.data.run_name=={}: 1199 # state.data.run = [str(state.data.name)] 1200 # state.data.run_name[0] = state.data.name 1201 1202 if issubclass(state.data.__class__, DataLoader.data_info.Data1D): 1203 data = state.data 1204 doc, sasentry = self._to_xml_doc(data) 1205 else: 1206 data = state.data 1207 doc, sasentry = self._data2d_to_xml_doc(data) 1208 1209 1210 if state is not None: 1211 state.toXML(doc=doc, file=data.name, entry_node=sasentry) 1212 1213 return doc 1185 1214 1186 1215 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.