Changeset eb8da5f in sasview for src/sas/sasgui/perspectives/file_converter/cansas_writer.py
- Timestamp:
- Jul 21, 2016 10:47:25 AM (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:
- 94f4518
- Parents:
- 8976865
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/file_converter/cansas_writer.py
r8976865 reb8da5f 6 6 class CansasWriter(CansasReader): 7 7 8 def write(self, filename, datainfo, sasentry_attrs=None):8 def write(self, filename, frame_data, sasentry_attrs=None): 9 9 """ 10 10 Write the content of a Data1D as a CanSAS XML file … … 14 14 """ 15 15 # Create XML document 16 doc, _ = self._to_xml_doc( datainfo, sasentry_attrs)16 doc, _ = self._to_xml_doc(frame_data, sasentry_attrs) 17 17 # Write the file 18 18 file_ref = open(filename, 'w') … … 24 24 25 25 26 def _to_xml_doc(self, datainfo, sasentry_attrs=None):26 def _to_xml_doc(self, frame_data, sasentry_attrs=None): 27 27 """ 28 Create an XML document to contain the content of a Data1D28 Create an XML document to contain the content of an array of Data1Ds 29 29 30 :param datainfo: Data1D object30 :param frame_data: An array of Data1D objects 31 31 """ 32 if not issubclass(datainfo.__class__, Data1D): 33 raise RuntimeError, "The cansas writer expects a Data1D instance" 32 valid_class = all([issubclass(data.__class__, Data1D) for data in frame_data]) 33 if not valid_class: 34 raise RuntimeError, ("The cansas writer expects an array of " 35 "Data1D instances") 34 36 35 37 # Get PIs and create root element … … 46 48 root.append(entry_node) 47 49 50 # Use the first element in the array for writing metadata 51 datainfo = frame_data[0] 48 52 # Add Title to SASentry 49 53 self.write_node(entry_node, "Title", datainfo.title) … … 51 55 self._write_run_names(datainfo, entry_node) 52 56 # Add Data info to SASEntry 53 self._write_data( datainfo, entry_node)57 self._write_data(frame_data, entry_node) 54 58 # Transmission Spectrum Info 55 59 self._write_trans_spectrum(datainfo, entry_node) … … 70 74 # Return the document, and the SASentry node associated with 71 75 # the data we just wrote 72 76 73 77 return doc, entry_node 78 79 def _write_data(self, frame_data, entry_node): 80 """ 81 Writes the I and Q data to the XML file 82 83 :param datainfo: The Data1D object the information is coming from 84 :param entry_node: lxml node ElementTree object to be appended to 85 """ 86 for datainfo in frame_data: 87 node = self.create_element("SASdata") 88 self.append(node, entry_node) 89 90 for i in range(len(datainfo.x)): 91 point = self.create_element("Idata") 92 node.append(point) 93 self.write_node(point, "Q", datainfo.x[i], 94 {'unit': datainfo.x_unit}) 95 if len(datainfo.y) >= i: 96 self.write_node(point, "I", datainfo.y[i], 97 {'unit': datainfo.y_unit}) 98 if datainfo.dy != None and len(datainfo.dy) > i: 99 self.write_node(point, "Idev", datainfo.dy[i], 100 {'unit': datainfo.y_unit}) 101 if datainfo.dx != None and len(datainfo.dx) > i: 102 self.write_node(point, "Qdev", datainfo.dx[i], 103 {'unit': datainfo.x_unit}) 104 if datainfo.dxw != None and len(datainfo.dxw) > i: 105 self.write_node(point, "dQw", datainfo.dxw[i], 106 {'unit': datainfo.x_unit}) 107 if datainfo.dxl != None and len(datainfo.dxl) > i: 108 self.write_node(point, "dQl", datainfo.dxl[i], 109 {'unit': datainfo.x_unit})
Note: See TracChangeset
for help on using the changeset viewer.