Changeset b8080e1 in sasview for src/sas/sascalc/dataloader


Ignore:
Timestamp:
Aug 29, 2018 10:01:23 AM (6 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
9463ca2
Parents:
ce30949
git-author:
Piotr Rozyczko <rozyczko@…> (08/29/18 09:59:56)
git-committer:
Piotr Rozyczko <rozyczko@…> (08/29/18 10:01:23)
Message:

cherry picking sascalc changes from master SASVIEW-996
minor unit test fixes

Location:
src/sas/sascalc/dataloader
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/data_info.py

    r749b715 rb8080e1  
    775775        clone.meta_data = deepcopy(self.meta_data) 
    776776        clone.errors = deepcopy(self.errors) 
    777         clone.isSesans = self.isSesans 
    778777 
    779778        return clone 
  • src/sas/sascalc/dataloader/file_reader_base_class.py

    r9e6aeaf rb8080e1  
    77import os 
    88import sys 
    9 import re 
     9import math 
    1010import logging 
    1111from abc import abstractmethod 
     
    2626        return s.decode() if isinstance(s, bytes) else s 
    2727 
     28# Data 1D fields for iterative purposes 
     29FIELDS_1D = ('x', 'y', 'dx', 'dy', 'dxl', 'dxw') 
     30# Data 2D fields for iterative purposes 
     31FIELDS_2D = ('data', 'qx_data', 'qy_data', 'q_data', 'err_data', 
     32                 'dqx_data', 'dqy_data', 'mask') 
     33DEPRECATION_MESSAGE = ("\rThe extension of this file suggests the data set migh" 
     34                       "t not be fully reduced. Support for the reader associat" 
     35                       "ed with this file type has been removed. An attempt to " 
     36                       "load the file was made, but, should it be successful, " 
     37                       "SasView cannot guarantee the accuracy of the data.") 
     38 
    2839class FileReader(object): 
    29     # List of Data1D and Data2D objects to be sent back to data_loader 
    30     output = [] 
    31     # Current plottable_(1D/2D) object being loaded in 
    32     current_dataset = None 
    33     # Current DataInfo object being loaded in 
    34     current_datainfo = None 
    3540    # String to describe the type of data this reader can load 
    3641    type_name = "ASCII" 
     
    3944    # List of allowed extensions 
    4045    ext = ['.txt'] 
     46    # Deprecated extensions 
     47    deprecated_extensions = ['.asc', '.nxs'] 
    4148    # Bypass extension check and try to load anyway 
    4249    allow_all = False 
    4350    # Able to import the unit converter 
    4451    has_converter = True 
    45     # Open file handle 
    46     f_open = None 
    4752    # Default value of zero 
    4853    _ZERO = 1e-16 
    4954 
     55    def __init__(self): 
     56        # List of Data1D and Data2D objects to be sent back to data_loader 
     57        self.output = [] 
     58        # Current plottable_(1D/2D) object being loaded in 
     59        self.current_dataset = None 
     60        # Current DataInfo object being loaded in 
     61        self.current_datainfo = None 
     62        # File path sent to reader 
     63        self.filepath = None 
     64        # Open file handle 
     65        self.f_open = None 
     66 
    5067    def read(self, filepath): 
    5168        """ 
     
    5471        :param filepath: The full or relative path to a file to be loaded 
    5572        """ 
     73        self.filepath = filepath 
    5674        if os.path.isfile(filepath): 
    5775            basename, extension = os.path.splitext(os.path.basename(filepath)) 
     
    7593                    if not self.f_open.closed: 
    7694                        self.f_open.close() 
     95                    if any(filepath.lower().endswith(ext) for ext in 
     96                           self.deprecated_extensions): 
     97                        self.handle_error_message(DEPRECATION_MESSAGE) 
    7798                    if len(self.output) > 0: 
    7899                        # Sort the data that's been loaded 
     
    85106 
    86107        # Return a list of parsed entries that data_loader can manage 
    87         return self.output 
     108        final_data = self.output 
     109        self.reset_state() 
     110        return final_data 
     111 
     112    def reset_state(self): 
     113        """ 
     114        Resets the class state to a base case when loading a new data file so previous 
     115        data files do not appear a second time 
     116        """ 
     117        self.current_datainfo = None 
     118        self.current_dataset = None 
     119        self.filepath = None 
     120        self.ind = None 
     121        self.output = [] 
    88122 
    89123    def nextline(self): 
     
    112146        """ 
    113147        Generic error handler to add an error to the current datainfo to 
    114         propogate the error up the error chain. 
     148        propagate the error up the error chain. 
    115149        :param msg: Error message 
    116150        """ 
     
    121155        else: 
    122156            logger.warning(msg) 
     157            raise NoKnownLoaderException(msg) 
    123158 
    124159    def send_to_output(self): 
     
    142177                # Sort data by increasing x and remove 1st point 
    143178                ind = np.lexsort((data.y, data.x)) 
    144                 data.x = np.asarray([data.x[i] for i in ind]).astype(np.float64) 
    145                 data.y = np.asarray([data.y[i] for i in ind]).astype(np.float64) 
     179                data.x = self._reorder_1d_array(data.x, ind) 
     180                data.y = self._reorder_1d_array(data.y, ind) 
    146181                if data.dx is not None: 
    147182                    if len(data.dx) == 0: 
    148183                        data.dx = None 
    149184                        continue 
    150                     data.dx = np.asarray([data.dx[i] for i in ind]).astype(np.float64) 
     185                    data.dx = self._reorder_1d_array(data.dx, ind) 
    151186                if data.dxl is not None: 
    152                     data.dxl = np.asarray([data.dxl[i] for i in ind]).astype(np.float64) 
     187                    data.dxl = self._reorder_1d_array(data.dxl, ind) 
    153188                if data.dxw is not None: 
    154                     data.dxw = np.asarray([data.dxw[i] for i in ind]).astype(np.float64) 
     189                    data.dxw = self._reorder_1d_array(data.dxw, ind) 
    155190                if data.dy is not None: 
    156191                    if len(data.dy) == 0: 
    157192                        data.dy = None 
    158193                        continue 
    159                     data.dy = np.asarray([data.dy[i] for i in ind]).astype(np.float64) 
     194                    data.dy = self._reorder_1d_array(data.dy, ind) 
    160195                if data.lam is not None: 
    161                     data.lam = np.asarray([data.lam[i] for i in ind]).astype(np.float64) 
     196                    data.lam = self._reorder_1d_array(data.lam, ind) 
    162197                if data.dlam is not None: 
    163                     data.dlam = np.asarray([data.dlam[i] for i in ind]).astype(np.float64) 
     198                    data.dlam = self._reorder_1d_array(data.dlam, ind) 
     199                data = self._remove_nans_in_data(data) 
    164200                if len(data.x) > 0: 
    165201                    data.xmin = np.min(data.x) 
     
    167203                    data.ymin = np.min(data.y) 
    168204                    data.ymax = np.max(data.y) 
     205 
     206    @staticmethod 
     207    def _reorder_1d_array(array, ind): 
     208        """ 
     209        Reorders a 1D array based on the indices passed as ind 
     210        :param array: Array to be reordered 
     211        :param ind: Indices used to reorder array 
     212        :return: reordered array 
     213        """ 
     214        array = np.asarray(array, dtype=np.float64) 
     215        return array[ind] 
     216 
     217    @staticmethod 
     218    def _remove_nans_in_data(data): 
     219        """ 
     220        Remove data points where nan is loaded 
     221        :param data: 1D or 2D data object 
     222        :return: data with nan points removed 
     223        """ 
     224        if isinstance(data, Data1D): 
     225            fields = FIELDS_1D 
     226        elif isinstance(data, Data2D): 
     227            fields = FIELDS_2D 
     228        else: 
     229            return data 
     230        # Make array of good points - all others will be removed 
     231        good = np.isfinite(getattr(data, fields[0])) 
     232        for name in fields[1:]: 
     233            array = getattr(data, name) 
     234            if array is not None: 
     235                # Update good points only if not already changed 
     236                good &= np.isfinite(array) 
     237        if not np.all(good): 
     238            for name in fields: 
     239                array = getattr(data, name) 
     240                if array is not None: 
     241                    setattr(data, name, array[good]) 
     242        return data 
    169243 
    170244    def sort_two_d_data(self): 
     
    197271                    dataset.x_bins = dataset.qx_data[:int(n_cols)] 
    198272                dataset.data = dataset.data.flatten() 
     273                dataset = self._remove_nans_in_data(dataset) 
    199274                if len(dataset.data) > 0: 
    200275                    dataset.xmin = np.min(dataset.qx_data) 
     
    314389    def splitline(line): 
    315390        """ 
    316         Splits a line into pieces based on common delimeters 
     391        Splits a line into pieces based on common delimiters 
    317392        :param line: A single line of text 
    318393        :return: list of values 
  • src/sas/sascalc/dataloader/loader.py

    rdc8d1c2 rb8080e1  
    9090            ascii_loader = ascii_reader.Reader() 
    9191            return ascii_loader.read(path) 
     92        except NoKnownLoaderException: 
     93            pass  # Try the Cansas XML reader 
    9294        except DefaultReaderException: 
    9395            pass  # Loader specific error to try the cansas XML reader 
     
    100102            cansas_loader = cansas_reader.Reader() 
    101103            return cansas_loader.read(path) 
     104        except NoKnownLoaderException: 
     105            pass  # Try the NXcanSAS reader 
    102106        except DefaultReaderException: 
    103107            pass  # Loader specific error to try the NXcanSAS reader 
  • src/sas/sascalc/dataloader/readers/abs_reader.py

    r1efbc190 rb8080e1  
    2929    type_name = "IGOR 1D" 
    3030    # Wildcards 
    31     type = ["IGOR 1D files (*.abs)|*.abs"] 
     31    type = ["IGOR 1D files (*.abs)|*.abs", "IGOR 1D USANS files (*.cor)|*.cor"] 
    3232    # List of allowed extensions 
    33     ext = ['.abs'] 
     33    ext = ['.abs', '.cor'] 
    3434 
    3535    def get_file_contents(self): 
     
    4646        self.current_datainfo = DataInfo() 
    4747        self.current_datainfo.filename = filepath 
    48         self.reset_data_list(len(lines)) 
    4948        detector = Detector() 
    5049        data_line = 0 
     
    172171 
    173172                try: 
    174                     _x = float(toks[0]) 
     173                    _x = float(toks[4]) 
    175174                    _y = float(toks[1]) 
    176175                    _dy = float(toks[2]) 
     
    188187                    self.current_dataset.y[data_line] = _y 
    189188                    self.current_dataset.dy[data_line] = _dy 
    190                     self.current_dataset.dx[data_line] = _dx 
     189                    if _dx > 0: 
     190                        self.current_dataset.dx[data_line] = _dx 
     191                    else: 
     192                        if data_line == 0: 
     193                            self.current_dataset.dx = None 
     194                            self.current_dataset.dxl = np.zeros(len(lines)) 
     195                            self.current_dataset.dxw = np.zeros(len(lines)) 
     196                        self.current_dataset.dxl[data_line] = abs(_dx) 
     197                        self.current_dataset.dxw[data_line] = 0 
    191198                    data_line += 1 
    192199 
     
    197204                    pass 
    198205 
     206            # SANS Data: 
    199207            # The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. 
    200208            # I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor| 
    201             if line.count("The 6 columns") > 0: 
     209            # USANS Data: 
     210            # EMP LEVEL: <value> ; BKG LEVEL: <value> 
     211            if line.startswith("The 6 columns") or line.startswith("EMP LEVEL"): 
    202212                is_data_started = True 
    203213 
  • src/sas/sascalc/dataloader/readers/associations.py

    r574adc7 rb8080e1  
    2626    ".dat": "red2d_reader", 
    2727    ".abs": "abs_reader", 
     28    ".cor": "abs_reader", 
    2829    ".sans": "danse_reader", 
    2930    ".pdh": "anton_paar_saxs_reader" 
  • src/sas/sascalc/dataloader/readers/cansas_reader.py

    r2b538cd rb8080e1  
    6868        data files do not appear a second time 
    6969        """ 
    70         self.current_datainfo = None 
    71         self.current_dataset = None 
    72         self.current_data1d = None 
     70        super(Reader, self).reset_state() 
    7371        self.data = [] 
    7472        self.process = Process() 
     
    7977        self.names = [] 
    8078        self.cansas_defaults = {} 
    81         self.output = [] 
    8279        self.ns_list = None 
    8380        self.logging = [] 
     
    8582 
    8683    def read(self, xml_file, schema_path="", invalid=True): 
    87         if schema_path != "" or invalid != True: 
     84        if schema_path != "" or not invalid: 
    8885            # read has been called from self.get_file_contents because xml file doens't conform to schema 
    8986            _, self.extension = os.path.splitext(os.path.basename(xml_file)) 
     
    945942            pos, "z", datainfo.sample.position.z, 
    946943            {"unit": datainfo.sample.position_unit}) 
    947         if written == True: 
     944        if written: 
    948945            self.append(pos, sample) 
    949946 
     
    958955            ori, "yaw", datainfo.sample.orientation.z, 
    959956            {"unit": datainfo.sample.orientation_unit}) 
    960         if written == True: 
     957        if written: 
    961958            self.append(ori, sample) 
    962959 
     
    10051002            size, "z", datainfo.source.beam_size.z, 
    10061003            {"unit": datainfo.source.beam_size_unit}) 
    1007         if written == True: 
     1004        if written: 
    10081005            self.append(size, source) 
    10091006 
     
    10611058                    size, "z", aperture.size.z, 
    10621059                    {"unit": aperture.size_unit}) 
    1063                 if written == True: 
     1060                if written: 
    10641061                    self.append(size, apert) 
    10651062 
     
    10841081            written = written | self.write_node(det, "SDD", item.distance, 
    10851082                                                {"unit": item.distance_unit}) 
    1086             if written == True: 
     1083            if written: 
    10871084                self.append(det, instr) 
    10881085 
     
    10941091            written = written | self.write_node(off, "z", item.offset.z, 
    10951092                                                {"unit": item.offset_unit}) 
    1096             if written == True: 
     1093            if written: 
    10971094                self.append(off, det) 
    10981095 
     
    11061103                                                item.orientation.z, 
    11071104                                                {"unit": item.orientation_unit}) 
    1108             if written == True: 
     1105            if written: 
    11091106                self.append(ori, det) 
    11101107 
     
    11181115                                                item.beam_center.z, 
    11191116                                                {"unit": item.beam_center_unit}) 
    1120             if written == True: 
     1117            if written: 
    11211118                self.append(center, det) 
    11221119 
     
    11281125            written = written | self.write_node(pix, "z", item.pixel_size.z, 
    11291126                                                {"unit": item.pixel_size_unit}) 
    1130             if written == True: 
     1127            if written: 
    11311128                self.append(pix, det) 
    11321129            self.write_node(det, "slit_length", item.slit_length, 
  • src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py

    rc416a17 rb8080e1  
    99import sys 
    1010 
    11 from sas.sascalc.dataloader.data_info import plottable_1D, plottable_2D,\ 
     11from ..data_info import plottable_1D, plottable_2D,\ 
    1212    Data1D, Data2D, DataInfo, Process, Aperture, Collimation, \ 
    1313    TransmissionSpectrum, Detector 
    14 from sas.sascalc.dataloader.data_info import combine_data_info_with_plottable 
    15  
    16  
    17 class Reader(): 
     14from ..data_info import combine_data_info_with_plottable 
     15from ..loader_exceptions import FileContentsException, DefaultReaderException 
     16from ..file_reader_base_class import FileReader, decode 
     17 
     18def h5attr(node, key, default=None): 
     19    return decode(node.attrs.get(key, default)) 
     20 
     21class Reader(FileReader): 
    1822    """ 
    1923    A class for reading in CanSAS v2.0 data files. The existing iteration opens 
     
    2529    Any number of SASdata sets may be present in a SASentry and the data within 
    2630    can be either 1D I(Q) or 2D I(Qx, Qy). 
     31 
    2732    Also supports reading NXcanSAS formatted HDF5 files 
    2833 
     
    3944    # Raw file contents to be processed 
    4045    raw_data = None 
    41     # Data info currently being read in 
    42     current_datainfo = None 
    43     # SASdata set currently being read in 
    44     current_dataset = None 
    4546    # List of plottable1D objects that should be linked to the current_datainfo 
    4647    data1d = None 
     
    5556    # Flag to bypass extension check 
    5657    allow_all = True 
    57     # List of files to return 
    58     output = None 
    59  
    60     def read(self, filename): 
     58 
     59    def get_file_contents(self): 
    6160        """ 
    6261        This is the general read method that all SasView data_loaders must have. 
     
    6665        """ 
    6766        # Reinitialize when loading a new data file to reset all class variables 
    68         self.reset_class_variables() 
     67        self.reset_state() 
     68 
     69        filename = self.f_open.name 
     70        self.f_open.close() # IO handled by h5py 
     71 
    6972        # Check that the file exists 
    7073        if os.path.isfile(filename): 
     
    7477            if extension in self.ext or self.allow_all: 
    7578                # Load the data file 
    76                 self.raw_data = h5py.File(filename, 'r') 
    77                 # Read in all child elements of top level SASroot 
    78                 self.read_children(self.raw_data, []) 
    79                 # Add the last data set to the list of outputs 
    80                 self.add_data_set() 
    81                 # Close the data file 
    82                 self.raw_data.close() 
    83         # Return data set(s) 
    84         return self.output 
    85  
    86     def reset_class_variables(self): 
     79                try: 
     80                    self.raw_data = h5py.File(filename, 'r') 
     81                except Exception as e: 
     82                    if extension not in self.ext: 
     83                        msg = "CanSAS2.0 HDF5 Reader could not load file {}".format(basename + extension) 
     84                        raise DefaultReaderException(msg) 
     85                    raise FileContentsException(e.message) 
     86                try: 
     87                    # Read in all child elements of top level SASroot 
     88                    self.read_children(self.raw_data, []) 
     89                    # Add the last data set to the list of outputs 
     90                    self.add_data_set() 
     91                except Exception as exc: 
     92                    raise FileContentsException(exc.message) 
     93                finally: 
     94                    # Close the data file 
     95                    self.raw_data.close() 
     96 
     97                for dataset in self.output: 
     98                    if isinstance(dataset, Data1D): 
     99                        if dataset.x.size < 5: 
     100                            self.output = [] 
     101                            raise FileContentsException("Fewer than 5 data points found.") 
     102 
     103    def reset_state(self): 
    87104        """ 
    88105        Create the reader object and define initial states for class variables 
    89106        """ 
    90         self.current_datainfo = None 
    91         self.current_dataset = None 
     107        super(Reader, self).reset_state() 
    92108        self.data1d = [] 
    93109        self.data2d = [] 
     
    95111        self.errors = set() 
    96112        self.logging = [] 
    97         self.output = [] 
    98113        self.parent_class = u'' 
    99114        self.detector = Detector() 
     
    115130            # Get all information for the current key 
    116131            value = data.get(key) 
    117             if value.attrs.get(u'canSAS_class') is not None: 
    118                 class_name = value.attrs.get(u'canSAS_class') 
    119             else: 
    120                 class_name = value.attrs.get(u'NX_class') 
     132            class_name = h5attr(value, u'canSAS_class') 
     133            if class_name is None: 
     134                class_name = h5attr(value, u'NX_class') 
    121135            if class_name is not None: 
    122136                class_prog = re.compile(class_name) 
     
    125139 
    126140            if isinstance(value, h5py.Group): 
     141                # Set parent class before recursion 
    127142                self.parent_class = class_name 
    128143                parent_list.append(key) 
     
    135150                # Recursion step to access data within the group 
    136151                self.read_children(value, parent_list) 
     152                # Reset parent class when returning from recursive method 
     153                self.parent_class = class_name 
    137154                self.add_intermediate() 
    138155                parent_list.remove(key) 
     
    165182                        self.current_dataset.x = data_set.flatten() 
    166183                    continue 
     184                elif key == u'Qdev': 
     185                    self.current_dataset.dx = data_set.flatten() 
     186                    continue 
     187                elif key == u'dQw': 
     188                    self.current_dataset.dxw = data_set.flatten() 
     189                    continue 
     190                elif key == u'dQl': 
     191                    self.current_dataset.dxl = data_set.flatten() 
     192                    continue 
    167193                elif key == u'Qy': 
    168194                    self.current_dataset.yaxis("Q_y", unit) 
     
    198224 
    199225                for data_point in data_set: 
     226                    if isinstance(data_point, np.ndarray): 
     227                        if data_point.dtype.char == 'S': 
     228                            data_point = decode(bytes(data_point)) 
     229                    else: 
     230                        data_point = decode(data_point) 
    200231                    # Top Level Meta Data 
    201232                    if key == u'definition': 
     
    203234                    elif key == u'run': 
    204235                        self.current_datainfo.run.append(data_point) 
     236                        try: 
     237                            run_name = h5attr(value, 'name') 
     238                            run_dict = {data_point: run_name} 
     239                            self.current_datainfo.run_name = run_dict 
     240                        except Exception: 
     241                            pass 
    205242                    elif key == u'title': 
    206243                        self.current_datainfo.title = data_point 
     
    411448        Data1D and Data2D objects 
    412449        """ 
    413  
    414450        # Type cast data arrays to float64 
    415451        if len(self.current_datainfo.trans_spectrum) > 0: 
     
    435471        # Type cast data arrays to float64 and find min/max as appropriate 
    436472        for dataset in self.data2d: 
    437             dataset.data = dataset.data.astype(np.float64) 
    438             dataset.err_data = dataset.err_data.astype(np.float64) 
    439             if dataset.qx_data is not None: 
    440                 dataset.xmin = np.min(dataset.qx_data) 
    441                 dataset.xmax = np.max(dataset.qx_data) 
    442                 dataset.qx_data = dataset.qx_data.astype(np.float64) 
    443             if dataset.dqx_data is not None: 
    444                 dataset.dqx_data = dataset.dqx_data.astype(np.float64) 
    445             if dataset.qy_data is not None: 
    446                 dataset.ymin = np.min(dataset.qy_data) 
    447                 dataset.ymax = np.max(dataset.qy_data) 
    448                 dataset.qy_data = dataset.qy_data.astype(np.float64) 
    449             if dataset.dqy_data is not None: 
    450                 dataset.dqy_data = dataset.dqy_data.astype(np.float64) 
    451             if dataset.q_data is not None: 
    452                 dataset.q_data = dataset.q_data.astype(np.float64) 
    453473            zeros = np.ones(dataset.data.size, dtype=bool) 
    454474            try: 
     
    473493                dataset.x_bins = dataset.qx_data[:n_cols] 
    474494                dataset.data = dataset.data.flatten() 
    475  
    476             final_dataset = combine_data_info_with_plottable( 
    477                 dataset, self.current_datainfo) 
    478             self.output.append(final_dataset) 
     495            self.current_dataset = dataset 
     496            self.send_to_output() 
    479497 
    480498        for dataset in self.data1d: 
    481             if dataset.x is not None: 
    482                 dataset.x = dataset.x.astype(np.float64) 
    483                 dataset.xmin = np.min(dataset.x) 
    484                 dataset.xmax = np.max(dataset.x) 
    485             if dataset.y is not None: 
    486                 dataset.y = dataset.y.astype(np.float64) 
    487                 dataset.ymin = np.min(dataset.y) 
    488                 dataset.ymax = np.max(dataset.y) 
    489             if dataset.dx is not None: 
    490                 dataset.dx = dataset.dx.astype(np.float64) 
    491             if dataset.dxl is not None: 
    492                 dataset.dxl = dataset.dxl.astype(np.float64) 
    493             if dataset.dxw is not None: 
    494                 dataset.dxw = dataset.dxw.astype(np.float64) 
    495             if dataset.dy is not None: 
    496                 dataset.dy = dataset.dy.astype(np.float64) 
    497             final_dataset = combine_data_info_with_plottable( 
    498                 dataset, self.current_datainfo) 
    499             self.output.append(final_dataset) 
     499            self.current_dataset = dataset 
     500            self.send_to_output() 
    500501 
    501502    def add_data_set(self, key=""): 
     
    579580        :return: unit for the value passed to the method 
    580581        """ 
    581         unit = value.attrs.get(u'units') 
     582        unit = h5attr(value, u'units') 
    582583        if unit is None: 
    583             unit = value.attrs.get(u'unit') 
     584            unit = h5attr(value, u'unit') 
    584585        # Convert the unit formats 
    585586        if unit == "1/A": 
  • src/sas/sascalc/dataloader/readers/danse_reader.py

    rcee5c78 rb8080e1  
    157157        # Store all data 
    158158        # Store wavelength 
    159         if has_converter == True and self.current_datainfo.source.wavelength_unit != 'A': 
     159        if has_converter and self.current_datainfo.source.wavelength_unit != 'A': 
    160160            conv = Converter('A') 
    161161            wavelength = conv(wavelength, 
     
    164164 
    165165        # Store distance 
    166         if has_converter == True and detector.distance_unit != 'm': 
     166        if has_converter and detector.distance_unit != 'm': 
    167167            conv = Converter('m') 
    168168            distance = conv(distance, units=detector.distance_unit) 
     
    170170 
    171171        # Store pixel size 
    172         if has_converter == True and detector.pixel_size_unit != 'mm': 
     172        if has_converter and detector.pixel_size_unit != 'mm': 
    173173            conv = Converter('mm') 
    174174            pixel = conv(pixel, units=detector.pixel_size_unit) 
     
    191191        x_vals = np.tile(x_vals, (size_y, 1)).flatten() 
    192192        y_vals = np.tile(y_vals, (size_x, 1)).T.flatten() 
    193         if (np.all(self.current_dataset.err_data is None) 
     193        if (np.all(self.current_dataset.err_data == None) 
    194194                or np.any(self.current_dataset.err_data <= 0)): 
    195195            new_err_data = np.sqrt(np.abs(self.current_dataset.data)) 
  • src/sas/sascalc/dataloader/readers/sesans_reader.py

    r849094a rb8080e1  
    1212from ..file_reader_base_class import FileReader 
    1313from ..data_info import plottable_1D, DataInfo 
    14 from ..loader_exceptions import FileContentsException, DataReaderException 
     14from ..loader_exceptions import FileContentsException 
    1515 
    1616# Check whether we have a converter available 
     
    1818try: 
    1919    from sas.sascalc.data_util.nxsunit import Converter 
    20 except: 
     20except ImportError: 
    2121    has_converter = False 
    2222_ZERO = 1e-16 
     
    4646        line = self.nextline() 
    4747        params = {} 
    48         while not line.startswith("BEGIN_DATA"): 
     48        while line and not line.startswith("BEGIN_DATA"): 
    4949            terms = line.split() 
    5050            if len(terms) >= 2: 
     
    6363            raise FileContentsException("Wavelength has no units") 
    6464        if params["SpinEchoLength_unit"] != params["Wavelength_unit"]: 
    65             raise FileContentsException("The spin echo data has rudely used " 
    66                                "different units for the spin echo length " 
    67                                "and the wavelength.  While sasview could " 
    68                                "handle this instance, it is a violation " 
    69                                "of the file format and will not be " 
    70                                "handled by other software.") 
     65            raise FileContentsException( 
     66                "The spin echo data has rudely used " 
     67                "different units for the spin echo length " 
     68                "and the wavelength.  While sasview could " 
     69                "handle this instance, it is a violation " 
     70                "of the file format and will not be " 
     71                "handled by other software.") 
    7172 
    7273        headers = self.nextline().split() 
     
    8687 
    8788        if not data.size: 
    88             raise FileContentsException("{} is empty".format(path)) 
     89            raise FileContentsException("{} is empty".format(self.filepath)) 
    8990        x = data[:, headers.index("SpinEchoLength")] 
    9091        if "SpinEchoLength_error" in headers: 
Note: See TracChangeset for help on using the changeset viewer.