Changeset cb9feea8 in sasview


Ignore:
Timestamp:
Apr 4, 2017 6:15:55 PM (7 years ago)
Author:
Adam Washington <adam.washington@…>
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:
8390cf6
Parents:
56e2e3e
Message:

Pulled code out of conditional in sesans_reader.py

File:
1 edited

Legend:

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

    r56e2e3e rcb9feea8  
    4949            basename = os.path.basename(path) 
    5050            _, extension = os.path.splitext(basename) 
    51             if self.allow_all or extension.lower() in self.ext: 
    52                 with open(path, 'r') as input_f: 
    53                     # Read in binary mode since GRASP frequently has no-ascii 
    54                     # characters that brakes the open operation 
    55                     line = input_f.readline() 
    56                     params = {} 
    57                     while line.strip() != "": 
    58                         terms = line.strip().split("\t") 
    59                         params[terms[0].strip()] = " ".join(terms[1:]).strip() 
    60                         line = input_f.readline() 
    61                     headers_temp = input_f.readline().strip().split("\t") 
    62                     headers = {} 
    63                     for h in headers_temp: 
    64                         temp = h.strip().split() 
    65                         headers[h[:-1].strip()] = temp[-1][1:-1] 
    66                     data = np.loadtxt(input_f) 
    67                     if data.size < 1: 
    68                         raise RuntimeError("{} is empty".format(path)) 
    69                     x = data[:, 0] 
    70                     dx = data[:, 3] 
    71                     lam = data[:, 4] 
    72                     dlam = data[:, 5] 
    73                     y = data[:, 1] 
    74                     dy = data[:, 2] 
     51            if not (self.allow_all or extension.lower() in self.ext): 
     52                raise RuntimeError("{} has an unrecognized file extension".format(path)) 
     53        else: 
     54            raise RunetimeError("{} is not a file".format(path)) 
     55        with open(path, 'r') as input_f: 
     56            # Read in binary mode since GRASP frequently has no-ascii 
     57            # characters that brakes the open operation 
     58            line = input_f.readline() 
     59            params = {} 
     60            while line.strip() != "": 
     61                terms = line.strip().split("\t") 
     62                params[terms[0].strip()] = " ".join(terms[1:]).strip() 
     63                line = input_f.readline() 
     64            headers_temp = input_f.readline().strip().split("\t") 
     65            headers = {} 
     66            for h in headers_temp: 
     67                temp = h.strip().split() 
     68                headers[h[:-1].strip()] = temp[-1][1:-1] 
     69            data = np.loadtxt(input_f) 
     70            if data.size < 1: 
     71                raise RuntimeError("{} is empty".format(path)) 
     72            x = data[:, 0] 
     73            dx = data[:, 3] 
     74            lam = data[:, 4] 
     75            dlam = data[:, 5] 
     76            y = data[:, 1] 
     77            dy = data[:, 2] 
    7578 
    76                     lam_unit = self._header_fetch(headers, "wavelength") 
    77                     if lam_unit == "AA": 
    78                         lam_unit = "A" 
     79            lam_unit = self._header_fetch(headers, "wavelength") 
     80            if lam_unit == "AA": 
     81                lam_unit = "A" 
    7982 
    80                     x, x_unit = self._unit_conversion( 
    81                         x, lam_unit, 
    82                         self._fetch_unit(headers, "spin echo length")) 
    83                     dx, dx_unit = self._unit_conversion( 
    84                         dx, lam_unit, 
    85                         self._fetch_unit(headers, "error SEL")) 
    86                     dlam, dlam_unit = self._unit_conversion( 
    87                         dlam, lam_unit, 
    88                         self._fetch_unit(headers, "error wavelength")) 
    89                     y_unit = r'\AA^{-2} cm^{-1}' 
     83            x, x_unit = self._unit_conversion( 
     84                x, lam_unit, 
     85                self._fetch_unit(headers, "spin echo length")) 
     86            dx, dx_unit = self._unit_conversion( 
     87                dx, lam_unit, 
     88                self._fetch_unit(headers, "error SEL")) 
     89            dlam, dlam_unit = self._unit_conversion( 
     90                dlam, lam_unit, 
     91                self._fetch_unit(headers, "error wavelength")) 
     92            y_unit = r'\AA^{-2} cm^{-1}' 
    9093 
    91                     output = Data1D(x=x, y=y, lam=lam, dy=dy, dx=dx, dlam=dlam, 
    92                                     isSesans=True) 
    93                     self.filename = output.filename = basename 
    94                     output.xaxis(r"\rm{z}", x_unit) 
    95                     # Adjust label to ln P/(lam^2 t), remove lam column refs 
    96                     output.yaxis(r"\rm{ln(P)/(t \lambda^2)}", y_unit) 
    97                     # Store loading process information 
    98                     output.meta_data['loader'] = self.type_name 
    99                     output.sample.name = params["Sample"] 
    100                     output.sample.ID = params["DataFileTitle"] 
     94            output = Data1D(x=x, y=y, lam=lam, dy=dy, dx=dx, dlam=dlam, 
     95                            isSesans=True) 
     96            self.filename = output.filename = basename 
     97            output.xaxis(r"\rm{z}", x_unit) 
     98            # Adjust label to ln P/(lam^2 t), remove lam column refs 
     99            output.yaxis(r"\rm{ln(P)/(t \lambda^2)}", y_unit) 
     100            # Store loading process information 
     101            output.meta_data['loader'] = self.type_name 
     102            output.sample.name = params["Sample"] 
     103            output.sample.ID = params["DataFileTitle"] 
    101104 
    102                     output.sample.zacceptance = ( 
    103                         float(self._header_fetch(params, "Q_zmax")), 
    104                         self._fetch_unit(params, "Q_zmax")) 
     105            output.sample.zacceptance = ( 
     106                float(self._header_fetch(params, "Q_zmax")), 
     107                self._fetch_unit(params, "Q_zmax")) 
    105108 
    106                     output.sample.yacceptance = ( 
    107                         float(self._header_fetch(params, "Q_ymax")), 
    108                         self._fetch_unit(params, "Q_ymax")) 
    109                     return output 
    110  
    111         else: 
    112             raise RuntimeError("%s is not a file" % path) 
    113         return None 
     109            output.sample.yacceptance = ( 
     110                float(self._header_fetch(params, "Q_ymax")), 
     111                self._fetch_unit(params, "Q_ymax")) 
     112            return output 
    114113 
    115114    @staticmethod 
Note: See TracChangeset for help on using the changeset viewer.