Changeset a235f715 in sasview
- Timestamp:
- Sep 14, 2016 11:33:30 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, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- b61bd57
- Parents:
- 7d94915
- git-author:
- Jeff Krzywon <krzywon@…> (09/14/16 11:33:30)
- git-committer:
- Jeff KRzywon <krzywon@…> (09/14/16 11:33:30)
- Location:
- src/sas/sascalc/dataloader/readers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/anton_paar_saxs_reader.py
r80c5d46 ra235f715 45 45 output = None 46 46 47 def __init__(self):47 def reset_state(self): 48 48 self.current_dataset = Data1D(np.empty(0), np.empty(0), 49 49 np.empty(0), np.empty(0)) … … 72 72 73 73 ## Reinitialize the class when loading a new data file to reset all class variables 74 self. __init__()74 self.reset_state() 75 75 ## Check that the file exists 76 76 if os.path.isfile(filename): … … 84 84 self.raw_data = buff.splitlines() 85 85 self.read_data() 86 xml_intermediate = self.raw_data[self.upper:]87 xml = ''.join(xml_intermediate)88 self.set_xml_file(xml)89 86 return self.output 90 87 … … 100 97 self.lower = 5 101 98 self.upper = self.lower + self.data_points 102 self.detector.distance = float(line4[1]) 99 self.source.radiation = 'x-ray' 100 normal = float(line4[3]) 103 101 self.current_dataset.source.radiation = "x-ray" 104 102 self.current_dataset.source.name = "Anton Paar SAXSess Instrument" 105 103 self.current_dataset.source.wavelength = float(line4[4]) 106 normal = line4[3] 104 xvals = [] 105 yvals = [] 106 dyvals = [] 107 107 for i in range(self.lower, self.upper): 108 index = i - self.lower 108 109 data = self.raw_data[i].split() 109 x_val = [float(data[0])] 110 y_val = [float(data[1])] 111 dy_val = [float(data[2])] 112 self.current_dataset.x = np.append(self.current_dataset.x, x_val) 113 self.current_dataset.y = np.append(self.current_dataset.y, y_val) 114 self.current_dataset.dy = np.append(self.current_dataset.dy, dy_val) 115 self.current_dataset.xaxis("Q (%s)" % (q_unit), q_unit) 116 self.current_dataset.yaxis("Intensity (%s)" % (i_unit), i_unit) 117 self.current_dataset.detector.append(self.detector) 110 xvals.insert(index, normal * float(data[0])) 111 yvals.insert(index, normal * float(data[1])) 112 dyvals.insert(index, normal * float(data[2])) 113 self.current_dataset.x = np.append(self.current_dataset.x, xvals) 114 self.current_dataset.y = np.append(self.current_dataset.y, yvals) 115 self.current_dataset.dy = np.append(self.current_dataset.dy, dyvals) 116 if self.data_points != self.current_dataset.x.size: 117 self.errors.add("Not all data was loaded properly.") 118 if self.current_dataset.dx.size != self.current_dataset.x.size: 119 dxvals = np.zeros(self.current_dataset.x.size) 120 self.current_dataset.dx = dxvals 121 if self.current_dataset.x.size != self.current_dataset.y.size: 122 self.errors.add("The x and y data sets are not the same size.") 123 if self.current_dataset.y.size != self.current_dataset.dy.size: 124 self.errors.add("The y and dy datasets are not the same size.") 125 self.current_dataset.errors = self.errors 126 self.current_dataset.xaxis("Q", q_unit) 127 self.current_dataset.yaxis("Intensity", i_unit) 128 xml_intermediate = self.raw_data[self.upper:] 129 xml = ''.join(xml_intermediate) 130 self.set_xml_string(xml) 131 dom = self.xmlroot.xpath('/fileinfo') 132 self._parse_child(dom) 118 133 self.output.append(self.current_dataset) 134 135 def _parse_child(self, dom, parent=''): 136 """ 137 Recursive method for stepping through the embedded XML 138 :param dom: XML node with or without children 139 """ 140 for node in dom: 141 tagname = node.tag 142 value = node.text 143 attr = node.attrib 144 key = attr.get("key", '') 145 if len(node.getchildren()) > 1: 146 self._parse_child(node, key) 147 if key == "SampleDetector": 148 self.current_dataset.detector.append(self.detector) 149 self.detector = Detector() 150 else: 151 if key == "value": 152 if parent == "Wavelength": 153 self.current_dataset.source.wavelength = value 154 elif parent == "SampleDetector": 155 self.detector.distance = value 156 elif parent == "Temperature": 157 self.current_dataset.sample.temperature = value 158 elif parent == "CounterSlitLength": 159 self.detector.slit_length = value 160 elif key == "unit": 161 value = value.replace("_", "") 162 if parent == "Wavelength": 163 self.current_dataset.source.wavelength_unit = value 164 elif parent == "SampleDetector": 165 self.detector.distance_unit = value 166 elif parent == "X": 167 self.current_dataset.xaxis(self.current_dataset._xaxis, value) 168 elif parent == "Y": 169 self.current_dataset.yaxis(self.current_dataset._yaxis, value) 170 elif parent == "Temperature": 171 self.current_dataset.sample.temperature_unit = value 172 elif parent == "CounterSlitLength": 173 self.detector.slit_length_unit = value 174 elif key == "quantity": 175 if parent == "X": 176 self.current_dataset.xaxis(value, self.current_dataset._xunit) 177 elif parent == "Y": 178 self.current_dataset.yaxis(value, self.current_dataset._yunit) -
src/sas/sascalc/dataloader/readers/xml_reader.py
rb699768 ra235f715 70 70 self.xmldoc = etree.parse(self.xml, parser=PARSER) 71 71 self.xmlroot = self.xmldoc.getroot() 72 except etree.XMLSyntaxError as xml_error: 73 logging.info(xml_error) 74 except Exception: 75 self.xml = None 76 self.xmldoc = None 77 self.xmlroot = None 78 79 def set_xml_string(self, tag_soup): 80 """ 81 Set an XML string as the working XML. 82 83 :param tag_soup: XML formatted string 84 """ 85 try: 86 self.xml = tag_soup 87 self.xmldoc = tag_soup 88 self.xmlroot = etree.fromstring(tag_soup) 72 89 except etree.XMLSyntaxError as xml_error: 73 90 logging.info(xml_error)
Note: See TracChangeset
for help on using the changeset viewer.