Changeset ff3f5821 in sasview for src/sas/sasgui/perspectives/fitting/pagestate.py
- Timestamp:
- Oct 7, 2016 12:31:19 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:
- e6de6b8
- Parents:
- 998ca90 (diff), dd72190 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/pagestate.py
r6c382da r998ca90 2 2 Class that holds a fit page state 3 3 """ 4 # TODO: Refactor code so we don't need to use getattr/setattr4 # TODO: Refactor code so we don't need to use getattr/setattr 5 5 ################################################################################ 6 # This software was developed by the University of Tennessee as part of the7 # Distributed Data Analysis of Neutron Scattering Experiments (DANSE)8 # project funded by the US National Science Foundation.6 # This software was developed by the University of Tennessee as part of the 7 # Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 8 # project funded by the US National Science Foundation. 9 9 # 10 # See the license text in license.txt10 # See the license text in license.txt 11 11 # 12 # copyright 2009, University of Tennessee12 # copyright 2009, University of Tennessee 13 13 ################################################################################ 14 14 import time … … 30 30 from sas.sascalc.dataloader.readers.cansas_reader import Reader as CansasReader 31 31 from sas.sascalc.dataloader.readers.cansas_reader import get_content, write_node 32 from sas.sascalc.dataloader.data_info import Data2D 33 from sas.sascalc.dataloader.data_info import Collimation 34 from sas.sascalc.dataloader.data_info import Detector 35 from sas.sascalc.dataloader.data_info import Process 36 from sas.sascalc.dataloader.data_info import Aperture 37 #Information to read/write state as xml 32 from sas.sascalc.dataloader.data_info import Data2D, Collimation, Detector 33 from sas.sascalc.dataloader.data_info import Process, Aperture 34 # Information to read/write state as xml 38 35 FITTING_NODE_NAME = 'fitting_plug_in' 39 36 CANSAS_NS = "cansas1d/1.0" … … 123 120 try: 124 121 return node.get(item[0]).strip() == "True" 125 126 122 except: 127 123 return None … … 146 142 """ 147 143 self.file = None 148 # Time of state creation144 # Time of state creation 149 145 self.timestamp = time.time() 150 # #Data member to store the dispersion object created146 # Data member to store the dispersion object created 151 147 self._disp_obj_dict = {} 152 # ------------------------153 # Data used for fitting148 # ------------------------ 149 # Data used for fitting 154 150 self.data = data 155 151 # model data 156 152 self.theory_data = None 157 # Is 2D153 # Is 2D 158 154 self.is_2D = False 159 155 self.images = None 160 156 161 #save additional information on data that dataloader.reader does not read 157 # save additional information on data that dataloader.reader 158 # does not read 162 159 self.is_data = None 163 160 self.data_name = "" … … 172 169 self.data_group_id = self.data.group_id 173 170 174 # # reset True change the state of exsiting button171 # reset True change the state of existing button 175 172 self.reset = False 176 173 … … 180 177 self.model = model 181 178 self.m_name = None 182 # list of process done to model179 # list of process done to model 183 180 self.process = [] 184 # fit page manager181 # fit page manager 185 182 self.manager = None 186 # Store the parent of this panel parent183 # Store the parent of this panel parent 187 184 # For this application fitpanel is the parent 188 185 self.parent = parent 189 186 # Event_owner is the owner of model event 190 187 self.event_owner = None 191 # #page name188 # page name 192 189 self.page_name = "" 193 190 # Contains link between model, all its parameters, and panel organization … … 196 193 self.str_parameters = [] 197 194 # Contains list of parameters that cannot be fitted and reference to 198 # panel objects195 # panel objects 199 196 self.fixed_param = [] 200 197 # Contains list of parameters with dispersity and reference to 201 # panel objects198 # panel objects 202 199 self.fittable_param = [] 203 # #orientation parameters200 # orientation parameters 204 201 self.orientation_params = [] 205 # #orientation parameters for gaussian dispersity202 # orientation parameters for gaussian dispersity 206 203 self.orientation_params_disp = [] 207 # #smearer info204 # smearer info 208 205 self.smearer = None 209 206 self.smear_type = None … … 214 211 self.dxl = None 215 212 self.dxw = None 216 # list of dispersion parameters213 # list of dispersion parameters 217 214 self.disp_list = [] 218 215 if self.model is not None: … … 223 220 self.weights = {} 224 221 225 # contains link between a model and selected parameters to fit222 # contains link between a model and selected parameters to fit 226 223 self.param_toFit = [] 227 # #dictionary of model type and model class224 # dictionary of model type and model class 228 225 self.model_list_box = None 229 # #save the state of the context menu226 # save the state of the context menu 230 227 self.saved_states = {} 231 # #save selection of combobox228 # save selection of combobox 232 229 self.formfactorcombobox = None 233 230 self.categorycombobox = None 234 231 self.structurecombobox = None 235 232 236 # #radio box to select type of model237 # self.shape_rbutton = False238 # self.shape_indep_rbutton = False239 # self.struct_rbutton = False240 # self.plugin_rbutton = False241 # #the indice of the current selection233 # radio box to select type of model 234 # self.shape_rbutton = False 235 # self.shape_indep_rbutton = False 236 # self.struct_rbutton = False 237 # self.plugin_rbutton = False 238 # the indice of the current selection 242 239 self.disp_box = 0 243 # #Qrange244 # #Q range240 # Qrange 241 # Q range 245 242 self.qmin = 0.001 246 243 self.qmax = 0.1 247 # reset data range244 # reset data range 248 245 self.qmax_x = None 249 246 self.qmin_x = None … … 253 250 self.multi_factor = None 254 251 self.magnetic_on = False 255 # #enable smearering state252 # enable smearering state 256 253 self.enable_smearer = False 257 254 self.disable_smearer = True … … 263 260 self.dI_sqrdata = False 264 261 self.dI_idata = False 265 # #disperity selection262 # disperity selection 266 263 self.enable_disp = False 267 264 self.disable_disp = True 268 265 269 # #state of selected all check button266 # state of selected all check button 270 267 self.cb1 = False 271 # #store value of chisqr268 # store value of chisqr 272 269 self.tcChi = None 273 270 … … 293 290 obj.structurecombobox = self.structurecombobox 294 291 295 # obj.shape_rbutton = self.shape_rbutton296 # obj.shape_indep_rbutton = self.shape_indep_rbutton297 # obj.struct_rbutton = self.struct_rbutton298 # obj.plugin_rbutton = self.plugin_rbutton292 # obj.shape_rbutton = self.shape_rbutton 293 # obj.shape_indep_rbutton = self.shape_indep_rbutton 294 # obj.struct_rbutton = self.struct_rbutton 295 # obj.plugin_rbutton = self.plugin_rbutton 299 296 300 297 obj.manager = self.manager … … 381 378 382 379 rep += "State created: %s\n" % time_str 383 rep += "State form factor combobox selection: %s\n" % self.formfactorcombobox 384 rep += "State structure factor combobox selection: %s\n" % self.structurecombobox 380 rep += "State form factor combobox selection: %s\n" % \ 381 self.formfactorcombobox 382 rep += "State structure factor combobox selection: %s\n" % \ 383 self.structurecombobox 385 384 rep += "is data : %s\n" % self.is_data 386 385 rep += "data's name : %s\n" % self.data_name 387 386 rep += "data's id : %s\n" % self.data_id 388 if self.model !=None:387 if self.model is not None: 389 388 m_name = self.model.__class__.__name__ 390 389 if m_name == 'Model': … … 397 396 rep += "model type (Category) selected: %s\n" % self.categorycombobox 398 397 rep += "data : %s\n" % str(self.data) 399 rep += "Plotting Range: min: %s, max: %s, steps: %s\n" % (str(self.qmin),400 398 rep += "Plotting Range: min: %s, max: %s, steps: %s\n" % \ 399 (str(self.qmin),str(self.qmax), str(self.npts)) 401 400 rep += "Dispersion selection : %s\n" % str(self.disp_box) 402 401 rep += "Smearing enable : %s\n" % str(self.enable_smearer) … … 414 413 415 414 rep += "2D enable : %s\n" % str(self.enable2D) 416 rep += "All parameters checkbox selected: %s\n" % (self.cb1)415 rep += "All parameters checkbox selected: %s\n" % str(self.cb1) 417 416 rep += "Value of Chisqr : %s\n" % str(self.tcChi) 418 417 rep += "Smear object : %s\n" % str(self.smearer) 419 rep += "Smear type : %s\n" % (self.smear_type)418 rep += "Smear type : %s\n" % str(self.smear_type) 420 419 rep += "dq_l : %s\n" % self.dq_l 421 420 rep += "dq_r : %s\n" % self.dq_r … … 434 433 if not self.is_2D: 435 434 for item in self.parameters: 436 if not itemin self.orientation_params:435 if item not in self.orientation_params: 437 436 temp_parameters.append(item) 438 437 for item in self.fittable_param: 439 if not itemin self.orientation_params_disp:438 if item not in self.orientation_params_disp: 440 439 temp_fittable_param.append(item) 441 440 else: … … 443 442 temp_fittable_param = self.fittable_param 444 443 445 rep += "number parameters(self.parameters): %s\n" % len(temp_parameters) 444 rep += "number parameters(self.parameters): %s\n" % \ 445 len(temp_parameters) 446 446 rep = self._repr_helper(list=temp_parameters, rep=rep) 447 rep += "number str_parameters(self.str_parameters): %s\n" % len(self.str_parameters) 447 rep += "number str_parameters(self.str_parameters): %s\n" % \ 448 len(self.str_parameters) 448 449 rep = self._repr_helper(list=self.str_parameters, rep=rep) 449 rep += "number fittable_param(self.fittable_param): %s\n" % len(temp_fittable_param) 450 rep += "number fittable_param(self.fittable_param): %s\n" % \ 451 len(temp_fittable_param) 450 452 rep = self._repr_helper(list=temp_fittable_param, rep=rep) 451 453 return rep … … 551 553 paramval_string += CENTRE % param + "\n" 552 554 553 text_string = "\n\n\n%s\n\n%s\n%s\n%s\n\n%s" % (title, file, q_name, chi2, paramval) 555 text_string = "\n\n\n%s\n\n%s\n%s\n%s\n\n%s" % \ 556 (title, file, q_name, chi2, paramval) 554 557 555 558 title_name = self._check_html_format(title_name) … … 632 635 element.appendChild(sub_element) 633 636 634 def toXML(self, file="fitting_state.fitv", doc=None, entry_node=None): 635 """ 636 Writes the state of the InversionControl panel to file, as XML. 637 def toXML(self, file="fitting_state.fitv", doc=None, 638 entry_node=None, batch_fit_state=None): 639 """ 640 Writes the state of the fit panel to file, as XML. 637 641 638 642 Compatible with standalone writing, or appending to an 639 already existing XML document. In that case, the XML document 640 isrequired. An optional entry node in the XML document may also be given.643 already existing XML document. In that case, the XML document is 644 required. An optional entry node in the XML document may also be given. 641 645 642 646 :param file: file to write to 643 647 :param doc: XML document object [optional] 644 :param entry_node: XML node within the XML document at which we will append the data [optional]645 648 :param entry_node: XML node within the XML document at which we 649 will append the data [optional] 646 650 """ 647 651 from xml.dom.minidom import getDOMImplementation … … 691 695 element.setAttributeNode(attr) 692 696 top_element.appendChild(element) 697 693 698 # Inputs 694 699 inputs = newdoc.createElement("Attributes") … … 741 746 for item in LIST_OF_STATE_PARAMETERS: 742 747 element = newdoc.createElement(item[0]) 743 self._toXML_helper(thelist=getattr(self, item[1]), element=element, newdoc=newdoc) 748 self._toXML_helper(thelist=getattr(self, item[1]), 749 element=element, newdoc=newdoc) 744 750 inputs.appendChild(element) 751 752 # Combined and Simultaneous Fit Parameters 753 if batch_fit_state is not None: 754 batch_combo = newdoc.createElement('simultaneous_fit') 755 top_element.appendChild(batch_combo) 756 757 # Simultaneous Fit Number For Linking Later 758 element = newdoc.createElement('sim_fit_number') 759 element.setAttribute('fit_number', str(batch_fit_state.fit_page_no)) 760 batch_combo.appendChild(element) 761 762 # Save constraints 763 constraints = newdoc.createElement('constraints') 764 batch_combo.appendChild(constraints) 765 for constraint in batch_fit_state.constraints_list: 766 if constraint.model_cbox.GetValue() != "": 767 # model_cbox, param_cbox, egal_txt, constraint, btRemove, sizer 768 doc_cons = newdoc.createElement('constraint') 769 doc_cons.setAttribute('model_cbox', 770 str(constraint.model_cbox.GetValue())) 771 doc_cons.setAttribute('param_cbox', 772 str(constraint.param_cbox.GetValue())) 773 doc_cons.setAttribute('egal_txt', 774 str(constraint.egal_txt.GetLabel())) 775 doc_cons.setAttribute('constraint', 776 str(constraint.constraint.GetValue())) 777 constraints.appendChild(doc_cons) 778 779 # Save all models 780 models = newdoc.createElement('model_list') 781 batch_combo.appendChild(models) 782 for model in batch_fit_state.model_list: 783 doc_model = newdoc.createElement('model_list_item') 784 doc_model.setAttribute('checked', str(model[0].GetValue())) 785 keys = model[1].keys() 786 doc_model.setAttribute('name', str(keys[0])) 787 values = model[1].get(keys[0]) 788 doc_model.setAttribute('fit_number', str(model[2])) 789 doc_model.setAttribute('fit_page_source', str(model[3])) 790 doc_model.setAttribute('model_name', str(values.model.id)) 791 models.appendChild(doc_model) 792 793 # Select All Checkbox 794 element = newdoc.createElement('select_all') 795 if batch_fit_state.select_all: 796 element.setAttribute('checked', 'True') 797 else: 798 element.setAttribute('checked', 'False') 799 batch_combo.appendChild(element) 745 800 746 801 # Save the file … … 809 864 :param file: .fitv file 810 865 :param node: node of a XML document to read from 811 812 866 """ 813 867 if file is not None: … … 816 870 raise RuntimeError, msg 817 871 818 if node.get('version') and node.get('version') == '1.0':872 if node.get('version') and node.get('version') == '1.0': 819 873 820 874 # Get file name … … 862 916 value = cls.type 863 917 except Exception: 864 logging.error("unable to load distribution %r for %s"865 918 base = "unable to load distribution %r for %s" 919 logging.error(base % (value, parameter)) 866 920 continue 867 921 _disp_obj_dict = getattr(self, varname) … … 960 1014 self.cansas = cansas 961 1015 self.state = None 1016 # batch fitting params for saving 1017 self.batchfit_params = [] 962 1018 963 1019 def get_state(self): … … 984 1040 raise RuntimeError, "The cansas writer expects a Data2D instance" 985 1041 1042 title = "cansas1d/%s" % self.version 1043 title += "http://svn.smallangles.net/svn/canSAS/1dwg/trunk/cansas1d.xsd" 986 1044 doc = xml.dom.minidom.Document() 987 1045 main_node = doc.createElement("SASroot") 988 1046 main_node.setAttribute("version", self.version) 989 1047 main_node.setAttribute("xmlns", "cansas1d/%s" % self.version) 990 main_node.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")991 main_node.setAttribute("xsi:schemaLocation",992 "cansas1d/%s http://svn.smallangles.net/svn/canSAS/1dwg/trunk/cansas1d.xsd" % self.version)1048 main_node.setAttribute("xmlns:xsi", 1049 "http://www.w3.org/2001/XMLSchema-instance") 1050 main_node.setAttribute("xsi:schemaLocation", title) 993 1051 994 1052 doc.appendChild(main_node) … … 999 1057 write_node(doc, entry_node, "Title", datainfo.title) 1000 1058 if datainfo is not None: 1001 write_node(doc, entry_node, "data_class", datainfo.__class__.__name__) 1059 write_node(doc, entry_node, "data_class", 1060 datainfo.__class__.__name__) 1002 1061 for item in datainfo.run: 1003 1062 runname = {} 1004 if datainfo.run_name.has_key(item) and len(str(datainfo.run_name[item])) > 1: 1063 if datainfo.run_name.has_key(item) and \ 1064 len(str(datainfo.run_name[item])) > 1: 1005 1065 runname = {'name': datainfo.run_name[item]} 1006 1066 write_node(doc, entry_node, "Run", item, runname) … … 1219 1279 1220 1280 :param entry: XML node to read from 1221 1222 1281 :return: PageState object 1223 1282 """ … … 1228 1287 nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME, 1229 1288 namespaces={'ns': CANSAS_NS}) 1230 if nodes != []:1289 if nodes: 1231 1290 # Create an empty state 1232 1291 state = PageState() … … 1238 1297 1239 1298 return state 1299 1300 def _parse_simfit_state(self, entry): 1301 """ 1302 Parses the saved data for a simultaneous fit 1303 :param entry: XML object to read from 1304 :return: XML object for a simultaneous fit or None 1305 """ 1306 nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME, 1307 namespaces={'ns': CANSAS_NS}) 1308 if nodes: 1309 simfitstate = nodes[0].xpath('ns:simultaneous_fit', 1310 namespaces={'ns': CANSAS_NS}) 1311 if simfitstate: 1312 from simfitpage import SimFitPageState 1313 sim_fit_state = SimFitPageState() 1314 simfitstate_0 = simfitstate[0] 1315 all = simfitstate_0.xpath('ns:select_all', 1316 namespaces={'ns': CANSAS_NS}) 1317 atts = all[0].attrib 1318 checked = atts.get('checked') 1319 sim_fit_state.select_all = bool(checked) 1320 model_list = simfitstate_0.xpath('ns:model_list', 1321 namespaces={'ns': CANSAS_NS}) 1322 model_list_items = model_list[0].xpath('ns:model_list_item', 1323 namespaces={'ns': CANSAS_NS}) 1324 for model in model_list_items: 1325 attrs = model.attrib 1326 sim_fit_state.model_list.append(attrs) 1327 1328 constraints = simfitstate_0.xpath('ns:constraints', 1329 namespaces={'ns': CANSAS_NS}) 1330 constraint_list = constraints[0].xpath('ns:constraint', 1331 namespaces={'ns': CANSAS_NS}) 1332 for constraint in constraint_list: 1333 attrs = constraint.attrib 1334 sim_fit_state.constraints_list.append(attrs) 1335 1336 return sim_fit_state 1337 else: 1338 return None 1240 1339 1241 1340 def _parse_save_state_entry(self, dom): … … 1298 1397 data_info.notes.append(note_value) 1299 1398 except Exception: 1300 err_mess = "cansas_reader.read: error processing entry notes\n %s" % sys.exc_value 1399 err_mess = "cansas_reader.read: error processing entry notes\n" 1400 err_mess += " %s" % sys.exc_value 1301 1401 self.errors.append(err_mess) 1302 1402 logging.error(err_mess) … … 1308 1408 1309 1409 self._store_content('ns:SASsample/ns:ID', dom, 'ID', data_info.sample) 1310 self._store_float('ns:SASsample/ns:thickness', dom, 'thickness', data_info.sample) 1311 self._store_float('ns:SASsample/ns:transmission', dom, 'transmission', data_info.sample) 1312 self._store_float('ns:SASsample/ns:temperature', dom, 'temperature', data_info.sample) 1313 1314 nodes = dom.xpath('ns:SASsample/ns:details', namespaces={'ns': CANSAS_NS}) 1410 self._store_float('ns:SASsample/ns:thickness', dom, 'thickness', 1411 data_info.sample) 1412 self._store_float('ns:SASsample/ns:transmission', dom, 'transmission', 1413 data_info.sample) 1414 self._store_float('ns:SASsample/ns:temperature', dom, 'temperature', 1415 data_info.sample) 1416 1417 nodes = dom.xpath('ns:SASsample/ns:details', 1418 namespaces={'ns': CANSAS_NS}) 1315 1419 for item in nodes: 1316 1420 try: … … 1320 1424 data_info.sample.details.append(detail_value) 1321 1425 except Exception: 1322 err_mess = "cansas_reader.read: error processing sample details\n %s" % sys.exc_value 1426 err_mess = "cansas_reader.read: error processing entry notes\n" 1427 err_mess += " %s" % sys.exc_value 1323 1428 self.errors.append(err_mess) 1324 1429 logging.error(err_mess) 1325 1430 1326 1431 # Position (as a vector) 1327 self._store_float('ns:SASsample/ns:position/ns:x', dom, 'position.x', data_info.sample) 1328 self._store_float('ns:SASsample/ns:position/ns:y', dom, 'position.y', data_info.sample) 1329 self._store_float('ns:SASsample/ns:position/ns:z', dom, 'position.z', data_info.sample) 1432 self._store_float('ns:SASsample/ns:position/ns:x', dom, 'position.x', 1433 data_info.sample) 1434 self._store_float('ns:SASsample/ns:position/ns:y', dom, 'position.y', 1435 data_info.sample) 1436 self._store_float('ns:SASsample/ns:position/ns:z', dom, 'position.z', 1437 data_info.sample) 1330 1438 1331 1439 # Orientation (as a vector) … … 1461 1569 process.term.append(term_attr) 1462 1570 except: 1463 err_mess = "cansas_reader.read: error processing process term\n %s" % sys.exc_value 1571 err_mess = "cansas_reader.read: error processing " 1572 err_mess += "entry notes\n %s" % sys.exc_value 1464 1573 self.errors.append(err_mess) 1465 1574 logging.error(err_mess) … … 1476 1585 nodes = dom.xpath('ns:SASdata', namespaces={'ns': CANSAS_NS}) 1477 1586 if len(nodes) > 1: 1478 raise RuntimeError, "CanSAS reader is not compatible with multiple SASdata entries" 1587 raise RuntimeError, "CanSAS reader is not compatible with" + \ 1588 " multiple SASdata entries" 1479 1589 1480 1590 for entry in nodes: … … 1488 1598 value_list = [] 1489 1599 if field is not None: 1490 value_list = [parse_entry_helper(node, item) for node in field] 1600 value_list = \ 1601 [parse_entry_helper(node, item) for node in field] 1491 1602 if len(value_list) < 2: 1492 1603 setattr(data_info, item[0], None) … … 1498 1609 def _read_cansas(self, path): 1499 1610 """ 1500 Load data and P(r)information from a CanSAS XML file.1611 Load data and fitting information from a CanSAS XML file. 1501 1612 1502 1613 :param path: file path 1503 1504 1614 :return: Data1D object if a single SASentry was found, 1505 1615 or a list of Data1D objects if multiple entries were found, 1506 1616 or None of nothing was found 1507 1508 1617 :raise RuntimeError: when the file can't be opened 1509 1618 :raise ValueError: when the length of the data vectors are inconsistent 1510 1511 1619 """ 1512 1620 output = [] 1621 simfitstate = None 1513 1622 basename = os.path.basename(path) 1514 1623 root, extension = os.path.splitext(basename) … … 1516 1625 try: 1517 1626 if os.path.isfile(path): 1518 1519 #TODO: eventually remove the check for .xml once 1520 # the P(r) writer/reader is truly complete. 1521 if ext in self.ext or \ 1522 ext == '.xml': 1523 1627 if ext in self.ext or ext == '.xml': 1524 1628 tree = etree.parse(path, parser=etree.ETCompatXMLParser()) 1525 1629 # Check the format version number 1526 # Specifying the namespace will take care of the file format version 1630 # Specifying the namespace will take care of the file 1631 # format version 1527 1632 root = tree.getroot() 1528 1633 entry_list = root.xpath('ns:SASentry', 1529 1634 namespaces={'ns': CANSAS_NS}) 1635 name_map = {} 1530 1636 for entry in entry_list: 1531 1637 try: … … 1534 1640 raise 1535 1641 fitstate = self._parse_state(entry) 1536 1537 #state could be None when .svs file is loaded 1538 #in this case, skip appending to output 1539 if fitstate != None: 1642 simfitstate = self._parse_simfit_state(entry) 1643 1644 # state could be None when .svs file is loaded 1645 # in this case, skip appending to output 1646 if fitstate is not None: 1540 1647 sas_entry.meta_data['fitstate'] = fitstate 1541 1648 sas_entry.filename = fitstate.file 1542 1649 output.append(sas_entry) 1650 1543 1651 else: 1544 1652 self.call_back(format=ext) … … 1580 1688 name = original_fname 1581 1689 state.data.group_id = name 1582 # store state in fitting1690 # store state in fitting 1583 1691 self.call_back(state=state, 1584 1692 datainfo=output[ind], format=ext) 1585 1693 self.state = state 1694 if simfitstate is not None: 1695 self.call_back(state=simfitstate) 1696 1586 1697 return output 1587 1698 except: … … 1599 1710 """ 1600 1711 # Sanity check 1601 if self.cansas == True:1712 if self.cansas: 1602 1713 # Add fitting information to the XML document 1603 1714 doc = self.write_toXML(datainfo, fitstate) … … 1611 1722 fd.close() 1612 1723 1613 def write_toXML(self, datainfo=None, state=None ):1724 def write_toXML(self, datainfo=None, state=None, batchfit=None): 1614 1725 """ 1615 1726 Write toXML, a helper for write(), … … 1619 1730 """ 1620 1731 1621 if state.data is None:1622 data = sas.sascalc.dataloader.data_info.Data1D(x=[], y=[])1732 self.batchfit_params = batchfit 1733 if state.data is None or not state.data.is_data: 1623 1734 return None 1624 elif not state.data.is_data: 1625 return None 1735 # make sure title and data run are filled. 1736 if state.data.title is None or state.data.title == '': 1737 state.data.title = state.data.name 1738 if state.data.run_name is None or state.data.run_name == {}: 1739 state.data.run = [str(state.data.name)] 1740 state.data.run_name[0] = state.data.name 1741 1742 if issubclass(state.data.__class__, 1743 sas.sascalc.dataloader.data_info.Data1D): 1744 data = state.data 1745 doc, sasentry = self._to_xml_doc(data) 1626 1746 else: 1627 #make sure title and data run is filled up. 1628 if state.data.title == None or state.data.title == '': 1629 state.data.title = state.data.name 1630 if state.data.run_name == None or state.data.run_name == {}: 1631 state.data.run = [str(state.data.name)] 1632 state.data.run_name[0] = state.data.name 1633 1634 if issubclass(state.data.__class__, 1635 sas.sascalc.dataloader.data_info.Data1D): 1636 data = state.data 1637 doc, sasentry = self._to_xml_doc(data) 1638 else: 1639 data = state.data 1640 doc, sasentry = self._data2d_to_xml_doc(data) 1747 data = state.data 1748 doc, sasentry = self._data2d_to_xml_doc(data) 1641 1749 1642 1750 if state is not None: 1643 doc = state.toXML(doc=doc, file=data.filename, entry_node=sasentry) 1751 doc = state.toXML(doc=doc, file=data.filename, entry_node=sasentry, 1752 batch_fit_state=self.batchfit_params) 1644 1753 1645 1754 return doc 1646 1647 # Simple html report templet1648 HEADER = "<html>\n"1649 HEADER += "<head>\n"1650 HEADER += "<meta http-equiv=Content-Type content='text/html; "1651 HEADER += "charset=windows-1252'> \n"1652 HEADER += "<meta name=Generator >\n"1653 HEADER += "</head>\n"1654 HEADER += "<body lang=EN-US>\n"1655 HEADER += "<div class=WordSection1>\n"1656 HEADER += "<p class=MsoNormal><b><span ><center><font size='4' >"1657 HEADER += "%s</font></center></span></center></b></p>"1658 HEADER += "<p class=MsoNormal> </p>"1659 PARA = "<p class=MsoNormal><font size='4' > %s \n"1660 PARA += "</font></p>"1661 CENTRE = "<p class=MsoNormal><center><font size='4' > %s \n"1662 CENTRE += "</font></center></p>"1663 FEET_1 = \1664 """1665 <p class=MsoNormal> </p>1666 <br>1667 <p class=MsoNormal><b><span ><center> <font size='4' > Graph1668 </font></span></center></b></p>1669 <p class=MsoNormal> </p>1670 <center>1671 <br><font size='4' >Model Computation</font>1672 <br><font size='4' >Data: "%s"</font><br>1673 """1674 FEET_2 = \1675 """1676 <img src="%s" >1677 </img>1678 """1679 FEET_3 = \1680 """1681 </center>1682 </div>1683 </body>1684 </html>1685 """1686 ELINE = "<p class=MsoNormal> </p>"1687 1688 if __name__ == "__main__":1689 state = PageState(parent=None)1690 #state.toXML()1691 """1692 1693 file = open("test_state", "w")1694 pickle.dump(state, file)1695 print pickle.dumps(state)1696 state.data_name = "hello---->"1697 pickle.dump(state, file)1698 file = open("test_state", "r")1699 new_state= pickle.load(file)1700 print "new state", new_state1701 new_state= pickle.load(file)1702 print "new state", new_state1703 #print "state", state1704 """1705 import bsddb1706 import pickle1707 db = bsddb.btopen('file_state.db', 'c')1708 val = (pickle.dumps(state), "hello", "hi")1709 db['state1'] = pickle.dumps(val)1710 print pickle.loads(db['state1'])1711 state.data_name = "hello---->22"1712 db['state2'] = pickle.dumps(state)1713 state.data_name = "hello---->2"1714 db['state3'] = pickle.dumps(state)1715 del db['state3']1716 state.data_name = "hello---->3"1717 db['state4'] = pickle.dumps(state)1718 new_state = pickle.loads(db['state1'])1719 #print db.last()1720 db.set_location('state2')1721 state.data_name = "hello---->5"1722 db['aastate5'] = pickle.dumps(state)1723 db.keys().sort()1724 print pickle.loads(db['state2'])1725 1726 db.close()
Note: See TracChangeset
for help on using the changeset viewer.