Changeset dfcdbf8 in sasview for src/sas/sascalc
- Timestamp:
- Nov 1, 2018 2:23:18 PM (6 years ago)
- Branches:
- master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249
- Children:
- 282bc3f
- Parents:
- 9f45f83
- Location:
- src/sas/sascalc/dataloader
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/file_reader_base_class.py
r9fb4572 rdfcdbf8 47 47 ext = ['.txt'] 48 48 # Deprecated extensions 49 deprecated_extensions = ['.asc' , '.nxs']49 deprecated_extensions = ['.asc'] 50 50 # Bypass extension check and try to load anyway 51 51 allow_all = False … … 151 151 """ 152 152 if len(self.output) > 0: 153 self.output[-1].errors.a ppend(msg)153 self.output[-1].errors.add(msg) 154 154 elif isinstance(self.current_datainfo, DataInfo): 155 self.current_datainfo.errors.a ppend(msg)155 self.current_datainfo.errors.add(msg) 156 156 else: 157 157 logger.warning(msg) … … 304 304 return data 305 305 306 def convert_data_units(self, default_q_unit="1/A" , default_i_unit="1/cm"):306 def convert_data_units(self, default_q_unit="1/A"): 307 307 """ 308 308 Converts al; data to the sasview default of units of A^{-1} for Q and 309 309 cm^{-1} for I. 310 310 :param default_q_unit: The default Q unit used by Sasview 311 :param default_i_unit: The default I unit used by Sasview312 """311 """ 312 convert_q = True 313 313 new_output = [] 314 314 for data in self.output: … … 316 316 new_output.append(data) 317 317 continue 318 file_x_unit = data._xunit 319 data_conv_x = Converter(file_x_unit) 320 file_y_unit = data._yunit 321 data_conv_y = Converter(file_y_unit) 322 if isinstance(data, Data1D): 323 try: 324 data.x = data_conv_x(data.x, units=default_q_unit) 325 data._xunit = default_q_unit 326 data.x_unit = default_q_unit 327 if data.dx is not None: 328 data.dx = data_conv_x(data.dx, units=default_q_unit) 329 if data.dxl is not None: 330 data.dxl = data_conv_x(data.dxl, units=default_q_unit) 331 if data.dxw is not None: 332 data.dxw = data_conv_x(data.dxw, units=default_q_unit) 333 except KeyError: 334 message = "Unable to convert Q units from {0} to 1/A." 335 message.format(default_q_unit) 336 data.errors.append(message) 337 try: 338 data.y = data_conv_y(data.y, units=default_i_unit) 339 data._yunit = default_i_unit 340 data.y_unit = default_i_unit 341 if data.dy is not None: 342 data.dy = data_conv_y(data.dy, units=default_i_unit) 343 except KeyError: 344 message = "Unable to convert I units from {0} to 1/cm." 345 message.format(default_q_unit) 346 data.errors.append(message) 347 elif isinstance(data, Data2D): 348 try: 349 data.qx_data = data_conv_x(data.qx_data, 350 units=default_q_unit) 351 if data.dqx_data is not None: 352 data.dqx_data = data_conv_x(data.dqx_data, 353 units=default_q_unit) 354 data.qy_data = data_conv_y(data.qy_data, 355 units=default_q_unit) 356 if data.dqy_data is not None: 357 data.dqy_data = data_conv_y(data.dqy_data, 358 units=default_q_unit) 359 except KeyError: 360 message = "Unable to convert Q units from {0} to 1/A." 361 message.format(default_q_unit) 362 data.errors.append(message) 363 try: 364 file_z_unit = data._zunit 365 data_conv_z = Converter(file_z_unit) 366 data.data = data_conv_z(data.data, units=default_i_unit) 367 if data.err_data is not None: 368 data.err_data = data_conv_z(data.err_data, 369 units=default_i_unit) 370 except KeyError: 371 message = "Unable to convert I units from {0} to 1/cm." 372 message.format(default_q_unit) 373 data.errors.append(message) 374 else: 375 # TODO: Throw error of some sort... 376 pass 318 try: 319 file_x_unit = data._xunit 320 data_conv_x = Converter(file_x_unit) 321 except KeyError: 322 logger.info("Unrecognized Q units in data file. No data " 323 "conversion attempted") 324 convert_q = False 325 try: 326 327 if isinstance(data, Data1D): 328 if convert_q: 329 data.x = data_conv_x(data.x, units=default_q_unit) 330 data._xunit = default_q_unit 331 data.x_unit = default_q_unit 332 if data.dx is not None: 333 data.dx = data_conv_x(data.dx, 334 units=default_q_unit) 335 if data.dxl is not None: 336 data.dxl = data_conv_x(data.dxl, 337 units=default_q_unit) 338 if data.dxw is not None: 339 data.dxw = data_conv_x(data.dxw, 340 units=default_q_unit) 341 elif isinstance(data, Data2D): 342 if convert_q: 343 data.qx_data = data_conv_x(data.qx_data, 344 units=default_q_unit) 345 if data.dqx_data is not None: 346 data.dqx_data = data_conv_x(data.dqx_data, 347 units=default_q_unit) 348 try: 349 file_y_unit = data._yunit 350 data_conv_y = Converter(file_y_unit) 351 data.qy_data = data_conv_y(data.qy_data, 352 units=default_q_unit) 353 if data.dqy_data is not None: 354 data.dqy_data = data_conv_y(data.dqy_data, 355 units=default_q_unit) 356 except KeyError: 357 logger.info("Unrecognized Qy units in data file. No" 358 " data conversion attempted") 359 except KeyError: 360 message = "Unable to convert Q units from {0} to 1/A." 361 message.format(default_q_unit) 362 data.errors.add(message) 377 363 new_output.append(data) 378 364 self.output = new_output -
src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py
rb204004 rdfcdbf8 172 172 # Top Level Meta Data 173 173 if key == u'definition': 174 self.current_datainfo.meta_data['reader'] = data_point 174 self.current_datainfo.meta_data['reader'] = data_set 175 break 175 176 # Run 176 177 elif key == u'run': 177 self.current_datainfo.run.append(data_ point)178 self.current_datainfo.run.append(data_set) 178 179 try: 179 180 run_name = h5attr(value, 'name') 180 run_dict = {data_ point: run_name}181 run_dict = {data_set: run_name} 181 182 self.current_datainfo.run_name = run_dict 182 183 except Exception: 183 184 pass 185 break 184 186 # Title 185 187 elif key == u'title': 186 self.current_datainfo.title = data_ point188 self.current_datainfo.title = data_set 187 189 # Note 188 190 elif key == u'SASnote': 189 self.current_datainfo.notes.append(data_point) 191 self.current_datainfo.notes.append(data_set) 192 break 190 193 # Sample Information 191 194 elif self.parent_class == u'SASsample': … … 619 622 raise TypeError 620 623 except TypeError: 621 iterable = iterable.split(",") 624 if isinstance(iterable, basestring): 625 iterable = iterable.split(",") 626 else: 627 iterable = [iterable] 622 628 return iterable 623 629
Note: See TracChangeset
for help on using the changeset viewer.