Changes in sasmodels/sesans.py [3c56da87:384d114] in sasmodels
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/sesans.py
r3c56da87 r384d114 12 12 import numpy as np 13 13 from numpy import pi, exp 14 15 14 from scipy.special import jv as besselj 16 15 17 def make_q(q_zmax, Rmax): 16 def make_q(q_max, Rmax): 17 r""" 18 Return a $q$ vector suitable for SESANS covering from $2\pi/ (10 R_{\max})$ 19 to $q_max$. 20 """ 18 21 q_min = dq = 0.1 * 2*pi / Rmax 19 #q_min = 0.00003 20 return np.arange(q_min, q_zmax, dq) 21 22 # TODO: dead code; for now the call to the hankel transform happens in BumpsModel 23 class SesansCalculator: 24 def __init__(self, kernel, q_zmax, Rmax, SElength, wavelength, thickness): 25 self._set_kernel(kernel, q_zmax, Rmax) 26 self.SElength = SElength 27 self.wavelength = wavelength 28 self.thickness = thickness 29 30 def _set_kernel(self, kernel, q_zmax, Rmax): 31 kernel_input = kernel.make_input([make_q(q_zmax, Rmax)]) 32 self.sans_calculator = kernel(kernel_input) 33 34 def __call__(self, pars, pd_pars, cutoff=1e-5): 35 Iq = self.sans_calculator(pars, pd_pars, cutoff) 36 P = hankel(self.SElength, self.wavelength, self.thickness, self.q, Iq) 37 self.Iq = Iq 38 return P 22 return np.arange(q_min, q_max, dq) 39 23 40 24 def hankel(SElength, wavelength, thickness, q, Iq): 41 """25 r""" 42 26 Compute the expected SESANS polarization for a given SANS pattern. 43 27 44 Uses the hankel transform followed by the exponential. The values 45 for zz (or spin echo length, or delta), wavelength and sample thickness46 information should come from the dataset. *q* should be chosen such47 that the oscillations in *I(q)* are well sampled (e.g., 5*2*pi/d_max).28 Uses the hankel transform followed by the exponential. The values for *zz* 29 (or spin echo length, or delta), wavelength and sample thickness should 30 come from the dataset. $q$ should be chosen such that the oscillations 31 in $I(q)$ are well sampled (e.g., $5 \cdot 2 \pi/d_{\max}$). 48 32 49 *SElength* [A] is the set of z points at which to compute the hankel transform 33 *SElength* [A] is the set of $z$ points at which to compute the 34 Hankel transform 50 35 51 36 *wavelength* [m] is the wavelength of each individual point *zz* … … 53 38 *thickness* [cm] is the sample thickness. 54 39 55 *q* [A ^{-1}] is the set of q points at which the model has been computed.56 These should be equally spaced.40 *q* [A$^{-1}$] is the set of $q$ points at which the model has been 41 computed. These should be equally spaced. 57 42 58 *I* [cm ^{-1}] is the value of the SANS model at *q*43 *I* [cm$^{-1}$] is the value of the SANS model at *q* 59 44 """ 60 45 G = np.zeros(len(SElength), 'd') 61 46 for i in range(len(SElength)): 62 integr = besselj(0, q*SElength[i])*Iq*q47 integr = besselj(0, q*SElength[i])*Iq*q 63 48 G[i] = np.sum(integr) 64 dq=(q[1]-q[0])*1e10 # [m^-1] step size in q, needed for integration 65 G *= dq*1e10*2*pi # integr step, conver q into [m**-1] and 2 pi circle integr 49 50 # [m^-1] step size in q, needed for integration 51 dq=(q[1]-q[0])*1e10 52 53 # integration step, convert q into [m**-1] and 2 pi circle integration 54 G *= dq*1e10*2*pi 55 66 56 P = exp(thickness*wavelength**2/(4*pi**2)*(G-G[0])) 67 57
Note: See TracChangeset
for help on using the changeset viewer.