- Timestamp:
- Mar 4, 2015 1:02:23 PM (10 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:
- 7cd87c2
- Parents:
- 5a7d933
- Location:
- src/sas/calculator
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/calculator/instrument.py
r26500ec rb6627d9 85 85 """ 86 86 if len(size) == 0: 87 self.s ample_size = 0.088 else: 89 self.s ample_size = size87 self.size = 0.0 88 else: 89 self.size = size 90 90 validate(size[0]) 91 91 -
src/sas/calculator/resolution_calculator.py
r6bd3a8d1 rb6627d9 13 13 import math 14 14 import numpy 15 import sys 16 import logging 15 17 16 18 #Plank's constant in cgs unit … … 77 79 self.detector_pix_size = [] 78 80 self.detector_size = [] 79 # get all the values of the instrumental parameters80 #self.intensity = self.get_intensity()81 #self.wavelength = self.get_wavelength()82 #self.wavelength_spread = self.get_wavelength_spread()83 81 self.get_all_instrument_params() 84 82 # max q range for all lambdas … … 87 85 88 86 def compute_and_plot(self, qx_value, qy_value, qx_min, qx_max, 89 87 qy_min, qy_max, coord='cartesian'): 90 88 """ 91 89 Compute the resolution … … 120 118 # make image 121 119 image = self.get_image(qx_value, qy_value, sigma_1, sigma_2, 122 sigma_r, qx_min, qx_max, qy_min, qy_max,123 coord, False)120 sigma_r, qx_min, qx_max, qy_min, qy_max, 121 coord, False) 124 122 if qx_min > self.qx_min: 125 123 qx_min = self.qx_min … … 150 148 intens = self.setup_tof(lam, dlam) 151 149 out = self.get_image(qx_value, qy_value, sig1_list[ind], 152 153 150 sig2_list[ind], sigr_list[ind], 151 qx_min, qx_max, qy_min, qy_max, coord) 154 152 # this is the case of q being outside the detector 155 153 #if numpy.all(out==0.0): … … 272 270 # sigma in the radial/x direction 273 271 # for source aperture 274 sigma_1 272 sigma_1 = self.get_variance(rone, l1_cor, phi, comp1) 275 273 # for sample apperture 276 274 sigma_1 += self.get_variance(rtwo, lp_cor, phi, comp1) … … 279 277 # for gravity term for 1d 280 278 sigma_1grav1d = self.get_variance_gravity(l_ssa, l_sad, lamb, 281 lamb_spread, phi, comp1, 'on') / tof_factor279 lamb_spread, phi, comp1, 'on') / tof_factor 282 280 # for wavelength spread 283 281 # reserve for 1d calculation 284 282 A_value = self._cal_A_value(lamb, l_ssa, l_sad) 285 283 sigma_wave_1, sigma_wave_1_1d = self.get_variance_wave(A_value, 286 radius, l_two, lamb_spread,287 phi, 'radial', 'on')284 radius, l_two, lamb_spread, 285 phi, 'radial', 'on') 288 286 sigma_wave_1 /= tof_factor 289 287 sigma_wave_1_1d /= tof_factor … … 300 298 # sigma in the phi/y direction 301 299 # for source apperture 302 sigma_2 300 sigma_2 = self.get_variance(rone, l1_cor, phi, comp2) 303 301 304 302 # for sample apperture … … 310 308 # for gravity term for 1d 311 309 sigma_2grav1d = self.get_variance_gravity(l_ssa, l_sad, lamb, 312 lamb_spread, phi, comp2, 'on') / tof_factor310 lamb_spread, phi, comp2, 'on') / tof_factor 313 311 314 312 # for wavelength spread 315 313 # reserve for 1d calculation 316 314 sigma_wave_2, sigma_wave_2_1d = self.get_variance_wave(A_value, 317 radius, l_two, lamb_spread,318 phi, 'phi', 'on')315 radius, l_two, lamb_spread, 316 phi, 'phi', 'on') 319 317 sigma_wave_2 /= tof_factor 320 318 sigma_wave_2_1d /= tof_factor … … 377 375 378 376 # Check whether the q value is within the detector range 379 #msg = "Invalid input: Q value out of the detector range..."380 377 if qx_min < self.qx_min: 381 378 self.qx_min = qx_min … … 409 406 # Calculate the 2D Gaussian distribution image 410 407 image = self._gaussian2d_polar(q_1, q_2, qc_1, qc_2, 411 sigma_1, sigma_2, sigma_r)408 sigma_1, sigma_2, sigma_r) 412 409 else: 413 410 # catesian coordinate … … 452 449 # Image 453 450 im = plt.imshow(image, 454 extent=[qx_min, qx_max, qy_min, qy_max])451 extent=[qx_min, qx_max, qy_min, qy_max]) 455 452 456 453 # bilinear interpolation to make it smoother … … 506 503 raise ValueError, " Improper input..." 507 504 # get them squared 508 sigma 505 sigma = x_comp * x_comp 509 506 sigma += y_comp * y_comp 510 507 # normalize by distance … … 918 915 919 916 def _gaussian2d_polar(self, x_val, y_val, x0_val, y0_val, 920 sigma_x, sigma_y, sigma_r):917 sigma_x, sigma_y, sigma_r): 921 918 """ 922 919 Calculate 2D Gaussian distribution for polar coodinate … … 933 930 sigma_x = sqrt(sigma_x * sigma_x + sigma_r * sigma_r) 934 931 # call gaussian1d 935 gaussian 932 gaussian = self._gaussian1d(x_val, x0_val, sigma_x) 936 933 gaussian *= self._gaussian1d(y_val, y0_val, sigma_y) 937 934 … … 974 971 phi = math.atan2(qy_value, qx_value) 975 972 return phi 976 # default977 phi = 0978 # ToDo: This is misterious - sign???979 #qy_value = -qy_value980 # Take care of the singular point981 if qx_value == 0:982 if qy_value > 0:983 phi = pi / 2984 elif qy_value < 0:985 phi = -pi / 2986 else:987 phi = 0988 else:989 # the angle990 phi = math.atan2(qy_value, qx_value)991 992 return phi993 973 994 974 def _get_detector_qxqy_pixels(self): … … 1026 1006 detector_offset = self.sample2detector_distance[1] 1027 1007 except: 1028 pass1008 logging.error(sys.exc_value) 1029 1009 1030 1010 # detector size in [no of pix_x,no of pix_y] … … 1043 1023 # beam center position in pix number (start from 0) 1044 1024 center_x, center_y = self._get_beamcenter_position(detector_pix_nums_x, 1045 detector_pix_nums_y, offset_x, offset_y) 1025 detector_pix_nums_y, 1026 offset_x, offset_y) 1046 1027 # distance [cm] from the beam center on detector plane 1047 1028 detector_ind_x = numpy.arange(detector_pix_nums_x) … … 1088 1069 # i.e., edges of the last pixels. 1089 1070 self.qy_min += self._get_qx(-0.5 * pix_y_size, 1090 sample2detector_distance, wavelength)1071 sample2detector_distance, wavelength) 1091 1072 self.qy_max += self._get_qx(0.5 * pix_y_size, 1092 sample2detector_distance, wavelength)1073 sample2detector_distance, wavelength) 1093 1074 #if self.qx_min == self.qx_max: 1094 1075 self.qx_min += self._get_qx(-0.5 * pix_x_size, 1095 sample2detector_distance, wavelength)1076 sample2detector_distance, wavelength) 1096 1077 self.qx_max += self._get_qx(0.5 * pix_x_size, 1097 1078 sample2detector_distance, wavelength) … … 1108 1089 output = Data2D() 1109 1090 inten = numpy.zeros_like(qx_value) 1110 output.data 1091 output.data = inten 1111 1092 output.qx_data = qx_value 1112 1093 output.qy_data = qy_value 1113 1094 except: 1114 pass1095 logging.error(sys.exc_value) 1115 1096 1116 1097 return output -
src/sas/calculator/sas_gen.py
re3f77d8b rb6627d9 1 # pylint: disable=invalid-name 1 2 """ 2 3 SAS generic computation and sld file readers … … 9 10 import os 10 11 import copy 12 import sys 13 import logging 11 14 12 15 MFACTOR_AM = 2.853E-12 … … 285 288 mask = (x_dir2 + y_dir2 + z_dir2) <= 1.0 286 289 except: 287 pass290 logging.error(sys.exc_value) 288 291 self.output = MagSLD(self.pos_x[mask], self.pos_y[mask], 289 292 self.pos_z[mask], self.sld_n[mask], … … 394 397 except: 395 398 # Skip non-data lines 396 pass399 logging.error(sys.exc_value) 397 400 #Reading Header; Segment count ignored 398 401 s_line = line.split(":", 1) … … 589 592 z_lines.append(z_line) 590 593 except: 591 pass594 logging.error(sys.exc_value) 592 595 593 596 output = MagSLD(pos_x, pos_y, pos_z, sld_n, sld_mx, sld_my, sld_mz) … … 683 686 except: 684 687 # Skip non-data lines 685 pass688 logging.error(sys.exc_value) 686 689 output = MagSLD(pos_x, pos_y, pos_z, sld_n, 687 690 sld_mx, sld_my, sld_mz) … … 1037 1040 1038 1041 def test_load(): 1042 """ 1043 Test code 1044 """ 1039 1045 from sas.plottools.arrow3d import Arrow3D 1040 1046 current_dir = os.path.abspath(os.path.curdir) … … 1083 1089 ax.add_artist(a) 1084 1090 plt.show() 1091 1085 1092 def test(): 1093 """ 1094 Test code 1095 """ 1086 1096 current_dir = os.path.abspath(os.path.curdir) 1087 1097 for i in range(3): -
src/sas/calculator/slit_length_calculator.py
r6bd3a8d1 rb6627d9 57 57 58 58 # sum 10 or more y values until getting max_y, 59 while (True):59 while True: 60 60 if ind >= 10 and y_max == max_y: 61 61 break … … 72 72 ind = 0.0 73 73 # find indices where it crosses y = y_half. 74 while (True):74 while True: 75 75 # no need to check when ind == 0 76 76 ind += 1
Note: See TracChangeset
for help on using the changeset viewer.