Changes in / [b2ac7b0:6f17afa] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/sesans_reader.py
r26d4864 rb699768 87 87 # print output 88 88 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 90 116 # #Initialize counters for data lines and header lines. 91 117 # is_data = False # Has more than 5 lines … … 115 141 for line in lines: 116 142 # Initial try for CSV (split on ,) 143 # print line 117 144 line=line.strip() 145 # print line 118 146 toks = line.split('\t') 147 # print toks 119 148 if len(toks)==2: 120 149 paramnames.append(toks[0]) 150 # print paramnames 121 151 paramvals.append(toks[1]) 152 # print paramvals 122 153 if len(toks)>5: 123 154 zvals.append(toks[0]) … … 129 160 else: 130 161 continue 131 162 # print varheaders 163 # print paramnames 164 # print paramvals 165 # print zvals 166 # print len(zvals) 167 132 168 x=[] 133 169 y=[] … … 136 172 dy=[] 137 173 dlam=[] 138 lam_header = lamvals[0].split()139 data_conv_z = None140 default_z_unit = "A"141 data_conv_P = None142 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)148 174 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 150 178 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 158 186 x,y,lam,dy,dx,dlam = [ 159 187 numpy.asarray(v, 'double') … … 161 189 ] 162 190 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 163 201 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 165 229 #Data 166 230 output.x = x #[x != 0] 231 # print output.x 167 232 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)) 168 238 output.dy = dy 169 239 output.dx = dx … … 171 241 output.dlam = dlam 172 242 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}", " ") 175 255 # Store loading process information 176 256 output.meta_data['loader'] = self.type_name … … 181 261 output.vars=varheader 182 262 263 # print "sesans_reader end" 264 183 265 if len(output.x) < 1: 184 266 raise RuntimeError, "%s is empty" % path 267 # print output 268 # print output.lam 185 269 return output 186 270 187 271 else: 188 272 raise RuntimeError, "%s is not a file" % path 189 273 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_unit196 else:197 new_unit = value_unit198 return value, new_unit
Note: See TracChangeset
for help on using the changeset viewer.