Changes in / [b2ac7b0:6f17afa] in sasview


Ignore:
File:
1 edited

Legend:

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

    r26d4864 rb699768  
    8787#                print output                 
    8888                self.filename = output.filename = basename 
    89  
     89                 
     90                 
     91                data_conv_z = None 
     92                data_conv_P = None 
     93#                print "passing" 
     94                if has_converter == True and output.x_unit != 'A': 
     95                    data_conv_z = Converter('nm') 
     96                    # Test it 
     97                    data_conv_z(1.0, output.x_unit) 
     98#                    print data_conv_z 
     99#                    print data_conv_z(1.0, output.x_unit) 
     100                if has_converter == True and output.y_unit != ' ': 
     101                    data_conv_P = Converter('a.u.') 
     102                    # Test it 
     103                    data_conv_P(1.0, output.y_unit) 
     104#                    print data_conv_P 
     105#                    print data_conv_P(1.0, output.y_unit) 
     106                # The first good line of data will define whether 
     107                # we have 2-column or 3-column ascii 
     108#                print output.x_unit 
     109#                print output.y_unit 
     110                 
     111#                print "past output" 
     112                 
     113#                has_error_dx = None 
     114#                has_error_dy = None 
     115                 
    90116#                #Initialize counters for data lines and header lines. 
    91117#                is_data = False  # Has more than 5 lines 
     
    115141                for line in lines: 
    116142                    # Initial try for CSV (split on ,) 
     143#                    print line 
    117144                    line=line.strip() 
     145#                    print line 
    118146                    toks = line.split('\t') 
     147#                    print toks 
    119148                    if len(toks)==2: 
    120149                        paramnames.append(toks[0]) 
     150#                        print paramnames 
    121151                        paramvals.append(toks[1]) 
     152#                        print paramvals 
    122153                    if len(toks)>5: 
    123154                        zvals.append(toks[0]) 
     
    129160                    else: 
    130161                        continue 
    131  
     162#                print varheaders 
     163#                print paramnames 
     164#                print paramvals 
     165#                print zvals   
     166#                print len(zvals) 
     167                 
    132168                x=[] 
    133169                y=[] 
     
    136172                dy=[] 
    137173                dlam=[] 
    138                 lam_header = lamvals[0].split() 
    139                 data_conv_z = None 
    140                 default_z_unit = "A" 
    141                 data_conv_P = None 
    142                 default_p_unit = " " 
    143                 lam_unit = lam_header[1].replace("[","").replace("]","") 
    144                 for i,x_val in output.x: 
    145                     output.x[i], output.x_unit = self._unit_conversion(x_val, lam_unit, default_z_unit) 
    146                 for i,y_val in output.y: 
    147                     output.y[i], output.y_unit = self._unit_conversion(y_val, " ", default_p_unit) 
    148174                varheader=[zvals[0],dzvals[0],lamvals[0],dlamvals[0],Pvals[0],dPvals[0]] 
    149                 valrange=range(1, len(zvals)) 
     175#                print varheader 
     176                valrange=range(len(zvals)-1) 
     177#                print valrange 
    150178                for i in valrange: 
    151                     x.append(float(zvals[i])) 
    152                     y.append(float(Pvals[i])) 
    153                     lam.append(float(lamvals[i])) 
    154                     dy.append(float(dPvals[i])) 
    155                     dx.append(float(dzvals[i])) 
    156                     dlam.append(float(dlamvals[i])) 
    157  
     179                    x.append(float(zvals[i+1])) 
     180                    y.append(float(Pvals[i+1])) 
     181                    lam.append(float(lamvals[i+1])) 
     182                    dy.append(float(dPvals[i+1])) 
     183                    dx.append(float(dzvals[i+1])) 
     184                    dlam.append(float(dlamvals[i+1])) 
     185                     
    158186                x,y,lam,dy,dx,dlam = [ 
    159187                   numpy.asarray(v, 'double') 
     
    161189                ] 
    162190 
     191#                print x 
     192#                print y 
     193#                print dx 
     194#                print dy 
     195#                print len(x) 
     196#                print len(y) 
     197#                print len(dx) 
     198#                print len(dy) 
     199                 
     200                 
    163201                input_f.close() 
    164  
     202                # Sanity check 
     203#                if has_error_dy == True and not len(y) == len(dy): 
     204#                    msg = "sesans_reader: y and dy have different length" 
     205#                    raise RuntimeError, msg 
     206#                if has_error_dx == True and not len(x) == len(dx): 
     207#                    msg = "sesans_reader: y and dy have different length" 
     208#                    raise RuntimeError, msg 
     209#                # If the data length is zero, consider this as 
     210#                # though we were not able to read the file. 
     211#                if len(x) == 0: 
     212#                    raise RuntimeError, "sesans_reader: could not load file" 
     213#                print "alive" 
     214                #Let's re-order the data to make cal. 
     215                # curve look better some cases 
     216#                ind = numpy.lexsort((ty, tx)) 
     217#                for i in ind: 
     218#                    x[i] = tx[ind[i]] 
     219#                    y[i] = ty[ind[i]] 
     220#                    if has_error_dy == True: 
     221#                        dy[i] = tdy[ind[i]] 
     222#                    if has_error_dx == True: 
     223#                        dx[i] = tdx[ind[i]] 
     224                # Zeros in dx, dy 
     225#                if has_error_dx: 
     226#                    dx[dx == 0] = _ZERO 
     227#                if has_error_dy: 
     228#                    dy[dy == 0] = _ZERO 
    165229                #Data 
    166230                output.x = x #[x != 0] 
     231#                print output.x 
    167232                output.y = y #[x != 0] 
     233#                print output.y 
     234#                output.dy = dy[x != 0] if has_error_dy == True\ 
     235#                    else numpy.zeros(len(output.y)) 
     236#                output.dx = dx[x != 0] if has_error_dx == True\ 
     237#                    else numpy.zeros(len(output.x)) 
    168238                output.dy = dy 
    169239                output.dx = dx 
     
    171241                output.dlam = dlam 
    172242 
    173                 output.xaxis("\rm{z}", output.x_unit) 
    174                 output.yaxis("\\rm{P/P0}", output.y_unit) 
     243 
     244#                print "still alive"                 
     245#                if data_conv_z is not None: 
     246#                    output.xaxis("\\rm{z}", output.x_unit) 
     247#                else: 
     248#                    output.xaxis("\\rm{z}", 'nm') 
     249#                if data_conv_P is not None: 
     250#                    output.yaxis("\\rm{P/P0}", output.y_unit) 
     251#                else: 
     252#                    output.yaxis("\\rm{P/P0}", "a.u.") 
     253                output.xaxis("\\rm{z}", 'nm')    
     254                output.yaxis("\\rm{P/P0}", " ") 
    175255                # Store loading process information 
    176256                output.meta_data['loader'] = self.type_name 
     
    181261                output.vars=varheader 
    182262 
     263#                print "sesans_reader end" 
     264                 
    183265                if len(output.x) < 1: 
    184266                    raise RuntimeError, "%s is empty" % path 
     267#                print output 
     268#                print output.lam 
    185269                return output 
    186  
     270             
    187271        else: 
    188272            raise RuntimeError, "%s is not a file" % path 
    189273        return None 
    190  
    191     def _unit_conversion(self, value, value_unit, default_unit): 
    192         if has_converter == True and value_unit != default_unit: 
    193             data_conv_q = Converter(value_unit) 
    194             value = data_conv_q(value, units=default_unit) 
    195             new_unit = default_unit 
    196         else: 
    197             new_unit = value_unit 
    198         return value, new_unit 
Note: See TracChangeset for help on using the changeset viewer.