Changeset 802fc18 in sasview


Ignore:
Timestamp:
Nov 15, 2018 12:08:56 PM (6 years ago)
Author:
Jeff Krzywon <jkrzywon@…>
Branches:
master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249
Children:
a165bee
Parents:
c1dc994
Message:

Support for multi-frame NXcanSAS data sets.

File:
1 edited

Legend:

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

    rc1dc994 r802fc18  
    11""" 
    2     CanSAS 2D data reader for reading HDF5 formatted CanSAS files. 
     2    NXcanSAS data reader for reading HDF5 formatted CanSAS files. 
    33""" 
    44 
     
    2222class Reader(FileReader): 
    2323    """ 
    24     A class for reading in CanSAS v2.0 data files. The existing iteration opens 
    25     Mantid generated HDF5 formatted files with file extension .h5/.H5. Any 
    26     number of data sets may be present within the file and any dimensionality 
    27     of data may be used. Currently 1D and 2D SAS data sets are supported, but 
    28     future implementations will include 1D and 2D SESANS data. 
    29  
    30     Any number of SASdata sets may be present in a SASentry and the data within 
    31     can be either 1D I(Q) or 2D I(Qx, Qy). 
    32  
    33     Also supports reading NXcanSAS formatted HDF5 files 
     24    A class for reading in NXcanSAS data files. The current implementation has 
     25    been tested to load data generated by multiple facilities, all of which are 
     26    known to produce NXcanSAS standards compliant data. Any number of data sets 
     27    may be present within the file and any dimensionality of data may be used. 
     28    Currently 1D and 2D SAS data sets are supported, but should be immediately 
     29    extensible to SESANS data. 
     30 
     31    Any number of SASdata groups  may be present in a SASentry and the data 
     32    within each SASdata group can be a single 1D I(Q), multi-framed 1D I(Q), 
     33    2D I(Qx, Qy) or multi-framed 2D I(Qx, Qy). 
    3434 
    3535    :Dependencies: 
    36         The CanSAS HDF5 reader requires h5py => v2.5.0 or later. 
     36        The NXcanSAS HDF5 reader requires h5py => v2.5.0 or later. 
    3737    """ 
    3838 
     
    102102        self.data2d = [] 
    103103        self.raw_data = None 
     104        self.multi_frame = False 
     105        self.data_frames = [] 
     106        self.data_uncertainty_frames = [] 
    104107        self.errors = [] 
    105108        self.logging = [] 
     
    150153                    self.add_data_set(key) 
    151154                elif class_prog.match(u'SASdata'): 
     155                    self._find_data_attributes(value) 
    152156                    self._initialize_new_data_set(value) 
    153                     self._find_data_attributes(value) 
    154157                # Recursion step to access data within the group 
    155158                self.read_children(value, parent_list) 
     
    252255        """ 
    253256        if key == self.i_name: 
    254             self.current_dataset.y = data_set.flatten() 
    255             self.current_dataset.yaxis("Intensity", unit) 
     257            if self.multi_frame: 
     258                for x in range(0, data_set.shape[0]): 
     259                    self.data_frames.append(data_set[x].flatten()) 
     260            else: 
     261                self.current_dataset.y = data_set.flatten() 
     262                self.current_dataset.yaxis("Intensity", unit) 
    256263        elif key == self.i_uncertainties_name: 
     264            if self.multi_frame: 
     265                for x in range(0, data_set.shape[0]): 
     266                    self.data_uncertainty_frames.append(data_set[x].flatten()) 
    257267            self.current_dataset.dy = data_set.flatten() 
    258268        elif key in self.q_names: 
     
    517527                self.data2d.append(self.current_dataset) 
    518528            elif isinstance(self.current_dataset, plottable_1D): 
    519                 self.data1d.append(self.current_dataset) 
     529                if self.multi_frame: 
     530                    for x in range(0, len(self.data_frames) - 1): 
     531                        self.current_dataset.y = self.data_frames[x] 
     532                        if len(self.data_uncertainty_frames) > x: 
     533                            self.current_dataset.dy = \ 
     534                                self.data_uncertainty_frames[x] 
     535                        self.data1d.append(self.current_dataset) 
     536                else: 
     537                    self.data1d.append(self.current_dataset) 
    520538 
    521539    def final_data_cleanup(self): 
     
    598616        if self.current_datainfo and self.current_dataset: 
    599617            self.final_data_cleanup() 
     618        self.data_frames = [] 
     619        self.data_uncertainty_frames = [] 
    600620        self.data1d = [] 
    601621        self.data2d = [] 
     
    617637            self.current_dataset = plottable_1D(x, y) 
    618638        self.current_datainfo.filename = self.raw_data.filename 
    619         self.mask_name = u'' 
    620         self.i_name = u'' 
    621         self.i_node = u'' 
    622         self.i_uncertainties_name = u'' 
    623         self.q_names = [] 
    624         self.q_uncertainty_names = [] 
    625         self.q_resolution_names = [] 
    626639 
    627640    @staticmethod 
     
    645658        :param value: SASdata/NXdata HDF5 Group 
    646659        """ 
     660        # Initialize values to base types 
     661        self.mask_name = u'' 
     662        self.i_name = u'' 
     663        self.i_node = u'' 
     664        self.i_uncertainties_name = u'' 
     665        self.q_names = [] 
     666        self.q_uncertainty_names = [] 
     667        self.q_resolution_names = [] 
     668        # Get attributes 
    647669        attrs = value.attrs 
    648670        signal = attrs.get("signal", "I") 
     
    652674        i_axes = self.check_is_list_or_array(i_axes) 
    653675        keys = value.keys() 
     676        # Assign attributes to appropriate class variables 
    654677        self.mask_name = attrs.get("mask") 
    655678        for val in q_indices: 
     
    676699                self.i_uncertainties_name = i_vals.attrs.get("uncertainty") 
    677700 
    678     def _is2d(self, value, basename="I"): 
     701    def _is2d(self, value, i_base="", q_base=[]): 
    679702        """ 
    680703        A private class to determine if the data set is 1d or 2d. 
    681704 
    682         :param parent_list: List of parents nodes in the HDF5 file 
     705        :param value: Nexus/NXcanSAS data group 
    683706        :param basename: Approximate name of an entry to search for 
    684707        :return: True if 2D, otherwise false 
    685708        """ 
    686  
    687         vals = value.get(basename) 
    688         return (vals is not None and vals.shape is not None 
    689                 and len(vals.shape) != 1) 
     709        i_basename = i_base if i_base != "" else self.i_name 
     710        i_vals = value.get(i_basename) 
     711        q_basename = q_base if q_base != [] else self.q_names 
     712        q_vals = value.get(q_basename[0]) 
     713        self.multi_frame = True if (i_vals is not None and q_vals is not None 
     714                                    and len(i_vals.shape) != 1 
     715                                    and len(q_vals.shape) == 1) else False 
     716        return (i_vals is not None and i_vals.shape is not None 
     717                and len(i_vals.shape) != 1 and not self.multi_frame) 
    690718 
    691719    def _create_unique_key(self, dictionary, name, numb=0): 
Note: See TracChangeset for help on using the changeset viewer.