Ignore:
Timestamp:
Jul 6, 2018 12:23:21 PM (6 years ago)
Author:
krzywon
Branches:
master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, unittest-saveload
Children:
eb6abab
Parents:
058f6c3
Message:

Changes to NXcanSAS reader to comply with specification. refs #976

File:
1 edited

Legend:

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

    r3bab401 r8f882fe  
    137137            if isinstance(value, h5py.Group): 
    138138                # Set parent class before recursion 
     139                last_parent_class = self.parent_class 
    139140                self.parent_class = class_name 
    140141                parent_list.append(key) 
     
    144145                    self.add_data_set(key) 
    145146                elif class_prog.match(u'SASdata'): 
     147                    self._initialize_new_data_set(value) 
    146148                    self._find_data_attributes(value) 
    147                     self._initialize_new_data_set(parent_list) 
    148149                # Recursion step to access data within the group 
    149150                self.read_children(value, parent_list) 
     151                self.add_intermediate() 
    150152                # Reset parent class when returning from recursive method 
    151                 self.parent_class = class_name 
    152                 self.add_intermediate() 
     153                self.parent_class = last_parent_class 
    153154                parent_list.remove(key) 
    154155 
     
    533534        self.current_datainfo = DataInfo() 
    534535 
    535     def _initialize_new_data_set(self, parent_list=None): 
     536    def _initialize_new_data_set(self, value=None): 
    536537        """ 
    537538        A private class method to generate a new 1D or 2D data object based on 
     
    541542        :param parent_list: List of names of parent elements 
    542543        """ 
    543  
    544         if parent_list is None: 
    545             parent_list = [] 
    546         if self._find_intermediate(parent_list, "Qx"): 
     544        if self._is2d(value): 
    547545            self.current_dataset = plottable_2D() 
    548546        else: 
     
    565563        :param value: SASdata/NXdata HDF5 Group 
    566564        """ 
     565        signal = "I" 
     566        i_axes = ["Q"] 
     567        q_indices = [0] 
    567568        attrs = value.attrs 
    568         signal = attrs.get("signal") 
    569         i_axes = np.array(str(attrs.get("I_axes")).split(",")) 
    570         q_indices = np.int_(attrs.get("Q_indices").split(",")) 
     569        if hasattr(attrs, "signal"): 
     570            signal = attrs.get("signal") 
     571        if hasattr(attrs, "I_axes"): 
     572            i_axes = np.array(str(attrs.get("I_axes")).split(",")) 
     573        if hasattr(attrs, "Q_indices"): 
     574            q_indices = np.int_(attrs.get("Q_indices").split(",")) 
    571575        keys = value.keys() 
    572576        self.mask_name = attrs.get("mask") 
     
    578582            if item in keys: 
    579583                q_vals = value.get(item) 
    580                 self.q_uncertainties = q_vals.attrs.get("uncertainty") 
    581                 self.q_resolutions = q_vals.attrs.get("resolution") 
     584                self.q_uncertainties = q_vals.attrs.get("uncertainties") 
     585                if self.q_uncertainties is None: 
     586                    self.q_uncertainties = q_vals.attrs.get("uncertainty") 
     587                self.q_resolutions = q_vals.attrs.get("resolutions") 
    582588        if self.i_name in keys: 
    583589            i_vals = value.get(self.i_name) 
    584             self.i_uncertainties = i_vals.attrs.get("uncertainty") 
    585  
    586     def _find_intermediate(self, parent_list, basename=""): 
    587         """ 
    588         A private class used to find an entry by either using a direct key or 
    589         knowing the approximate basename. 
     590            self.i_uncertainties = i_vals.attrs.get("uncertainties") 
     591            if self.i_uncertainties is None: 
     592                self.i_uncertainties = i_vals.attrs.get("uncertainty") 
     593 
     594    def _is2d(self, value, basename="I"): 
     595        """ 
     596        A private class to determine if the data set is 1d or 2d. 
    590597 
    591598        :param parent_list: List of parents nodes in the HDF5 file 
    592599        :param basename: Approximate name of an entry to search for 
    593         :return: 
    594         """ 
    595  
    596         entry = False 
    597         key_prog = re.compile(basename) 
    598         top = self.raw_data 
    599         for parent in parent_list: 
    600             top = top.get(parent) 
    601         for key in top.keys(): 
    602             if key_prog.match(key): 
    603                 entry = True 
    604                 break 
    605         return entry 
     600        :return: True if 2D, otherwise false 
     601        """ 
     602 
     603        vals = value.get(basename) 
     604        return (vals is not None and vals.shape is not None 
     605                and len(vals.shape) != 1) 
    606606 
    607607    def _create_unique_key(self, dictionary, name, numb=0): 
Note: See TracChangeset for help on using the changeset viewer.