Changeset 7d6351e in sasview for sansdataloader/src/sans/dataloader/readers/abs_reader.py
- Timestamp:
- Apr 27, 2012 11:22:31 AM (12 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:
- 4a96b8b
- Parents:
- f60a8c2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansdataloader/src/sans/dataloader/readers/abs_reader.py
raac129aa r7d6351e 4 4 #This software was developed by the University of Tennessee as part of the 5 5 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 6 #project funded by the US National Science Foundation. 6 #project funded by the US National Science Foundation. 7 7 #See the license text in license.txt 8 8 #copyright 2008, University of Tennessee … … 20 20 has_converter = False 21 21 22 22 23 class Reader: 23 24 """ … … 25 26 """ 26 27 ## File type 27 type_name = "IGOR 1D" 28 type_name = "IGOR 1D" 28 29 ## Wildcards 29 30 type = ["IGOR 1D files (*.abs)|*.abs"] 30 31 ## List of allowed extensions 31 ext = ['.abs', '.ABS'] 32 ext = ['.abs', '.ABS'] 32 33 33 34 def read(self, path): … … 43 44 """ 44 45 if os.path.isfile(path): 45 basename 46 basename = os.path.basename(path) 46 47 root, extension = os.path.splitext(basename) 47 48 if extension.lower() in self.ext: 48 49 try: 49 input_f = 50 except 50 input_f = open(path,'r') 51 except: 51 52 raise RuntimeError, "abs_reader: cannot open %s" % path 52 53 buff = input_f.read() … … 91 92 output.source.wavelength_unit != 'A': 92 93 conv = Converter('A') 93 output.source.wavelength = conv(value, 94 output.source.wavelength = conv(value, 94 95 units=output.source.wavelength_unit) 95 96 else: … … 99 100 msg = "abs_reader: cannot open %s" % path 100 101 raise RuntimeError, msg 101 #raise ValueError,"IgorReader: can't read this file,102 # missing wavelength"103 102 104 103 # Distance in meters … … 108 107 detector.distance_unit != 'm': 109 108 conv = Converter('m') 110 detector.distance = conv(value, 109 detector.distance = conv(value, 111 110 units=detector.distance_unit) 112 111 else: … … 116 115 msg = "abs_reader: cannot open %s" % path 117 116 raise RuntimeError, msg 118 # Transmission 117 # Transmission 119 118 try: 120 119 output.sample.transmission = float(line_toks[4]) … … 129 128 output.sample.thickness_unit != 'cm': 130 129 conv = Converter('cm') 131 output.sample.thickness = conv(value, 130 output.sample.thickness = conv(value, 132 131 units=output.sample.thickness_unit) 133 132 else: … … 144 143 # Find center info line 145 144 if is_center == True: 146 is_center = False 145 is_center = False 147 146 line_toks = line.split() 148 147 # Center in bin number … … 154 153 detector.pixel_size_unit != 'mm': 155 154 conv = Converter('mm') 156 detector.pixel_size.x = conv(5.0, 155 detector.pixel_size.x = conv(5.0, 157 156 units=detector.pixel_size_unit) 158 157 detector.pixel_size.y = conv(5.0, … … 164 163 # Store beam center in distance units 165 164 # Det 640 x 640 mm 166 if has_converter ==True and \165 if has_converter == True and \ 167 166 detector.beam_center_unit != 'mm': 168 167 conv = Converter('mm') 169 168 detector.beam_center.x = conv(center_x * 5.0, 170 169 units=detector.beam_center_unit) 171 detector.beam_center.y = conv(center_y * 5.0, 170 detector.beam_center.y = conv(center_y * 5.0, 172 171 units=detector.beam_center_unit) 173 172 else: … … 182 181 pass 183 182 184 #BCENT(X,Y) A1(mm) A2(mm) A1A2DIST(m) DL/L 185 # BSTOP(mm) DET_TYP 183 #BCENT(X,Y) A1(mm) A2(mm) A1A2DIST(m) DL/L 184 # BSTOP(mm) DET_TYP 186 185 if line.count("BCENT") > 0: 187 186 is_center = True … … 191 190 toks = line.split() 192 191 193 try: 192 try: 194 193 _x = float(toks[0]) 195 _y = float(toks[1]) 194 _y = float(toks[1]) 196 195 _dy = float(toks[2]) 197 196 _dx = float(toks[3]) … … 205 204 _dy = data_conv_i(_dy, units=output.y_unit) 206 205 207 x = numpy.append(x, _x)208 y = numpy.append(y,_y)206 x = numpy.append(x, _x) 207 y = numpy.append(y, _y) 209 208 dy = numpy.append(dy, _dy) 210 dx 209 dx = numpy.append(dx, _dx) 211 210 212 211 except: … … 218 217 #The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. 219 218 # I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor| 220 if line.count("The 6 columns") >0:219 if line.count("The 6 columns") > 0: 221 220 is_data_started = True 222 221 … … 230 229 raise ValueError, "ascii_reader: could not load file" 231 230 232 output.x = x[x !=0]233 output.y = y[x !=0]234 output.dy = dy[x !=0]235 output.dx = dx[x !=0]231 output.x = x[x != 0] 232 output.y = y[x != 0] 233 output.dy = dy[x != 0] 234 output.dx = dx[x != 0] 236 235 if data_conv_q is not None: 237 236 output.xaxis("\\rm{Q}", output.x_unit) … … 241 240 output.yaxis("\\rm{Intensity}", output.y_unit) 242 241 else: 243 output.yaxis("\\rm{Intensity}", "cm^{-1}")242 output.yaxis("\\rm{Intensity}", "cm^{-1}") 244 243 245 244 # Store loading process information 246 output.meta_data['loader'] = self.type_name 245 output.meta_data['loader'] = self.type_name 247 246 return output 248 247 else: 249 248 raise RuntimeError, "%s is not a file" % path 250 249 return None 251 252 if __name__ == "__main__":253 reader = Reader()254 print reader.read("../test/jan08002.ABS")255 256 257
Note: See TracChangeset
for help on using the changeset viewer.