Changeset 148ad64 in sasview for DataLoader
- Timestamp:
- Mar 10, 2009 9:49:34 AM (16 years ago)
- 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.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- fc67b48
- Parents:
- de1da34
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/readers/abs_reader.py
rca10d8e r148ad64 50 50 y = numpy.zeros(0) 51 51 dy = numpy.zeros(0) 52 output = Data1D(x, y, dy=dy) 52 dx = numpy.zeros(0) 53 output = Data1D(x, y, dy=dy, dx=dx) 53 54 detector = Detector() 54 55 output.detector.append(detector) … … 58 59 is_center = False 59 60 is_data_started = False 61 right_line_is = -2 62 line_n = 0 63 col = 0 60 64 61 65 data_conv_q = None … … 73 77 74 78 for line in lines: 75 79 #print "line",line 76 80 # Information line 1 77 81 if is_info==True: … … 88 92 output.source.wavelength = value 89 93 except: 90 raise ValueError,"IgorReader: can't read this file, missing wavelength" 94 pass 95 #raise ValueError,"IgorReader: can't read this file, missing wavelength" 91 96 92 97 # Distance in meters … … 99 104 detector.distance = value 100 105 except: 101 raise ValueError,"IgorReader: can't read this file, missing distance" 106 pass 107 #raise ValueError,"IgorReader: can't read this file, missing distance" 102 108 103 109 # Transmission … … 119 125 # Thickness is not a mandatory entry 120 126 pass 121 122 #MON CNT LAMBDA DET ANG DET DIST TRANS THICK AVE STEP 123 if line.count("LAMBDA")>0: 124 is_info = True 125 126 # Find center info line 127 if is_center==True: 128 is_center = False 129 line_toks = line.split() 130 # Center in bin number 131 center_x = float(line_toks[0]) 132 center_y = float(line_toks[1]) 133 134 # Bin size 135 if has_converter==True and detector.pixel_size_unit != 'mm': 136 conv = Converter('mm') 137 detector.pixel_size.x = conv(5.0, units=detector.pixel_size_unit) 138 detector.pixel_size.y = conv(5.0, units=detector.pixel_size_unit) 139 else: 140 detector.pixel_size.x = 5.0 141 detector.pixel_size.y = 5.0 142 143 # Store beam center in distance units 144 # Det 640 x 640 mm 145 if has_converter==True and detector.beam_center_unit != 'mm': 146 conv = Converter('mm') 147 detector.beam_center.x = conv(center_x*5.0, units=detector.beam_center_unit) 148 detector.beam_center.y = conv(center_y*5.0, units=detector.beam_center_unit) 149 else: 150 detector.beam_center.x = center_x*5.0 151 detector.beam_center.y = center_y*5.0 152 153 # Detector type 154 try: 155 detector.name = line_toks[7] 156 except: 157 # Detector name is not a mandatory entry 158 pass 159 160 #BCENT(X,Y) A1(mm) A2(mm) A1A2DIST(m) DL/L BSTOP(mm) DET_TYP 161 if line.count("BCENT")>0: 162 is_center = True 163 164 # Parse the data 165 if is_data_started==True: 166 toks = line.split() 167 try: 168 _x = float(toks[0]) 169 _y = float(toks[1]) 170 _dy = float(toks[2]) 171 172 if data_conv_q is not None: 173 _x = data_conv_q(_x, units=output.x_unit) 127 128 #MON CNT LAMBDA DET ANG DET DIST TRANS THICK AVE STEP 129 if line.count("LAMBDA")>0: 130 is_info = True 131 132 # Find center info line 133 if is_center==True: 134 is_center = False 135 line_toks = line.split() 136 # Center in bin number 137 center_x = float(line_toks[0]) 138 center_y = float(line_toks[1]) 139 140 # Bin size 141 if has_converter==True and detector.pixel_size_unit != 'mm': 142 conv = Converter('mm') 143 detector.pixel_size.x = conv(5.0, units=detector.pixel_size_unit) 144 detector.pixel_size.y = conv(5.0, units=detector.pixel_size_unit) 145 else: 146 detector.pixel_size.x = 5.0 147 detector.pixel_size.y = 5.0 148 149 # Store beam center in distance units 150 # Det 640 x 640 mm 151 if has_converter==True and detector.beam_center_unit != 'mm': 152 conv = Converter('mm') 153 detector.beam_center.x = conv(center_x*5.0, units=detector.beam_center_unit) 154 detector.beam_center.y = conv(center_y*5.0, units=detector.beam_center_unit) 155 else: 156 detector.beam_center.x = center_x*5.0 157 detector.beam_center.y = center_y*5.0 158 159 # Detector type 160 try: 161 detector.name = line_toks[7] 162 except: 163 # Detector name is not a mandatory entry 164 pass 165 166 #BCENT(X,Y) A1(mm) A2(mm) A1A2DIST(m) DL/L BSTOP(mm) DET_TYP 167 if line.count("BCENT")>0: 168 is_center = True 169 170 # Parse the data 171 # Specify one line of data 172 if len(lines)<2: 173 colnum = 6 174 else: 175 colnum = len(line.split()) 176 177 #If # of row = # of data points 178 if colnum == 0: 179 rangeiter = 0 180 #If # of row = 1 181 else: 182 rangeiter=numpy.ceil(len(line.split())/colnum) 183 184 #If all data is in one line, chop the line by every 6 columns and read x, y, dy, dx data 185 for col in range(0,rangeiter): 186 #The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor| 187 #Check the file format whether or not it read all header lines and if it has a header 188 if line.count("The 6 columns")>0 or (output.source.wavelength==None): 189 #if it has a full header 190 if line.count("The 6 columns")>0: 191 right_line_is = line_n 192 #If no header in the file 193 else: 194 right_line_is = 0 195 is_data_started = True 196 197 198 # If on the of data, not header, read data 199 if is_data_started==True and right_line_is >= 0: #and line_n > right_line_is 200 #print "col",col 201 toks = line.split() 202 try: 174 203 175 if data_conv_i is not None: 176 _y = data_conv_i(_y, units=output.y_unit) 177 _dy = data_conv_i(_dy, units=output.y_unit) 178 179 x = numpy.append(x, _x) 180 y = numpy.append(y, _y) 181 dy = numpy.append(dy, _dy) 182 except: 183 # Could not read this data line. If we are here 184 # it is because we are in the data section. Just 185 # skip it. 186 pass 187 188 #The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor| 189 if line.count("The 6 columns")>0: 190 is_data_started = True 191 204 if float(toks[col*6+0]) > 1: 205 continue 206 else: 207 not_data_line = False 208 209 _x = float(toks[col*6+0]) 210 _y = float(toks[col*6+1]) 211 _dy = float(toks[col*6+2]) 212 _dx = float(toks[col*6+3]) 213 214 215 if data_conv_q is not None: 216 _x = data_conv_q(_x, units=output.x_unit) 217 _dx = data_conv_i(_dx, units=output.x_unit) 218 219 if data_conv_i is not None: 220 _y = data_conv_i(_y, units=output.y_unit) 221 _dy = data_conv_i(_dy, units=output.y_unit) 222 223 x =numpy.append(x, _x) 224 y = numpy.append(y, _y) 225 dy = numpy.append(dy, _dy) 226 dx = numpy.append(dx, _dx) 227 228 except: 229 # Could not read this data line. If we are here 230 # it is because we are in the data section. Just 231 # skip it. 232 pass 233 234 line_n = line_n +1 192 235 # Sanity check 193 236 if not len(y) == len(dy): 194 237 raise ValueError, "abs_reader: y and dy have different length" 238 if not len(x) == len(dx): 239 raise ValueError, "abs_reader: x and dx have different length" 195 240 196 241 # If the data length is zero, consider this as … … 202 247 output.y = y 203 248 output.dy = dy 249 output.dx = dx 204 250 if data_conv_q is not None: 205 251 output.xaxis("\\rm{Q}", output.x_unit) … … 210 256 else: 211 257 output.yaxis("\\rm{I(Q)}","cm^{-1}") 212 258 #print " x,y,dx,dy", output.x,output.y,output.dy,output.dx 213 259 return output 214 260 else: … … 218 264 if __name__ == "__main__": 219 265 reader = Reader() 220 print reader.read("../test/jan08002.ABS")266 #print reader.read("../test/jan08002.ABS") 221 267 222 268
Note: See TracChangeset
for help on using the changeset viewer.