Changeset b3efb7d in sasview
- Timestamp:
- Feb 14, 2015 11:16:03 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:
- 10a483f
- Parents:
- b3133fd
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/data_util/nxsunit.py
r79492222 rb3efb7d 128 128 temperature = _build_metric_units('kelvin','K') 129 129 temperature.update(_build_metric_units('Kelvin','K')) 130 130 temperature.update(_build_metric_units('Celcius', 'C')) 131 temperature.update(_build_metric_units('celcius', 'C')) 132 131 133 charge = _build_metric_units('coulomb','C') 132 134 charge.update({'microAmp*hour':0.0036}) … … 146 148 """ 147 149 Unit converter for NeXus style units. 148 149 150 """ 150 151 # Define the units, using both American and European spelling. -
src/sas/dataloader/data_info.py
r79492222 rb3efb7d 338 338 ## Transmission [float] [fraction] 339 339 transmission = None 340 ## Temperature [float] [ C]340 ## Temperature [float] [No Default] 341 341 temperature = None 342 temperature_unit = 'C'342 temperature_unit = None 343 343 ## Position [Vector] [mm] 344 344 position = 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 != '': -
src/sas/guiframe/gui_statusbar.py
r79492222 rb3efb7d 315 315 if msg == "error": 316 316 e_msg = "Error(s) Occurred:\n" 317 e_msg += event.status 317 e_msg += "\t" + event.status + "\n\n" 318 e_msg += "Further information might be available in " 319 e_msg += "the Console log (bottom right corner)." 318 320 wx.MessageBox(e_msg, style=wx.ICON_ERROR) 319 321 -
src/sas/guiframe/local_perspectives/data_loader/data_loader.py
r7a04dbb rb3efb7d 171 171 file) for file in os.listdir(path)] 172 172 173 def _process_data_and_errors(self, item, p_file, output, message): 174 """ 175 Check to see if data set loaded with any errors. If so, append to 176 error message to be sure user knows the issue. 177 """ 178 data_error = False 179 for error_data in item.errors: 180 data_error = True 181 message += "\tError: {0}\n".format(error_data) 182 data = self.parent.create_gui_data(item, p_file) 183 output[data.id] = data 184 return output, message, data_error 185 173 186 def get_data(self, path, format=None): 174 187 """ … … 178 191 output = {} 179 192 any_error = False 193 data_error = False 180 194 error_message = "" 181 195 for p_file in path: 182 196 info = "info" 183 197 basename = os.path.basename(p_file) 184 root, extension = os.path.splitext(basename)198 _, extension = os.path.splitext(basename) 185 199 if extension.lower() in EXTENSIONS: 186 200 any_error = True … … 194 208 195 209 try: 210 message = "Loading Data... " + str(p_file) + "\n" 211 self.load_update(output=output, message=message, info=info) 196 212 temp = self.loader.load(p_file, format) 197 213 if temp.__class__.__name__ == "list": 198 214 for item in temp: 199 data = self.parent.create_gui_data(item, p_file) 200 output[data.id] = data 215 output, error_message, data_error = \ 216 self._process_data_and_errors(item, 217 p_file, 218 output, 219 error_message) 201 220 else: 202 data = self.parent.create_gui_data(temp, p_file) 203 output[data.id] = data 204 message = "Loading Data..." + str(p_file) + "\n" 205 self.load_update(output=output, message=message, info=info) 221 output, error_message, data_error = \ 222 self._process_data_and_errors(temp, 223 p_file, 224 output, 225 error_message) 206 226 except: 207 227 any_error = True 208 if error_message == "": 209 error = "Error: " + str(sys.exc_value) + "\n" 210 error += "while loading Data: \n%s\n" % str(p_file) 211 error_message = "The data file you selected could not be loaded.\n" 212 error_message += "Make sure the content of your file" 213 error_message += " is properly formatted.\n\n" 214 error_message += "When contacting the DANSE team, mention the" 215 error_message += " following:\n%s" % str(error) 216 else: 217 error_message += "%s\n"% str(p_file) 218 info = "error" 219 self.load_update(output=output, message=error_message, 228 if any_error or error_message != "": 229 if error_message == "": 230 error = "Error: " + str(sys.exc_value) + "\n" 231 error += "while loading Data: \n%s\n" % str(p_file) 232 error_message = "The data file you selected could not be loaded.\n" 233 error_message += "Make sure the content of your file" 234 error_message += " is properly formatted.\n\n" 235 error_message += "When contacting the DANSE team, mention the" 236 error_message += " following:\n%s" % str(error) 237 elif data_error: 238 base_message = "Errors occurred while loading {0}\n".format(p_file) 239 base_message += "The data file loaded but with errors.\n" 240 error_message = base_message + error_message 241 else: 242 error_message += "%s\n"% str(p_file) 243 info = "error" 244 self.load_update(output=output, message=error_message, 220 245 info=info) 221 246 222 message = "Loading Data Complete! " 247 else: 248 message = "Loading Data Complete! " 223 249 message += log_msg 224 if error_message != "":225 info = 'error'226 250 self.load_complete(output=output, error_message=error_message, 227 251 message=message, path=path, info=info) -
test/sasdataloader/test/utest_abs_reader.py
r35ec279 rb3efb7d 345 345 self.assertEqual(self.data.filename, filename) 346 346 # The followed should not have been loaded 347 self.assertEqual(self.data.sample.thickness, None)347 self.assertEqual(self.data.sample.thickness, 0.00103) 348 348 # This one should 349 349 self.assertEqual(self.data.sample.transmission, 0.327) 350 350 351 351 self.assertEqual(self.data.meta_data['loader'], "CanSAS 1D") 352 self.assertEqual(len(self.data.errors), 1) 352 print self.data.errors 353 self.assertEqual(len(self.data.errors), 2) 353 354 354 355
Note: See TracChangeset
for help on using the changeset viewer.