Changeset cd57c7d4 in sasview for src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py
- Timestamp:
- Sep 11, 2017 10:12:16 AM (7 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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- b1f20d1
- Parents:
- c9ecd1b (diff), e2b2473 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py
rc9ecd1b rcd57c7d4 13 13 TransmissionSpectrum, Detector 14 14 from sas.sascalc.dataloader.data_info import combine_data_info_with_plottable 15 16 17 class Reader(): 15 from sas.sascalc.dataloader.loader_exceptions import FileContentsException, DefaultReaderException 16 from sas.sascalc.dataloader.file_reader_base_class import FileReader 17 18 19 class Reader(FileReader): 18 20 """ 19 21 A class for reading in CanSAS v2.0 data files. The existing iteration opens … … 40 42 # Raw file contents to be processed 41 43 raw_data = None 42 # Data info currently being read in43 current_datainfo = None44 # SASdata set currently being read in45 current_dataset = None46 44 # List of plottable1D objects that should be linked to the current_datainfo 47 45 data1d = None … … 56 54 # Flag to bypass extension check 57 55 allow_all = True 58 # List of files to return 59 output = None 60 61 def read(self, filename): 56 57 def get_file_contents(self): 62 58 """ 63 59 This is the general read method that all SasView data_loaders must have. … … 68 64 # Reinitialize when loading a new data file to reset all class variables 69 65 self.reset_class_variables() 66 67 filename = self.f_open.name 68 self.f_open.close() # IO handled by h5py 69 70 70 # Check that the file exists 71 71 if os.path.isfile(filename): … … 75 75 if extension in self.ext or self.allow_all: 76 76 # Load the data file 77 self.raw_data = h5py.File(filename, 'r') 78 # Read in all child elements of top level SASroot 79 self.read_children(self.raw_data, []) 80 # Add the last data set to the list of outputs 81 self.add_data_set() 82 # Close the data file 83 self.raw_data.close() 84 # Return data set(s) 85 return self.output 77 try: 78 self.raw_data = h5py.File(filename, 'r') 79 except Exception as e: 80 if extension not in self.ext: 81 msg = "CanSAS2.0 HDF5 Reader could not load file {}".format(basename + extension) 82 raise DefaultReaderException(msg) 83 raise FileContentsException(e.message) 84 try: 85 # Read in all child elements of top level SASroot 86 self.read_children(self.raw_data, []) 87 # Add the last data set to the list of outputs 88 self.add_data_set() 89 except Exception as exc: 90 raise FileContentsException(exc.message) 91 finally: 92 # Close the data file 93 self.raw_data.close() 94 95 for dataset in self.output: 96 if isinstance(dataset, Data1D): 97 if dataset.x.size < 5: 98 self.output = [] 99 raise FileContentsException("Fewer than 5 data points found.") 86 100 87 101 def reset_class_variables(self): … … 430 444 Data1D and Data2D objects 431 445 """ 432 433 446 # Type cast data arrays to float64 434 447 if len(self.current_datainfo.trans_spectrum) > 0: … … 454 467 # Type cast data arrays to float64 and find min/max as appropriate 455 468 for dataset in self.data2d: 456 dataset.data = dataset.data.astype(np.float64)457 dataset.err_data = dataset.err_data.astype(np.float64)458 if dataset.qx_data is not None:459 dataset.xmin = np.min(dataset.qx_data)460 dataset.xmax = np.max(dataset.qx_data)461 dataset.qx_data = dataset.qx_data.astype(np.float64)462 if dataset.dqx_data is not None:463 dataset.dqx_data = dataset.dqx_data.astype(np.float64)464 if dataset.qy_data is not None:465 dataset.ymin = np.min(dataset.qy_data)466 dataset.ymax = np.max(dataset.qy_data)467 dataset.qy_data = dataset.qy_data.astype(np.float64)468 if dataset.dqy_data is not None:469 dataset.dqy_data = dataset.dqy_data.astype(np.float64)470 if dataset.q_data is not None:471 dataset.q_data = dataset.q_data.astype(np.float64)472 469 zeros = np.ones(dataset.data.size, dtype=bool) 473 470 try: … … 492 489 dataset.x_bins = dataset.qx_data[:n_cols] 493 490 dataset.data = dataset.data.flatten() 494 495 final_dataset = combine_data_info_with_plottable( 496 dataset, self.current_datainfo) 497 self.output.append(final_dataset) 491 self.current_dataset = dataset 492 self.send_to_output() 498 493 499 494 for dataset in self.data1d: 500 if dataset.x is not None: 501 dataset.x = dataset.x.astype(np.float64) 502 dataset.xmin = np.min(dataset.x) 503 dataset.xmax = np.max(dataset.x) 504 if dataset.y is not None: 505 dataset.y = dataset.y.astype(np.float64) 506 dataset.ymin = np.min(dataset.y) 507 dataset.ymax = np.max(dataset.y) 508 if dataset.dx is not None: 509 dataset.dx = dataset.dx.astype(np.float64) 510 if dataset.dxl is not None: 511 dataset.dxl = dataset.dxl.astype(np.float64) 512 if dataset.dxw is not None: 513 dataset.dxw = dataset.dxw.astype(np.float64) 514 if dataset.dy is not None: 515 dataset.dy = dataset.dy.astype(np.float64) 516 final_dataset = combine_data_info_with_plottable( 517 dataset, self.current_datainfo) 518 self.output.append(final_dataset) 495 self.current_dataset = dataset 496 self.send_to_output() 519 497 520 498 def add_data_set(self, key=""):
Note: See TracChangeset
for help on using the changeset viewer.