Changeset 470bf7e in sasview
- Timestamp:
- Apr 2, 2009 11:32:32 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:
- 954c045
- Parents:
- 89ef796
- Location:
- DataLoader/readers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/readers/abs_reader.py
r148ad64 r470bf7e 59 59 is_center = False 60 60 is_data_started = False 61 right_line_is = -262 line_n = 063 col = 064 61 65 62 data_conv_q = None … … 77 74 78 75 for line in lines: 79 #print "line",line76 80 77 # Information line 1 81 78 if is_info==True: … … 92 89 output.source.wavelength = value 93 90 except: 94 pass 91 #goes to ASC reader 92 raise RuntimeError, "abs_reader: cannot open %s" % path 95 93 #raise ValueError,"IgorReader: can't read this file, missing wavelength" 96 94 … … 104 102 detector.distance = value 105 103 except: 106 pass107 #raise ValueError,"IgorReader: can't read this file, missing distance"104 #goes to ASC reader 105 raise RuntimeError, "abs_reader: cannot open %s" % path 108 106 109 107 # Transmission … … 125 123 # Thickness is not a mandatory entry 126 124 pass 127 128 #MON CNT LAMBDA DET ANG DET DIST TRANS THICK AVE STEP 129 if line.count("LAMBDA")>0: 130 is_info = True 125 126 #MON CNT LAMBDA DET ANG DET DIST TRANS THICK AVE STEP 127 if line.count("LAMBDA")>0: 128 is_info = True 129 130 # Find center info line 131 if is_center==True: 132 is_center = False 133 line_toks = line.split() 134 # Center in bin number 135 center_x = float(line_toks[0]) 136 center_y = float(line_toks[1]) 137 138 # Bin size 139 if has_converter==True and detector.pixel_size_unit != 'mm': 140 conv = Converter('mm') 141 detector.pixel_size.x = conv(5.0, units=detector.pixel_size_unit) 142 detector.pixel_size.y = conv(5.0, units=detector.pixel_size_unit) 143 else: 144 detector.pixel_size.x = 5.0 145 detector.pixel_size.y = 5.0 146 147 # Store beam center in distance units 148 # Det 640 x 640 mm 149 if has_converter==True and detector.beam_center_unit != 'mm': 150 conv = Converter('mm') 151 detector.beam_center.x = conv(center_x*5.0, units=detector.beam_center_unit) 152 detector.beam_center.y = conv(center_y*5.0, units=detector.beam_center_unit) 153 else: 154 detector.beam_center.x = center_x*5.0 155 detector.beam_center.y = center_y*5.0 156 157 # Detector type 158 try: 159 detector.name = line_toks[7] 160 except: 161 # Detector name is not a mandatory entry 162 pass 163 164 #BCENT(X,Y) A1(mm) A2(mm) A1A2DIST(m) DL/L BSTOP(mm) DET_TYP 165 if line.count("BCENT")>0: 166 is_center = True 167 168 # Parse the data 169 if is_data_started==True: 170 toks = line.split() 171 172 try: 173 _x = float(toks[0]) 174 _y = float(toks[1]) 175 _dy = float(toks[2]) 176 _dx = float(toks[3]) 131 177 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]) 178 if data_conv_q is not None: 179 _x = data_conv_q(_x, units=output.x_unit) 180 _dx = data_conv_i(_dx, units=output.x_unit) 181 182 if data_conv_i is not None: 183 _y = data_conv_i(_y, units=output.y_unit) 184 _dy = data_conv_i(_dy, units=output.y_unit) 185 186 x = numpy.append(x, _x) 187 y = numpy.append(y, _y) 188 dy = numpy.append(dy, _dy) 189 dx = numpy.append(dx, _dx) 139 190 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 191 except: 192 # Could not read this data line. If we are here 193 # it is because we are in the data section. Just 194 # skip it. 195 pass 148 196 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: 203 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 197 #The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor| 198 if line.count("The 6 columns")>0: 199 is_data_started = True 200 235 201 # Sanity check 236 202 if not len(y) == len(dy): 237 203 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"240 204 241 205 # If the data length is zero, consider this as … … 256 220 else: 257 221 output.yaxis("\\rm{I(Q)}","cm^{-1}") 258 #print " x,y,dx,dy", output.x,output.y,output.dy,output.dx259 222 return output 260 223 else: … … 264 227 if __name__ == "__main__": 265 228 reader = Reader() 266 #print reader.read("../test/jan08002.ABS")229 print reader.read("../test/jan08002.ABS") 267 230 268 231 -
DataLoader/readers/ascii_reader.py
rde1da34 r470bf7e 26 26 ## File type 27 27 type = ["ASCII files (*.txt)|*.txt", 28 "ASCII files (*.dat)|*.dat"] 28 "ASCII files (*.dat)|*.dat", 29 "ASCII files (*.abs)|*.abs"] 29 30 ## List of allowed extensions 30 ext=['.txt', '.TXT', '.dat', '.DAT' ]31 ext=['.txt', '.TXT', '.dat', '.DAT', '.abs', '.ABS'] 31 32 32 33 def read(self, path): … … 49 50 buff = input_f.read() 50 51 lines = buff.split('\n') 52 53 # some ascii data has \r line separator, try it when it has only one line 54 if len(lines) < 2 : 55 lines = buff.split('\r') 56 51 57 x = numpy.zeros(0) 52 58 y = numpy.zeros(0) … … 163 169 raise RuntimeError, "ascii_reader: could not load file" 164 170 165 #Let's re oder the data171 #Let's re-order the data to make cal. curve look better some cases 166 172 ind = numpy.lexsort((ty,tx)) 167 173 for i in ind: … … 186 192 else: 187 193 output.yaxis("\\rm{I(Q)}","cm^{-1}") 188 194 189 195 return output 190 196 else:
Note: See TracChangeset
for help on using the changeset viewer.