Changeset 8a621ac in sasview for sanscalculator/src/sans/calculator/instrument.py
- Timestamp:
- Apr 27, 2012 7:22:40 AM (13 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:
- 10bfeb3
- Parents:
- 34f3ad0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sanscalculator/src/sans/calculator/instrument.py
rf93b6a1e r8a621ac 1 1 """ 2 This module is a small tool to allow user to 3 control instrumental parameters 2 This module is a small tool to allow user to 3 control instrumental parameters 4 4 """ 5 5 import numpy … … 7 7 # defaults in cgs unit 8 8 _SAMPLE_A_SIZE = [1.27] 9 _SOURCE_A_SIZE = [3.81] 10 _SAMPLE_DISTANCE = [1627, 0] 11 _SAMPLE_OFFSET = [0, 0] 12 _SAMPLE_SIZE = [2.54] 13 _SAMPLE_THICKNESS = 0.2 14 _D_DISTANCE = [1000, 0] 9 _SOURCE_A_SIZE = [3.81] 10 _SAMPLE_DISTANCE = [1627, 0] 11 _SAMPLE_OFFSET = [0, 0] 12 _SAMPLE_SIZE = [2.54] 13 _SAMPLE_THICKNESS = 0.2 14 _D_DISTANCE = [1000, 0] 15 15 _D_SIZE = [128, 128] 16 _D_PIX_SIZE = [0.5, 0.5] 16 _D_PIX_SIZE = [0.5, 0.5] 17 17 18 18 _MIN = 0.0 … … 21 21 _WAVE_LENGTH = 6.0 22 22 _WAVE_SPREAD = 0.125 23 _MASS = 1.67492729E-24 #[gr] 24 _LAMBDA_ARRAY = [[0, 1e+16],[_INTENSITY, _INTENSITY]] 23 _MASS = 1.67492729E-24 # [gr] 24 _LAMBDA_ARRAY = [[0, 1e+16], [_INTENSITY, _INTENSITY]] 25 25 26 26 27 class Aperture(object): … … 36 37 self.sample_distance = _SAMPLE_DISTANCE 37 38 38 def set_source_size(self, size 39 def set_source_size(self, size=[]): 39 40 """ 40 41 Set the source aperture size 41 42 """ 42 43 if len(size) == 0: 43 self.source_size = 0.0 44 self.source_size = 0.0 44 45 else: 45 46 self.source_size = size 46 47 validate(size[0]) 47 def set_sample_size(self, size =[]): 48 49 def set_sample_size(self, size=[]): 48 50 """ 49 51 Set the sample aperture size 50 52 """ 51 53 if len(size) == 0: 52 self.sample_size = 0.0 54 self.sample_size = 0.0 53 55 else: 54 56 self.sample_size = size 55 57 validate(size[0]) 56 58 57 def set_sample_distance(self, distance =[]):59 def set_sample_distance(self, distance=[]): 58 60 """ 59 61 Set the sample aperture distance 60 62 """ 61 63 if len(distance) == 0: 62 self.sample_distance = 0.0 64 self.sample_distance = 0.0 63 65 else: 64 66 self.sample_distance = distance … … 78 80 self.thickness = _SAMPLE_THICKNESS 79 81 80 81 def set_size(self, size =[]): 82 def set_size(self, size=[]): 82 83 """ 83 84 Set the sample size 84 85 """ 85 86 if len(size) == 0: 86 self.sample_size = 0.0 87 self.sample_size = 0.0 87 88 else: 88 89 self.sample_size = size 89 90 validate(size[0]) 90 91 91 def set_thickness(self, thickness =0.0):92 def set_thickness(self, thickness=0.0): 92 93 """ 93 94 Set the sample thickness … … 96 97 validate(thickness) 97 98 98 def set_distance(self, distance =[]):99 def set_distance(self, distance=[]): 99 100 """ 100 101 Set the sample distance 101 102 """ 102 103 if len(distance) == 0: 103 self.distance = 0.0 104 self.distance = 0.0 104 105 else: 105 106 self.distance = distance … … 122 123 123 124 124 def set_size(self, size 125 def set_size(self, size=[]): 125 126 """ 126 127 Set the detector size … … 132 133 validate(size[0]) 133 134 134 def set_pix_size(self, size =[]):135 def set_pix_size(self, size=[]): 135 136 """ 136 137 Set the detector pix_size 137 138 """ 138 139 if len(size) == 0: 139 self.pix_size = 0 140 self.pix_size = 0 140 141 else: 141 142 self.pix_size = size 142 143 validate(size[0]) 143 144 144 def set_distance(self, distance =[]):145 def set_distance(self, distance=[]): 145 146 """ 146 147 Set the detector distance … … 166 167 # wavelength spread (FWHM) 167 168 self.wavelength_spread = _WAVE_SPREAD 168 # wavelength spectrum 169 self.spectrum = self.get_default_spectrum() 169 # wavelength spectrum 170 self.spectrum = self.get_default_spectrum() 170 171 # intensity in counts/sec 171 self.intensity = numpy.interp(self.wavelength, 172 self.intensity = numpy.interp(self.wavelength, 172 173 self.spectrum[0], 173 174 self.spectrum[1], … … 188 189 """ 189 190 self.band = self.spectrum 190 def set_spectrum(self, spectrum): 191 192 def set_spectrum(self, spectrum): 191 193 """ 192 194 Set spectrum … … 194 196 :param spectrum: numpy array 195 197 """ 196 self.spectrum = spectrum 198 self.spectrum = spectrum 197 199 self.setup_spectrum() 198 200 199 201 def setup_spectrum(self): 200 202 """ 201 To set the wavelength spectrum, and intensity, assumes 203 To set the wavelength spectrum, and intensity, assumes 202 204 wavelength is already within the spectrum 203 205 """ 204 206 spectrum = self.spectrum 205 intensity = numpy.interp(self.wavelength, 207 intensity = numpy.interp(self.wavelength, 206 208 spectrum[0], 207 209 spectrum[1], … … 213 215 self.max = max(self.spectrum[0]) 214 216 # set default band 215 self.set_band([self.min, self.max])217 self.set_band([self.min, self.max]) 216 218 217 219 def set_band(self, band=[]): … … 224 226 if min(band) < self.min or\ 225 227 max(band) > self.max: 226 raise 228 raise 227 229 self.band = band 228 229 230 230 def set_intensity(self, intensity =368428):231 def set_intensity(self, intensity=368428): 231 232 """ 232 233 Sets the intensity in counts/sec 233 234 """ 234 self.intensity = intensity 235 validate(intensity) 236 237 def set_wavelength(self, wavelength =_WAVE_LENGTH):235 self.intensity = intensity 236 validate(intensity) 237 238 def set_wavelength(self, wavelength=_WAVE_LENGTH): 238 239 """ 239 240 Sets the wavelength … … 242 243 if wavelength < min(self.band) or\ 243 244 wavelength > max(self.band): 244 raise 245 raise 245 246 self.wavelength = wavelength 246 247 validate(wavelength) 247 self.intensity = numpy.interp(self.wavelength, 248 self.intensity = numpy.interp(self.wavelength, 248 249 self.spectrum[0], 249 250 self.spectrum[1], … … 251 252 0.0) 252 253 253 254 def set_mass(self, mass = _MASS): 254 def set_mass(self, mass=_MASS): 255 255 """ 256 256 Sets the wavelength … … 259 259 validate(mass) 260 260 261 def set_wavelength_spread(self, spread =_WAVE_SPREAD):261 def set_wavelength_spread(self, spread=_WAVE_SPREAD): 262 262 """ 263 263 Sets the wavelength spread … … 302 302 """ 303 303 return self.spectrum 304 304 305 def get_default_spectrum(self): 305 306 """ … … 307 308 """ 308 309 return numpy.array(_LAMBDA_ARRAY) 310 309 311 def get_band(self): 310 312 """ 311 313 To get the wavelength band 312 314 """ 313 return self.band 315 return self.band 314 316 315 317 def plot_spectrum(self): … … 320 322 try: 321 323 import matplotlib.pyplot as plt 322 plt.plot(self.spectrum[0], self.spectrum[1], linewidth = 2, color ='r')323 plt.legend(['Spectrum'], loc ='best')324 plt.plot(self.spectrum[0], self.spectrum[1], linewidth=2, color='r') 325 plt.legend(['Spectrum'], loc='best') 324 326 plt.show() 325 327 except: … … 345 347 get list of the intensity wrt wavelength_list 346 348 """ 347 out = numpy.interp(self.wavelength_list, 349 out = numpy.interp(self.wavelength_list, 348 350 self.spectrum[0], 349 351 self.spectrum[1], … … 375 377 376 378 377 def validate(value =None):379 def validate(value=None): 378 380 """ 379 381 Check if the value is folat > 0.0 … … 389 391 except: 390 392 val = False 391 #if not val:392 # raise ValueError, "Got improper value..."
Note: See TracChangeset
for help on using the changeset viewer.