Changeset 48153283 in sasview for src/sas/dataloader/readers
- Timestamp:
- Feb 17, 2015 3:46:30 AM (10 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:
- 36c5910
- Parents:
- 920928f (diff), 5dfdfa7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- src/sas/dataloader/readers
- Files:
-
- 1 added
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/dataloader/readers/associations.py
rfd5ac0d r5dfdfa7 17 17 import sys 18 18 import logging 19 from lxml import etree 20 # Py2exe compatibility: import _elementpath to ensure that py2exe finds it 21 from lxml import _elementpath 19 import json 22 20 23 ## Format version for the XML settings file 24 VERSION = 'sasloader/1.0' 21 FILE_NAME = 'defaults.json' 25 22 26 27 def read_associations(loader, settings='defaults.xml'): 23 def read_associations(loader, settings=FILE_NAME): 28 24 """ 29 25 Read the specified settings file to associate … … 31 27 32 28 :param loader: Loader object 33 :param settings: path to the XMLsettings file [string]29 :param settings: path to the json settings file [string] 34 30 """ 35 31 reader_dir = os.path.dirname(__file__) … … 47 43 path = "./%s" % settings 48 44 if os.path.isfile(path): 49 tree = etree.parse(path, parser=etree.ETCompatXMLParser()) 50 51 # Check the format version number 52 # Specifying the namespace will take care of the file format version 53 root = tree.getroot() 45 with open(path) as fh: 46 json_tree = json.load(fh) 54 47 55 48 # Read in the file extension associations 56 entry_list = root.xpath('/ns:SasLoader/ns:FileType', 57 namespaces={'ns': VERSION}) 49 entry_list = json_tree['SasLoader']['FileType'] 58 50 59 51 # For each FileType entry, get the associated reader and extension 60 52 for entry in entry_list: 61 reader = entry .get('reader')62 ext = entry .get('extension')53 reader = entry['-reader'] 54 ext = entry['-extension'] 63 55 64 56 if reader is not None and ext is not None: -
src/sas/dataloader/readers/cansas_reader.py
r79492222 rb3efb7d 307 307 if 'unit' in attr and new_current_level.get('unit') is not None: 308 308 try: 309 local_unit = attr['unit'] 309 310 if isinstance(node_value, float) is False: 310 311 exec("node_value = float({0})".format(node_value)) … … 312 313 unitname = new_current_level.get("unit") 313 314 exec "default_unit = data1d.{0}".format(unitname) 314 local_unit = attr['unit'] 315 if local_unit.lower() != default_unit.lower() and \ 316 local_unit is not None and local_unit.lower() != "none" \ 317 and default_unit is not None: 315 if local_unit is not None and default_unit is not None and \ 316 local_unit.lower() != default_unit.lower() \ 317 and local_unit.lower() != "none": 318 318 if HAS_CONVERTER == True: 319 try: 320 ## Check local units - bad units raise KeyError 321 Converter(local_unit) 322 data_conv_q = Converter(attr['unit']) 323 value_unit = default_unit 324 i_string = "node_value = data_conv_q" 325 i_string += "(node_value, units=data1d.{0})" 326 exec i_string.format(unitname) 327 except KeyError: 328 err_msg = "CanSAS reader: could not convert " 329 err_msg += "{0} unit {1}; " 330 err_msg = err_msg.format(tagname, local_unit) 331 intermediate = "err_msg += " + \ 332 "\"expecting [{1}] {2}\"" + \ 333 ".format(data1d.{0}, " + \ 334 "sys.exc_info()[1])" 335 exec intermediate.format(unitname, "{0}", "{1}") 336 self.errors.append(err_msg) 337 raise ValueError(err_msg) 338 except: 339 err_msg = \ 340 "CanSAS reader: could not convert the units" 341 self.errors.append(err_msg) 342 return 319 ## Check local units - bad units raise KeyError 320 data_conv_q = Converter(local_unit) 321 value_unit = default_unit 322 i_string = "node_value = data_conv_q" 323 i_string += "(node_value, units=data1d.{0})" 324 exec i_string.format(unitname) 343 325 else: 344 326 value_unit = local_unit 345 err_msg = "CanSAS reader: unrecognized %s unit [%s];"\ 346 % (node_value, default_unit) 347 err_msg += " expecting [%s]" % local_unit 327 err_msg = "Unit converter is not available.\n" 348 328 self.errors.append(err_msg) 349 raise ValueError, err_msg350 329 else: 351 330 value_unit = local_unit 331 except KeyError: 332 err_msg = "CanSAS reader: unexpected " 333 err_msg += "\"{0}\" unit [{1}]; " 334 err_msg = err_msg.format(tagname, local_unit) 335 intermediate = "err_msg += " + \ 336 "\"expecting [{1}]\"" + \ 337 ".format(data1d.{0})" 338 exec intermediate.format(unitname, "{0}", "{1}") 339 self.errors.append(err_msg) 340 value_unit = local_unit 352 341 except: 353 err_msg = "CanSAS reader: could not convert " 354 err_msg += "Q unit [%s]; " % attr['unit'] 355 intermediate = "err_msg += \"expecting [%s]\n %s\" % " + \ 356 "(data1d.{0}, sys.exc_info()[1])" 357 exec intermediate.format(unitname) 342 print sys.exc_info() 343 err_msg = "CanSAS reader: unknown error converting " 344 err_msg += "\"{0}\" unit [{1}]" 345 err_msg = err_msg.format(tagname, local_unit) 358 346 self.errors.append(err_msg) 359 raise ValueError, err_msg347 value_unit = local_unit 360 348 elif 'unit' in attr: 361 349 value_unit = attr['unit'] … … 488 476 data1d, tagname) 489 477 cansas_attrib = \ 490 cs_values.current_level.get("attributes").get(key)478 cs_values.current_level.get("attributes").get(key) 491 479 attrib_variable = cansas_attrib.get("variable") 492 480 if key == 'unit' and unit != '':
Note: See TracChangeset
for help on using the changeset viewer.