Changeset 5062bbf in sasview for sansview/perspectives/fitting/pagestate.py
- Timestamp:
- Jun 7, 2010 8:26:43 AM (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:
- b94945d
- Parents:
- 79ac6f8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/pagestate.py
r35b556d r5062bbf 1 """ 2 This software was developed by the University of Tennessee as part of the 3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 project funded by the US National Science Foundation. 5 6 See the license text in license.txt 7 8 copyright 2009, University of Tennessee 9 """ 1 2 3 ################################################################################ 4 #This software was developed by the University of Tennessee as part of the 5 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 6 #project funded by the US National Science Foundation. 7 # 8 #See the license text in license.txt 9 # 10 #copyright 2009, University of Tennessee 11 ################################################################################ 12 10 13 import time 11 14 import os … … 87 90 class PageState(object): 88 91 """ 89 92 Contains information to reconstruct a page of the fitpanel. 90 93 """ 91 94 def __init__(self, parent=None, model=None, data=None): 92 95 93 96 """ 94 Initialize the current state 95 @param model: a selected model within a page 96 @param data: 97 Initialize the current state 98 99 :param model: a selected model within a page 100 :param data: 101 97 102 """ 98 103 self.file = None … … 201 206 def clone(self): 202 207 """ 203 208 Create a new copy of the current object 204 209 """ 205 210 model = None … … 271 276 def _repr_helper(self, list, rep): 272 277 """ 273 278 Helper method to print a state 274 279 """ 275 280 for item in list: … … 288 293 def __repr__(self): 289 294 """ 290 295 output string for printing 291 296 """ 292 297 rep = "\nState name: %s\n"%self.file … … 321 326 def _toXML_helper(self, list, element, newdoc): 322 327 """ 323 328 Helper method to create xml file for saving state 324 329 """ 325 330 for item in list: … … 339 344 def toXML(self, file="fitting_state.fitv", doc=None, entry_node=None): 340 345 """ 341 Writes the state of the InversionControl panel to file, as XML. 342 343 Compatible with standalone writing, or appending to an 344 already existing XML document. In that case, the XML document 345 is required. An optional entry node in the XML document may also be given. 346 347 @param file: file to write to 348 @param doc: XML document object [optional] 349 @param entry_node: XML node within the XML document at which we will append the data [optional] 346 Writes the state of the InversionControl panel to file, as XML. 347 348 Compatible with standalone writing, or appending to an 349 already existing XML document. In that case, the XML document 350 is required. An optional entry node in the XML document may also be given. 351 352 :param file: file to write to 353 :param doc: XML document object [optional] 354 :param entry_node: XML node within the XML document at which we will append the data [optional] 355 350 356 """ 351 357 from xml.dom.minidom import getDOMImplementation … … 430 436 def _fromXML_helper(self, node, list): 431 437 """ 432 438 Helper function to write state to xml 433 439 """ 434 440 for item in node: … … 448 454 def fromXML(self, file=None, node=None): 449 455 """ 450 Load fitting state from a file 451 452 @param file: .fitv file 453 @param node: node of a XML document to read from 456 Load fitting state from a file 457 458 :param file: .fitv file 459 :param node: node of a XML document to read from 460 454 461 """ 455 462 … … 512 519 class Reader(CansasReader): 513 520 """ 514 521 Class to load a .fitv fitting file 515 522 """ 516 523 ## File type … … 524 531 def __init__(self, call_back=None, cansas=True): 525 532 """ 526 Initialize the call-back method to be called 527 after we load a file 528 @param call_back: call-back method 529 @param cansas: True = files will be written/read in CanSAS format 530 False = write CanSAS format 533 Initialize the call-back method to be called 534 after we load a file 535 536 :param call_back: call-back method 537 :param cansas: True = files will be written/read in CanSAS format 538 False = write CanSAS format 531 539 532 540 """ … … 538 546 def read(self, path): 539 547 """ 540 541 542 @param path: file path543 @return: None548 Load a new P(r) inversion state from file 549 550 :param path: file path 551 544 552 """ 545 553 if self.cansas == True: … … 548 556 def _data2d_to_xml_doc(self, datainfo): 549 557 """ 550 Create an XML document to contain the content of a Data2D 551 552 @param datainfo: Data2D object 558 Create an XML document to contain the content of a Data2D 559 560 :param datainfo: Data2D object 561 553 562 """ 554 563 if not issubclass(datainfo.__class__, Data2D): … … 722 731 for note in item.notes: 723 732 write_node(doc, node, "SASprocessnote", note) 724 725 733 # Return the document, and the SASentry node associated with 726 734 # the data we just wrote 727 735 return doc, entry_node 728 736 729 730 737 def _parse_state(self, entry): 731 738 """ 732 Read a fit result from an XML node 733 @param entry: XML node to read from 734 @return: PageState object 739 Read a fit result from an XML node 740 741 :param entry: XML node to read from 742 743 :return: PageState object 735 744 """ 736 745 # Create an empty state … … 747 756 def _parse_entry_2d(self, dom): 748 757 """ 749 Parse a SASentry 750 751 @param node: SASentry node 752 @return: Data2D object 753 """ 754 758 Parse a SASentry 759 760 :param node: SASentry node 761 762 :return: Data2D object 763 764 """ 755 765 data_info = Data2D() 756 766 … … 1083 1093 def _read_cansas(self, path): 1084 1094 """ 1085 Load data and P(r) information from a CanSAS XML file. 1086 1087 @param path: file path 1088 @return: Data1D object if a single SASentry was found, 1089 or a list of Data1D objects if multiple entries were found, 1090 or None of nothing was found 1091 @raise RuntimeError: when the file can't be opened 1092 @raise ValueError: when the length of the data vectors are inconsistent 1095 Load data and P(r) information from a CanSAS XML file. 1096 1097 :param path: file path 1098 1099 :return: Data1D object if a single SASentry was found, 1100 or a list of Data1D objects if multiple entries were found, 1101 or None of nothing was found 1102 1103 :raise RuntimeError: when the file can't be opened 1104 :raise ValueError: when the length of the data vectors are inconsistent 1105 1093 1106 """ 1094 1107 output = [] … … 1155 1168 def write(self, filename, datainfo=None, fitstate=None): 1156 1169 """ 1157 Write the content of a Data1D as a CanSAS XML file 1158 1159 @param filename: name of the file to write 1160 @param datainfo: Data1D object 1161 @param fitstate: PageState object 1170 Write the content of a Data1D as a CanSAS XML file 1171 1172 :param filename: name of the file to write 1173 :param datainfo: Data1D object 1174 :param fitstate: PageState object 1175 1162 1176 """ 1163 1177 # Sanity check … … 1182 1196 fitstate.toXML(file=filename) 1183 1197 1184 1185 if __name__ == "__main__": 1186 state = PageState(parent=None) 1187 state.toXML() 1188 print "state", state 1198 """ 1199 Example: :: 1200 1201 if __name__ == "__main__": 1202 state = PageState(parent=None) 1203 state.toXML() 1204 print "state", state 1205 1206 """
Note: See TracChangeset
for help on using the changeset viewer.