Changeset 5f3164c in sasview for sanscalculator/src
- Timestamp:
- Sep 19, 2011 4:11:40 PM (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:
- 7400883
- Parents:
- 8fe5a50
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sanscalculator/src/sans/calculator/resolution_calculator.py
reaa7162 r5f3164c 46 46 # 1D total 47 47 self.sigma_1d = 0 48 self.gravity_phi = None 48 49 # q min and max 49 50 self.qx_min = -0.3 … … 139 140 self.qxrange = [qx_min, qx_max] 140 141 self.qyrange = [qy_min, qy_max] 141 142 #print qy_max+qy_min,qy_max,qy_min 142 143 sig1_list.append(sigma_1) 143 144 sig2_list.append(sigma_2) … … 283 284 # for detector pix 284 285 sigma_1 += self.get_variance(rthree, l_two, phi, comp1) 285 # for gravity term 286 sigma_1 += (self.get_variance_gravity(l_ssa, l_sad, lamb, lamb_spread,287 phi, comp1, 'on') / tof_factor )286 # for gravity term for 1d 287 sigma_1grav1d = self.get_variance_gravity(l_ssa, l_sad, lamb, lamb_spread, 288 phi, comp1, 'on') / tof_factor 288 289 # for wavelength spread 289 290 # reserve for 1d calculation 290 sigma_wave_1 = (self.get_variance_wave(radius, l_two, lamb_spread, 291 phi, 'radial', 'on') / tof_factor) 291 A_value = self._cal_A_value(lamb, l_ssa, l_sad) 292 sigma_wave_1, sigma_wave_1_1d = self.get_variance_wave(A_value, 293 radius, l_two, lamb_spread, 294 phi, 'radial', 'on') 295 sigma_wave_1 /= tof_factor 296 sigma_wave_1_1d /= tof_factor 292 297 # for 1d 293 variance_1d_1 = sigma_1/2 + sigma_wave_1298 variance_1d_1 = (sigma_1 + sigma_1grav1d) /2 + sigma_wave_1_1d 294 299 # normalize 295 300 variance_1d_1 = knot * knot * variance_1d_1 / 12 … … 310 315 sigma_2 += self.get_variance(rthree, l_two, phi, comp2) 311 316 312 # for gravity term 313 sigma_2 += (self.get_variance_gravity(l_ssa, l_sad, lamb, lamb_spread,314 phi, comp2, 'on') / tof_factor )317 # for gravity term for 1d 318 sigma_2grav1d = self.get_variance_gravity(l_ssa, l_sad, lamb, lamb_spread, 319 phi, comp2, 'on') / tof_factor 315 320 316 321 317 322 # for wavelength spread 318 323 # reserve for 1d calculation 319 sigma_wave_2 = (self.get_variance_wave(radius, l_two, lamb_spread, 320 phi, 'phi', 'on') / tof_factor) 324 sigma_wave_2, sigma_wave_2_1d = self.get_variance_wave(A_value, 325 radius, l_two, lamb_spread, 326 phi, 'phi', 'on') 327 sigma_wave_2 /= tof_factor 328 sigma_wave_2_1d /= tof_factor 321 329 # for 1d 322 variance_1d_2 = sigma_2 / 2 + sigma_wave_2330 variance_1d_2 = (sigma_2 + sigma_2grav1d) / 2 + sigma_wave_2_1d 323 331 # normalize 324 332 variance_1d_2 = knot*knot*variance_1d_2 / 12 … … 514 522 return sigma 515 523 516 def get_variance_wave(self, radius, distance, spread, phi,524 def get_variance_wave(self, A_value, radius, distance, spread, phi, 517 525 comp = 'radial', switch = 'on'): 518 526 """ … … 524 532 : comp: direction of the sigma; can be 'phi', 'y', 'x', and 'radial' 525 533 526 : return variance: sigma^2 534 : return variance: sigma^2 for 2d, sigma^2 for 1d [tuple] 527 535 """ 528 536 if switch.lower() == 'off': 529 return 0 537 return 0, 0 530 538 # check the singular point 531 539 if distance == 0 or comp == 'phi': 532 return 0 533 else: 540 return 0, 0 541 else: 542 # calculate sigma^2 for 1d 543 sigma1d = 2 * math.pow(radius/distance*spread, 2) 544 if comp == 'x': 545 sigma1d *= (math.cos(phi)*math.cos(phi)) 546 elif comp == 'y': 547 sigma1d *= (math.sin(phi)*math.sin(phi)) 548 else: 549 sigma1d *= 1 550 # sigma^2 for 2d 551 # shift the coordinate due to the gravitational shift 552 rad_x = radius * math.cos(phi) 553 rad_y = A_value - radius * math.sin(phi) 554 radius = math.sqrt(rad_x * rad_x + rad_y * rad_y) 555 # new phi 556 phi = math.atan2(-rad_y, rad_x) 557 self.gravity_phi = phi 534 558 # calculate sigma^2 535 559 sigma = 2 * math.pow(radius/distance*spread, 2) … … 541 565 sigma *= 1 542 566 543 return sigma 567 return sigma, sigma1d 544 568 545 569 def get_variance_gravity(self, s_distance, d_distance, wavelength, spread, … … 564 588 return 0 565 589 else: 566 # neutron mass in cgs unit 567 self.mass = self.get_neutron_mass() 568 # plank constant in cgs unit 569 h_constant = _PLANK_H 570 # gravity in cgs unit 571 gravy = _GRAVITY 572 # m/h 573 m_over_h = self.mass /h_constant 574 # A value 575 a_value = d_distance * (s_distance + d_distance) 576 a_value *= math.pow(m_over_h / 2, 2) 577 a_value *= gravy 578 # unit correction (1/cm to 1/A) for A and d_distance below 579 a_value *= 1.0E-16 580 590 a_value = self._cal_A_value(None, s_distance, d_distance) 581 591 # calculate sigma^2 582 592 sigma = math.pow(a_value / d_distance, 2) … … 592 602 593 603 return sigma 594 604 605 def _cal_A_value(self, lamda, s_distance, d_distance): 606 """ 607 Calculate A value for gravity 608 609 : s_distance: source to sample distance 610 : d_distance: sample to detector distance 611 """ 612 # neutron mass in cgs unit 613 self.mass = self.get_neutron_mass() 614 # plank constant in cgs unit 615 h_constant = _PLANK_H 616 # gravity in cgs unit 617 gravy = _GRAVITY 618 # m/h 619 m_over_h = self.mass /h_constant 620 # A value 621 a_value = d_distance * (s_distance + d_distance) 622 a_value *= math.pow(m_over_h / 2, 2) 623 a_value *= gravy 624 # unit correction (1/cm to 1/A) for A and d_distance below 625 a_value *= 1.0E-16 626 # if lamda is give (broad meanning of A) return 2* lamda^2 * A 627 if lamda != None: 628 a_value *= (4 * lamda * lamda) 629 return a_value 630 595 631 def get_intensity(self): 596 632 """ … … 880 916 y_value = y_val - y0_val 881 917 phi_i = numpy.arctan2(y_val, x_val) 882 883 sin_phi = numpy.sin(phi_i) 884 cos_phi = numpy.cos(phi_i) 918 919 # phi correction due to the gravity shift (in phi) 920 phi_0 = math.atan2(y0_val, x0_val) 921 phi_i = phi_i - phi_0 + self.gravity_phi 922 923 sin_phi = numpy.sin(self.gravity_phi) 924 cos_phi = numpy.cos(self.gravity_phi) 885 925 886 926 x_p = x_value * cos_phi + y_value * sin_phi
Note: See TracChangeset
for help on using the changeset viewer.