- Timestamp:
- Sep 25, 2017 11:13:29 AM (7 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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 9e6aeaf
- Parents:
- b796c72
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/cansas_reader.py
re6e89c4 r9efdb29 34 34 INVALID_XML = "\n\nThe loaded xml file, {0} does not fully meet the CanSAS v1.x specification. SasView loaded " + \ 35 35 "as much of the data as possible.\n\n" 36 HAS_CONVERTER = True37 36 38 37 CONSTANTS = CansasConstants() … … 160 159 raise fc_exc 161 160 except Exception as e: # Convert all other exceptions to FileContentsExceptions 162 raise163 161 raise FileContentsException(str(e)) 164 162 … … 634 632 and local_unit.lower() != default_unit.lower() 635 633 and local_unit.lower() != "none"): 636 if HAS_CONVERTER: 637 # Check local units - bad units raise KeyError 638 #print("loading", tagname, node_value, local_unit, default_unit) 639 data_conv_q = Converter(local_unit) 640 value_unit = default_unit 641 node_value = data_conv_q(node_value, units=default_unit) 642 else: 643 value_unit = local_unit 644 err_msg = "Unit converter is not available.\n" 634 # Check local units - bad units raise KeyError 635 #print("loading", tagname, node_value, local_unit, default_unit) 636 data_conv_q = Converter(local_unit) 637 value_unit = default_unit 638 node_value = data_conv_q(node_value, units=default_unit) 645 639 else: 646 640 value_unit = local_unit … … 1287 1281 local_unit = getattr(storage, toks[0]+"_unit") 1288 1282 if local_unit is not None and units.lower() != local_unit.lower(): 1289 if HAS_CONVERTER == True: 1290 try: 1291 conv = Converter(units) 1292 setattrchain(storage, variable, conv(value, units=local_unit)) 1293 except Exception: 1294 _, exc_value, _ = sys.exc_info() 1295 err_mess = "CanSAS reader: could not convert" 1296 err_mess += " %s unit [%s]; expecting [%s]\n %s" \ 1297 % (variable, units, local_unit, exc_value) 1298 self.errors.add(err_mess) 1299 if optional: 1300 logger.info(err_mess) 1301 else: 1302 raise ValueError(err_mess) 1303 else: 1304 err_mess = "CanSAS reader: unrecognized %s unit [%s];"\ 1305 % (variable, units) 1306 err_mess += " expecting [%s]" % local_unit 1283 try: 1284 conv = Converter(units) 1285 setattrchain(storage, variable, conv(value, units=local_unit)) 1286 except Exception: 1287 _, exc_value, _ = sys.exc_info() 1288 err_mess = "CanSAS reader: could not convert" 1289 err_mess += " %s unit [%s]; expecting [%s]\n %s" \ 1290 % (variable, units, local_unit, exc_value) 1307 1291 self.errors.add(err_mess) 1308 1292 if optional: … … 1333 1317 entry = get_content(location, node) 1334 1318 if entry is not None and entry.text is not None: 1335 exec("storage.%s = entry.text.strip()" % variable)1319 setattrchain(storage, variable, entry.text.strip()) 1336 1320 1337 1321 # DO NOT REMOVE Called by outside packages:
Note: See TracChangeset
for help on using the changeset viewer.