Changes in / [4abcc93a:a4deca6] in sasview
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/cansas_reader.py
r5f26aa4 r1686a333 206 206 # Go through each child in the parent element 207 207 for node in dom: 208 attr = node.attrib209 name = attr.get("name", "")210 type = attr.get("type", "")211 208 # Get the element name and set the current names level 212 209 tagname = node.tag.replace(self.base_ns, "") … … 226 223 ## Recursion step to access data within the group 227 224 self._parse_entry(node) 228 if tagname == "SASsample":229 self.current_datainfo.sample.name = name230 elif tagname == "beam_size":231 self.current_datainfo.source.beam_size_name = name232 elif tagname == "SAScollimation":233 self.collimation.name = name234 elif tagname == "aperture":235 self.aperture.name = name236 self.aperture.type = type237 225 self.add_intermediate() 238 226 else: … … 241 229 ## If this is a dataset, store the data appropriately 242 230 if tagname == 'Run': 243 self.current_datainfo.run_name[data_point] = name244 231 self.current_datainfo.run.append(data_point) 245 232 elif tagname == 'Title': … … 382 369 self.process.notes.append(data_point) 383 370 elif tagname == 'term' and self.parent_class == 'SASprocess': 384 unit = attr.get("unit", "") 385 dic = {} 386 dic["name"] = name 387 dic["value"] = data_point 388 dic["unit"] = unit 389 self.process.term.append(dic) 371 self.process.term.append(data_point) 390 372 391 373 ## Transmission Spectrum … … 549 531 self.current_datainfo.collimation.append(self.collimation) 550 532 self.collimation = Collimation() 551 elif self.parent_class == ' aperture':533 elif self.parent_class == 'SASaperture': 552 534 self.collimation.aperture.append(self.aperture) 553 535 self.aperture = Aperture() … … 664 646 err_msg = None 665 647 default_unit = None 666 if not isinstance(node_value, float): 667 node_value = float(node_value) 668 if 'unit' in attr and attr.get('unit') is not None: 648 if 'unit' in attr and attr.get('unit') is not None and not self.ns_list.ns_optional: 669 649 try: 670 650 local_unit = attr['unit'] 651 if not isinstance(node_value, float): 652 node_value = float(node_value) 671 653 unitname = self.ns_list.current_level.get("unit", "") 672 654 if "SASdetector" in self.names: … … 925 907 self.write_node(point, "I", datainfo.y[i], 926 908 {'unit': datainfo.y_unit}) 927 if datainfo.dy is notNone and len(datainfo.dy) > i:909 if datainfo.dy != None and len(datainfo.dy) > i: 928 910 self.write_node(point, "Idev", datainfo.dy[i], 929 911 {'unit': datainfo.y_unit}) 930 if datainfo.dx is notNone and len(datainfo.dx) > i:912 if datainfo.dx != None and len(datainfo.dx) > i: 931 913 self.write_node(point, "Qdev", datainfo.dx[i], 932 914 {'unit': datainfo.x_unit}) 933 if datainfo.dxw is notNone and len(datainfo.dxw) > i:915 if datainfo.dxw != None and len(datainfo.dxw) > i: 934 916 self.write_node(point, "dQw", datainfo.dxw[i], 935 917 {'unit': datainfo.x_unit}) 936 if datainfo.dxl is notNone and len(datainfo.dxl) > i:918 if datainfo.dxl != None and len(datainfo.dxl) > i: 937 919 self.write_node(point, "dQl", datainfo.dxl[i], 938 920 {'unit': datainfo.x_unit}) … … 1202 1184 if isinstance(term, list): 1203 1185 value = term['value'] 1204 del term['value']1205 elif isinstance(term, dict):1206 value = term.get("value")1207 1186 del term['value'] 1208 1187 else: -
test/sasdataloader/test/utest_abs_reader.py
r5f26aa4 rb699768 176 176 177 177 self.assertEqual(self.data.run[0], "1234") 178 self.assertEqual(self.data.meta_data['loader'], "CanSAS XML 1D") 178 self.assertEqual(self.data.meta_data['loader'], "CanSAS 1D") 179 self.assertEqual(len(self.data.errors), 0) 179 180 180 181 # Data … … 197 198 self.assertEqual(self.data.sample.name, "my sample") 198 199 self.assertEqual(self.data.sample.thickness_unit, 'mm') 199 self.assert AlmostEqual(self.data.sample.thickness, 1.03)200 201 self.assert AlmostEqual(self.data.sample.transmission, 0.327)200 self.assertEqual(self.data.sample.thickness, 1.03) 201 202 self.assertEqual(self.data.sample.transmission, 0.327) 202 203 203 204 self.assertEqual(self.data.sample.temperature_unit, 'C') … … 232 233 233 234 self.assertEqual(self.data.source.wavelength_max_unit, "nm") 234 self.assert AlmostEqual(self.data.source.wavelength_max, 1.0)235 self.assertEqual(self.data.source.wavelength_max, 1.0) 235 236 self.assertEqual(self.data.source.wavelength_min_unit, "nm") 236 self.assert AlmostEqual(self.data.source.wavelength_min, 0.22)237 self.assertEqual(self.data.source.wavelength_min, 0.22) 237 238 self.assertEqual(self.data.source.wavelength_spread_unit, "percent") 238 239 self.assertEqual(self.data.source.wavelength_spread, 14.3) … … 247 248 self.assertEqual(item.size_unit,'mm') 248 249 self.assertEqual(item.distance_unit,'mm') 249 250 250 251 if item.size.x==50 \ 251 252 and item.distance==11000.0 \ … … 293 294 self.assertTrue(item.date in ['04-Sep-2007 18:35:02', 294 295 '03-SEP-2006 11:42:47']) 295 print item.term296 296 for t in item.term: 297 297 if t['name']=="ABS:DSTAND" \ … … 345 345 self.assertEqual(self.data.filename, filename) 346 346 # The followed should not have been loaded 347 self.assert AlmostEqual(self.data.sample.thickness, 0.00103)347 self.assertEqual(self.data.sample.thickness, 0.00103) 348 348 # This one should 349 self.assert AlmostEqual(self.data.sample.transmission, 0.327)350 351 self.assertEqual(self.data.meta_data['loader'], "CanSAS XML1D")349 self.assertEqual(self.data.sample.transmission, 0.327) 350 351 self.assertEqual(self.data.meta_data['loader'], "CanSAS 1D") 352 352 print self.data.errors 353 353 self.assertEqual(len(self.data.errors), 1) … … 385 385 386 386 if __name__ == '__main__': 387 unittest.main( )387 unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
Note: See TracChangeset
for help on using the changeset viewer.