Changeset fe78c7b in sasview for DataLoader/readers
- Timestamp:
- Sep 5, 2009 11:45:29 AM (15 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:
- 7d8c41f
- Parents:
- 4deaec6
- Location:
- DataLoader/readers
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/readers/IgorReader.py
r28caa03 rfe78c7b 290 290 output.zaxis("\\rm{Intensity}","cm^{-1}") 291 291 292 292 # Store loading process information 293 output.meta_data['loader'] = self.type_name 293 294 return output 294 295 -
DataLoader/readers/abs_reader.py
r28caa03 rfe78c7b 222 222 else: 223 223 output.yaxis("\\rm{Intensity}","cm^{-1}") 224 225 # Store loading process information 226 output.meta_data['loader'] = self.type_name 224 227 return output 225 228 else: -
DataLoader/readers/ascii_reader.py
re082e2c rfe78c7b 308 308 else: 309 309 output.yaxis("\\rm{Intensity}","cm^{-1}") 310 311 # Store loading process information 312 output.meta_data['loader'] = self.type_name 313 310 314 return output 311 315 -
DataLoader/readers/cansas_reader.py
rb0d0723 rfe78c7b 92 92 return value, attr 93 93 94 def _store_float(location, node, variable, storage): 95 """ 96 Get the content of a xpath location and store 97 the result. Check that the units are compatible 98 with the destination. The value is expected to 99 be a float. 100 101 The xpath location might or might not exist. 102 If it does not exist, nothing is done 103 104 @param location: xpath location to fetch 105 @param node: node to read the data from 106 @param variable: name of the data member to store it in [string] 107 @param storage: data object that has the 'variable' data member 108 109 @raise ValueError: raised when the units are not recognized 110 """ 111 entry = get_content(location, node) 112 try: 113 value = float(entry.text) 114 except: 115 value = None 116 117 if value is not None: 118 # If the entry has units, check to see that they are 119 # compatible with what we currently have in the data object 120 units = entry.get('unit') 121 if units is not None: 122 toks = variable.split('.') 123 exec "local_unit = storage.%s_unit" % toks[0] 124 if units.lower()!=local_unit.lower(): 125 if has_converter==True: 126 try: 127 conv = Converter(units) 128 exec "storage.%s = %g" % (variable, conv(value, units=local_unit)) 129 except: 130 raise ValueError, "CanSAS reader: could not convert %s unit [%s]; expecting [%s]\n %s" \ 131 % (variable, units, local_unit, sys.exc_value) 132 else: 133 raise ValueError, "CanSAS reader: unrecognized %s unit [%s]; expecting [%s]" \ 134 % (variable, units, local_unit) 135 else: 136 exec "storage.%s = value" % variable 137 else: 138 exec "storage.%s = value" % variable 139 140 141 def _store_content(location, node, variable, storage): 142 """ 143 Get the content of a xpath location and store 144 the result. The value is treated as a string. 145 146 The xpath location might or might not exist. 147 If it does not exist, nothing is done 148 149 @param location: xpath location to fetch 150 @param node: node to read the data from 151 @param variable: name of the data member to store it in [string] 152 @param storage: data object that has the 'variable' data member 153 """ 154 entry = get_content(location, node) 155 if entry is not None and entry.text is not None: 156 exec "storage.%s = entry.text.strip()" % variable 157 94 158 95 159 96 class Reader: … … 173 110 ext=['.xml', '.XML'] 174 111 112 def __init__(self): 113 ## List of errors 114 self.errors = [] 115 175 116 def read(self, path): 176 117 """ … … 199 140 200 141 for entry in entry_list: 142 self.errors = [] 201 143 sas_entry = self._parse_entry(entry) 202 144 sas_entry.filename = basename 145 146 # Store loading process information 147 sas_entry.errors = self.errors 148 sas_entry.meta_data['loader'] = self.type_name 203 149 output.append(sas_entry) 204 150 … … 227 173 228 174 # Look up title 229 _store_content('ns:Title', dom, 'title', data_info)175 self._store_content('ns:Title', dom, 'title', data_info) 230 176 231 177 # Look up run number … … 240 186 241 187 # Look up instrument name 242 _store_content('ns:SASinstrument/ns:name', dom, 'instrument', data_info)188 self._store_content('ns:SASinstrument/ns:name', dom, 'instrument', data_info) 243 189 244 190 # Notes … … 251 197 data_info.notes.append(note_value) 252 198 except: 253 logging.error("cansas_reader.read: error processing entry notes\n %s" % sys.exc_value) 199 err_mess = "cansas_reader.read: error processing entry notes\n %s" % sys.exc_value 200 self.errors.append(err_mess) 201 logging.error(err_mess) 254 202 255 203 # Sample info ################### … … 258 206 data_info.sample.name = entry.get('name') 259 207 260 _store_content('ns:SASsample/ns:ID',208 self._store_content('ns:SASsample/ns:ID', 261 209 dom, 'ID', data_info.sample) 262 _store_float('ns:SASsample/ns:thickness',210 self._store_float('ns:SASsample/ns:thickness', 263 211 dom, 'thickness', data_info.sample) 264 _store_float('ns:SASsample/ns:transmission',212 self._store_float('ns:SASsample/ns:transmission', 265 213 dom, 'transmission', data_info.sample) 266 _store_float('ns:SASsample/ns:temperature',214 self._store_float('ns:SASsample/ns:temperature', 267 215 dom, 'temperature', data_info.sample) 268 216 … … 275 223 data_info.sample.details.append(detail_value) 276 224 except: 277 logging.error("cansas_reader.read: error processing sample details\n %s" % sys.exc_value) 225 err_mess = "cansas_reader.read: error processing sample details\n %s" % sys.exc_value 226 self.errors.append(err_mess) 227 logging.error(err_mess) 278 228 279 229 # Position (as a vector) 280 _store_float('ns:SASsample/ns:position/ns:x',230 self._store_float('ns:SASsample/ns:position/ns:x', 281 231 dom, 'position.x', data_info.sample) 282 _store_float('ns:SASsample/ns:position/ns:y',232 self._store_float('ns:SASsample/ns:position/ns:y', 283 233 dom, 'position.y', data_info.sample) 284 _store_float('ns:SASsample/ns:position/ns:z',234 self._store_float('ns:SASsample/ns:position/ns:z', 285 235 dom, 'position.z', data_info.sample) 286 236 287 237 # Orientation (as a vector) 288 _store_float('ns:SASsample/ns:orientation/ns:roll',238 self._store_float('ns:SASsample/ns:orientation/ns:roll', 289 239 dom, 'orientation.x', data_info.sample) 290 _store_float('ns:SASsample/ns:orientation/ns:pitch',240 self._store_float('ns:SASsample/ns:orientation/ns:pitch', 291 241 dom, 'orientation.y', data_info.sample) 292 _store_float('ns:SASsample/ns:orientation/ns:yaw',242 self._store_float('ns:SASsample/ns:orientation/ns:yaw', 293 243 dom, 'orientation.z', data_info.sample) 294 244 … … 298 248 data_info.source.name = entry.get('name') 299 249 300 _store_content('ns:SASinstrument/ns:SASsource/ns:radiation',250 self._store_content('ns:SASinstrument/ns:SASsource/ns:radiation', 301 251 dom, 'radiation', data_info.source) 302 _store_content('ns:SASinstrument/ns:SASsource/ns:beam_shape',252 self._store_content('ns:SASinstrument/ns:SASsource/ns:beam_shape', 303 253 dom, 'beam_shape', data_info.source) 304 _store_float('ns:SASinstrument/ns:SASsource/ns:wavelength',254 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength', 305 255 dom, 'wavelength', data_info.source) 306 _store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_min',256 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_min', 307 257 dom, 'wavelength_min', data_info.source) 308 _store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_max',258 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_max', 309 259 dom, 'wavelength_max', data_info.source) 310 _store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_spread',260 self._store_float('ns:SASinstrument/ns:SASsource/ns:wavelength_spread', 311 261 dom, 'wavelength_spread', data_info.source) 312 262 … … 316 266 data_info.source.beam_size_name = entry.get('name') 317 267 318 _store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:x',268 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:x', 319 269 dom, 'beam_size.x', data_info.source) 320 _store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:y',270 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:y', 321 271 dom, 'beam_size.y', data_info.source) 322 _store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:z',272 self._store_float('ns:SASinstrument/ns:SASsource/ns:beam_size/ns:z', 323 273 dom, 'beam_size.z', data_info.source) 324 274 … … 329 279 if item.get('name') is not None: 330 280 collim.name = item.get('name') 331 _store_float('ns:length', item, 'length', collim)281 self._store_float('ns:length', item, 'length', collim) 332 282 333 283 # Look for apertures … … 340 290 aperture.type = apert.get('type') 341 291 342 _store_float('ns:distance', apert, 'distance', aperture)292 self._store_float('ns:distance', apert, 'distance', aperture) 343 293 344 294 entry = get_content('ns:size', apert) … … 346 296 aperture.size_name = entry.get('name') 347 297 348 _store_float('ns:size/ns:x', apert, 'size.x', aperture)349 _store_float('ns:size/ns:y', apert, 'size.y', aperture)350 _store_float('ns:size/ns:z', apert, 'size.z', aperture)298 self._store_float('ns:size/ns:x', apert, 'size.x', aperture) 299 self._store_float('ns:size/ns:y', apert, 'size.y', aperture) 300 self._store_float('ns:size/ns:z', apert, 'size.z', aperture) 351 301 352 302 collim.aperture.append(aperture) … … 360 310 detector = Detector() 361 311 362 _store_content('ns:name', item, 'name', detector)363 _store_float('ns:SDD', item, 'distance', detector)312 self._store_content('ns:name', item, 'name', detector) 313 self._store_float('ns:SDD', item, 'distance', detector) 364 314 365 315 # Detector offset (as a vector) 366 _store_float('ns:offset/ns:x', item, 'offset.x', detector)367 _store_float('ns:offset/ns:y', item, 'offset.y', detector)368 _store_float('ns:offset/ns:z', item, 'offset.z', detector)316 self._store_float('ns:offset/ns:x', item, 'offset.x', detector) 317 self._store_float('ns:offset/ns:y', item, 'offset.y', detector) 318 self._store_float('ns:offset/ns:z', item, 'offset.z', detector) 369 319 370 320 # Detector orientation (as a vector) 371 _store_float('ns:orientation/ns:roll', item, 'orientation.x', detector)372 _store_float('ns:orientation/ns:pitch', item, 'orientation.y', detector)373 _store_float('ns:orientation/ns:yaw', item, 'orientation.z', detector)321 self._store_float('ns:orientation/ns:roll', item, 'orientation.x', detector) 322 self._store_float('ns:orientation/ns:pitch', item, 'orientation.y', detector) 323 self._store_float('ns:orientation/ns:yaw', item, 'orientation.z', detector) 374 324 375 325 # Beam center (as a vector) 376 _store_float('ns:beam_center/ns:x', item, 'beam_center.x', detector)377 _store_float('ns:beam_center/ns:y', item, 'beam_center.y', detector)378 _store_float('ns:beam_center/ns:z', item, 'beam_center.z', detector)326 self._store_float('ns:beam_center/ns:x', item, 'beam_center.x', detector) 327 self._store_float('ns:beam_center/ns:y', item, 'beam_center.y', detector) 328 self._store_float('ns:beam_center/ns:z', item, 'beam_center.z', detector) 379 329 380 330 # Pixel size (as a vector) 381 _store_float('ns:pixel_size/ns:x', item, 'pixel_size.x', detector)382 _store_float('ns:pixel_size/ns:y', item, 'pixel_size.y', detector)383 _store_float('ns:pixel_size/ns:z', item, 'pixel_size.z', detector)384 385 _store_float('ns:slit_length', item, 'slit_length', detector)331 self._store_float('ns:pixel_size/ns:x', item, 'pixel_size.x', detector) 332 self._store_float('ns:pixel_size/ns:y', item, 'pixel_size.y', detector) 333 self._store_float('ns:pixel_size/ns:z', item, 'pixel_size.z', detector) 334 335 self._store_float('ns:slit_length', item, 'slit_length', detector) 386 336 387 337 data_info.detector.append(detector) … … 391 341 for item in nodes: 392 342 process = Process() 393 _store_content('ns:name', item, 'name', process)394 _store_content('ns:date', item, 'date', process)395 _store_content('ns:description', item, 'description', process)343 self._store_content('ns:name', item, 'name', process) 344 self._store_content('ns:date', item, 'date', process) 345 self._store_content('ns:description', item, 'description', process) 396 346 397 347 term_list = item.xpath('ns:term', namespaces={'ns': CANSAS_NS}) … … 405 355 process.term.append(term_attr) 406 356 except: 407 logging.error("cansas_reader.read: error processing process term\n %s" % sys.exc_value) 357 err_mess = "cansas_reader.read: error processing process term\n %s" % sys.exc_value 358 self.errors.append(err_mess) 359 logging.error(err_mess) 408 360 409 361 note_list = item.xpath('ns:SASprocessnote', namespaces={'ns': CANSAS_NS}) … … 756 708 fd.close() 757 709 758 710 def _store_float(self, location, node, variable, storage, optional=True): 711 """ 712 Get the content of a xpath location and store 713 the result. Check that the units are compatible 714 with the destination. The value is expected to 715 be a float. 716 717 The xpath location might or might not exist. 718 If it does not exist, nothing is done 719 720 @param location: xpath location to fetch 721 @param node: node to read the data from 722 @param variable: name of the data member to store it in [string] 723 @param storage: data object that has the 'variable' data member 724 @param optional: if True, no exception will be raised if unit conversion can't be done 725 726 @raise ValueError: raised when the units are not recognized 727 """ 728 entry = get_content(location, node) 729 try: 730 value = float(entry.text) 731 except: 732 value = None 733 734 if value is not None: 735 # If the entry has units, check to see that they are 736 # compatible with what we currently have in the data object 737 units = entry.get('unit') 738 if units is not None: 739 toks = variable.split('.') 740 exec "local_unit = storage.%s_unit" % toks[0] 741 if units.lower()!=local_unit.lower(): 742 if has_converter==True: 743 try: 744 conv = Converter(units) 745 exec "storage.%s = %g" % (variable, conv(value, units=local_unit)) 746 except: 747 err_mess = "CanSAS reader: could not convert %s unit [%s]; expecting [%s]\n %s" \ 748 % (variable, units, local_unit, sys.exc_value) 749 self.errors.append(err_mess) 750 if optional: 751 logging.info(err_mess) 752 else: 753 raise ValueError, err_mess 754 else: 755 err_mess = "CanSAS reader: unrecognized %s unit [%s]; expecting [%s]" \ 756 % (variable, units, local_unit) 757 self.errors.append(err_mess) 758 if optional: 759 logging.info(err_mess) 760 else: 761 raise ValueError, err_mess 762 else: 763 exec "storage.%s = value" % variable 764 else: 765 exec "storage.%s = value" % variable 766 767 def _store_content(self, location, node, variable, storage): 768 """ 769 Get the content of a xpath location and store 770 the result. The value is treated as a string. 771 772 The xpath location might or might not exist. 773 If it does not exist, nothing is done 774 775 @param location: xpath location to fetch 776 @param node: node to read the data from 777 @param variable: name of the data member to store it in [string] 778 @param storage: data object that has the 'variable' data member 779 @return: return a list of errors 780 """ 781 entry = get_content(location, node) 782 if entry is not None and entry.text is not None: 783 exec "storage.%s = entry.text.strip()" % variable 784 785 786 759 787 if __name__ == "__main__": 760 788 logging.basicConfig(level=logging.ERROR, -
DataLoader/readers/danse_reader.py
r28caa03 rfe78c7b 275 275 else: 276 276 logging.info("Danse_reader Reading %s \n"%filename) 277 return output 277 278 # Store loading process information 279 output.meta_data['loader'] = self.type_name 280 return output 278 281 279 282 return None -
DataLoader/readers/hfir1d_reader.py
r28caa03 rfe78c7b 120 120 output.yaxis("\\rm{Intensity}","cm^{-1}") 121 121 122 # Store loading process information 123 output.meta_data['loader'] = self.type_name 122 124 return output 123 125 else: -
DataLoader/readers/tiff_reader.py
r28caa03 rfe78c7b 95 95 output.ymax = im.size[0]-1 96 96 97 # Store loading process information 98 output.meta_data['loader'] = self.type_name 97 99 return output 98 100
Note: See TracChangeset
for help on using the changeset viewer.