Changeset 92c8fec in sasview
- Timestamp:
- Apr 1, 2014 5:26:38 AM (11 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:
- d0ac63f
- Parents:
- d7b46e71
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sans/dataloader/readers/cansas_reader.py
rc6ca23d r92c8fec 265 265 266 266 def _unit_conversion(self, new_current_level, attr, data1d, \ 267 node_value, optional = True):267 tagname, node_value, optional = True): 268 268 """ 269 269 A unit converter method used to convert the data included in the file … … 291 291 if HAS_CONVERTER == True: 292 292 try: 293 ## Check local units - bad units should raise KeyError 294 Converter(local_unit) 293 295 data_conv_q = Converter(attr['unit']) 294 296 value_unit = default_unit 295 297 exec "node_value = data_conv_q(node_value, units=data1d.{0})".format(unitname) 296 except :298 except KeyError as e: 297 299 err_msg = "CanSAS reader: could not convert " 298 err_msg += " Q unit {0}; ".format(local_unit)300 err_msg += "{0} unit {1}; ".format(tagname, local_unit) 299 301 intermediate = "err_msg += \"expecting [{1}] {2}\".format(data1d.{0}, sys.exc_info()[1])".format(unitname, "{0}", "{1}") 300 302 exec intermediate 301 303 self.errors.append(err_msg) 302 if optional: 303 logging.info(err_msg) 304 else: 305 raise ValueError, err_msg 304 raise ValueError(err_msg) 305 return 306 except: 307 err_msg = "error occured" 308 return 306 309 else: 307 310 value_unit = local_unit … … 310 313 err_msg += " expecting [%s]" % local_unit 311 314 self.errors.append(err_msg) 312 if optional: 313 logging.info(err_msg) 314 else: 315 raise ValueError, err_msg 315 raise ValueError, err_msg 316 return 316 317 else: 317 318 value_unit = local_unit … … 321 322 exec "err_msg += \"expecting [%s]\n %s\" % (data1d.{0}, sys.exc_info()[1])".format(unitname) 322 323 self.errors.append(err_msg) 323 if optional: 324 logging.info(err_msg) 325 else: 326 raise ValueError, err_msg 324 raise ValueError, err_msg 325 return 327 326 elif 'unit' in attr: 328 327 value_unit = attr['unit'] … … 415 414 or node_value.lower() == "nan": 416 415 node_value = "0.0" 417 node_value, unit = self._unit_conversion(\ 416 try: 417 node_value, unit = self._unit_conversion(\ 418 418 cs_values.current_level, attr, data1d, \ 419 node_value, cs_values.ns_optional) 419 tagname, node_value, cs_values.ns_optional) 420 except TypeError: 421 print "TypeError with units of {0} and node of {1}".format(attr['unit'], tagname) 420 422 421 423 # If appending to a dictionary (meta_data | run_name)
Note: See TracChangeset
for help on using the changeset viewer.