Ignore:
Timestamp:
Jul 27, 2017 11:08:18 AM (7 years ago)
Author:
lewis
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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
8dec7e7
Parents:
0b79323
Message:

Refactor NXcanSAS reader to use FileReader? class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py

    r7f75a3f r9d786e5  
    1414from sas.sascalc.dataloader.data_info import combine_data_info_with_plottable 
    1515from sas.sascalc.dataloader.loader_exceptions import FileContentsException 
    16  
    17  
    18 class Reader(): 
     16from sas.sascalc.dataloader.file_reader_base_class import FileReader 
     17 
     18 
     19class Reader(FileReader): 
    1920    """ 
    2021    A class for reading in CanSAS v2.0 data files. The existing iteration opens 
     
    4142    # Raw file contents to be processed 
    4243    raw_data = None 
    43     # Data info currently being read in 
    44     current_datainfo = None 
    45     # SASdata set currently being read in 
    46     current_dataset = None 
    4744    # List of plottable1D objects that should be linked to the current_datainfo 
    4845    data1d = None 
     
    5754    # Flag to bypass extension check 
    5855    allow_all = True 
    59     # List of files to return 
    60     output = None 
    61  
    62     def read(self, filename): 
     56 
     57    def get_file_contents(self): 
    6358        """ 
    6459        This is the general read method that all SasView data_loaders must have. 
     
    6964        # Reinitialize when loading a new data file to reset all class variables 
    7065        self.reset_class_variables() 
     66 
     67        filename = self.f_open.name 
     68        self.f_open.close() # IO handled by h5py 
     69 
    7170        # Check that the file exists 
    7271        if os.path.isfile(filename): 
     
    431430        Data1D and Data2D objects 
    432431        """ 
    433  
    434432        # Type cast data arrays to float64 
    435433        if len(self.current_datainfo.trans_spectrum) > 0: 
     
    455453        # Type cast data arrays to float64 and find min/max as appropriate 
    456454        for dataset in self.data2d: 
    457             dataset.data = dataset.data.astype(np.float64) 
    458             dataset.err_data = dataset.err_data.astype(np.float64) 
    459             if dataset.qx_data is not None: 
    460                 dataset.xmin = np.min(dataset.qx_data) 
    461                 dataset.xmax = np.max(dataset.qx_data) 
    462                 dataset.qx_data = dataset.qx_data.astype(np.float64) 
    463             if dataset.dqx_data is not None: 
    464                 dataset.dqx_data = dataset.dqx_data.astype(np.float64) 
    465             if dataset.qy_data is not None: 
    466                 dataset.ymin = np.min(dataset.qy_data) 
    467                 dataset.ymax = np.max(dataset.qy_data) 
    468                 dataset.qy_data = dataset.qy_data.astype(np.float64) 
    469             if dataset.dqy_data is not None: 
    470                 dataset.dqy_data = dataset.dqy_data.astype(np.float64) 
    471             if dataset.q_data is not None: 
    472                 dataset.q_data = dataset.q_data.astype(np.float64) 
    473455            zeros = np.ones(dataset.data.size, dtype=bool) 
    474456            try: 
     
    493475                dataset.x_bins = dataset.qx_data[:n_cols] 
    494476                dataset.data = dataset.data.flatten() 
    495  
    496             final_dataset = combine_data_info_with_plottable( 
    497                 dataset, self.current_datainfo) 
    498             self.output.append(final_dataset) 
     477            self.current_dataset = dataset 
     478            self.send_to_output() 
    499479 
    500480        for dataset in self.data1d: 
    501             if dataset.x is not None: 
    502                 dataset.x = dataset.x.astype(np.float64) 
    503                 dataset.xmin = np.min(dataset.x) 
    504                 dataset.xmax = np.max(dataset.x) 
    505             if dataset.y is not None: 
    506                 dataset.y = dataset.y.astype(np.float64) 
    507                 dataset.ymin = np.min(dataset.y) 
    508                 dataset.ymax = np.max(dataset.y) 
    509             if dataset.dx is not None: 
    510                 dataset.dx = dataset.dx.astype(np.float64) 
    511             if dataset.dxl is not None: 
    512                 dataset.dxl = dataset.dxl.astype(np.float64) 
    513             if dataset.dxw is not None: 
    514                 dataset.dxw = dataset.dxw.astype(np.float64) 
    515             if dataset.dy is not None: 
    516                 dataset.dy = dataset.dy.astype(np.float64) 
    517             final_dataset = combine_data_info_with_plottable( 
    518                 dataset, self.current_datainfo) 
    519             self.output.append(final_dataset) 
     481            self.current_dataset = dataset 
     482            self.send_to_output() 
    520483 
    521484    def add_data_set(self, key=""): 
Note: See TracChangeset for help on using the changeset viewer.