Changeset ac5b69d in sasview for src/sans/perspectives
- Timestamp:
- May 5, 2014 1:41:43 PM (11 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:
- c81aa18
- Parents:
- 0089be3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sans/perspectives/fitting/pagestate.py
reddb6ec rac5b69d 20 20 21 21 import xml.dom.minidom 22 from xml.dom.minidom import parseString 22 23 from lxml import etree 23 24 … … 672 673 # We are appending to an existing document 673 674 newdoc = doc 674 top_element = newdoc.createElement(FITTING_NODE_NAME) 675 try: 676 top_element = newdoc.createElement(FITTING_NODE_NAME) 677 except: 678 string = etree.tostring(doc, pretty_print=True) 679 newdoc = parseString(string) 680 top_element = newdoc.createElement(FITTING_NODE_NAME) 675 681 if entry_node is None: 676 682 newdoc.documentElement.appendChild(top_element) 677 683 else: 678 entry_node.appendChild(top_element) 679 684 try: 685 entry_node.appendChild(top_element) 686 except: 687 node_name = entry_node.tag 688 node_list = newdoc.getElementsByTagName(node_name) 689 entry_node = node_list.item(0) 690 entry_node.appendChild(top_element) 691 680 692 attr = newdoc.createAttribute("version") 681 693 attr.nodeValue = '1.0' … … 750 762 for item in list_of_state_parameters: 751 763 element = newdoc.createElement(item[0]) 752 com = "self._toXML_helper( list=self.%s,"764 com = "self._toXML_helper(thelist=self.%s," 753 765 com += " element=element, newdoc=newdoc)" 754 766 exec com % item[1] … … 762 774 return None 763 775 else: 764 return newdoc .toprettyxml()776 return newdoc 765 777 766 778 def _fromXML_helper(self, node, list): … … 1252 1264 state = PageState() 1253 1265 state.fromXML(node=nodes[0]) 1266 1254 1267 except: 1255 1268 logging.info("XML document does not contain fitting information.\n %s" % sys.exc_value) … … 1257 1270 return state 1258 1271 1259 def _parse_ entry(self, dom):1272 def _parse_save_state_entry(self, dom): 1260 1273 """ 1261 1274 Parse a SASentry … … 1268 1281 node = dom.xpath('ns:data_class', namespaces={'ns': CANSAS_NS}) 1269 1282 if not node or node[0].text.lstrip().rstrip() != "Data2D": 1270 return CansasReader._parse_entry(self, dom) 1283 return_value, _ = self._parse_entry(dom) 1284 numpy.trim_zeros(return_value.x) 1285 numpy.trim_zeros(return_value.y) 1286 numpy.trim_zeros(return_value.dy) 1287 size_dx = return_value.dx.size 1288 size_dxl = return_value.dxl.size 1289 size_dxw = return_value.dxw.size 1290 if size_dxl == 0 and size_dxw == 0: 1291 return_value.dxl = None 1292 return_value.dxw = None 1293 numpy.trim_zeros(return_value.dx) 1294 elif size_dx == 0: 1295 return_value.dx = None 1296 size_dx = size_dxl 1297 numpy.trim_zeros(return_value.dxl) 1298 numpy.trim_zeros(return_value.dxw) 1299 1300 return return_value, _ 1271 1301 1272 1302 #Parse 2D … … 1539 1569 for entry in entry_list: 1540 1570 try: 1541 sas_entry = self._parse_entry(entry)1571 sas_entry, _ = self._parse_save_state_entry(entry) 1542 1572 except: 1543 1573 raise … … 1608 1638 # Sanity check 1609 1639 if self.cansas == True: 1610 1611 1640 # Add fitting information to the XML document 1612 1641 doc = self.write_toXML(datainfo, fitstate) 1613 1642 # Write the XML document 1614 fd = open(filename, 'w')1615 fd.write(doc.toprettyxml())1616 fd.close()1617 1643 else: 1618 fitstate.toXML(file=filename) 1644 doc = fitstate.toXML(file=filename) 1645 1646 # Save the document no matter the type 1647 fd = open(filename, 'w') 1648 fd.write(doc.toprettyxml()) 1649 fd.close() 1619 1650 1620 1651 def write_toXML(self, datainfo=None, state=None): … … 1638 1669 state.data.run = [str(state.data.name)] 1639 1670 state.data.run_name[0] = state.data.name 1640 1671 1641 1672 if issubclass(state.data.__class__, 1642 1673 sans.dataloader.data_info.Data1D): … … 1648 1679 1649 1680 if state is not None: 1650 state.toXML(doc=doc, file=data.filename, entry_node=sasentry)1651 1681 doc = state.toXML(doc=doc, file=data.filename, entry_node=sasentry) 1682 1652 1683 return doc 1653 1684
Note: See TracChangeset
for help on using the changeset viewer.