- Timestamp:
- Mar 18, 2016 4:16:21 AM (8 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 30c2ac3
- Parents:
- 02e70ff (diff), c094758 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- sasmodels
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/data.py
r84db7a5 rc094758 178 178 self.qy_data, self.dqy_data = y, dy 179 179 self.data, self.err_data = z, dz 180 self.mask = ( ~np.isnan(z) if z is not None181 else np. ones_like(x) if x is not None180 self.mask = (np.isnan(z) if z is not None 181 else np.zeros_like(x, dtype='bool') if x is not None 182 182 else None) 183 183 self.q_data = np.sqrt(x**2 + y**2) -
sasmodels/kernelcl.py
r17bbadd rc094758 367 367 self.q_vectors = [_stretch_input(q, self.dtype, 32) for q in q_vectors] 368 368 context = env.get_context(self.dtype) 369 self.global_size = [self.q_vectors[0].size] 370 #print("creating inputs of size", self.global_size) 369 371 self.q_buffers = [ 370 372 cl.Buffer(context, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=q) 371 373 for q in self.q_vectors 372 374 ] 373 self.global_size = [self.q_vectors[0].size]374 375 375 376 def release(self): -
sasmodels/models/bessel.py
r07142f3 rcbd37a7 67 67 #Bessel 68 68 parameters = [ 69 ["ignored", "", 0.0, [-inf, inf], "", "no parameterless functions"], 69 70 ] 70 71 71 source = ["lib/polevl.c", "lib/j1 d.c"]72 source = ["lib/polevl.c", "lib/j1_cephes.c"] 72 73 73 74 # No volume normalization despite having a volume parameter … … 77 78 78 79 Iq = """ 79 return j1(q);80 return 2.0*j1(q)/q; 80 81 """ 81 82 -
sasmodels/models/lib/j0_cephes.c
rbfef528 r094e320 44 44 */ 45 45 46 /* y0.c47 *48 * Bessel function of the second kind, order zero49 *50 *51 *52 * SYNOPSIS:53 *54 * double x, y, y0();55 *56 * y = y0( x );57 *58 *59 *60 * DESCRIPTION:61 *62 * Returns Bessel function of the second kind, of order63 * zero, of the argument.64 *65 * The domain is divided into the intervals [0, 5] and66 * (5, infinity). In the first interval a rational approximation67 * R(x) is employed to compute68 * y0(x) = R(x) + 2 * log(x) * j0(x) / PI.69 * Thus a call to j0() is required.70 *71 * In the second interval, the Hankel asymptotic expansion72 * is employed with two rational functions of degree 6/673 * and 7/7.74 *75 *76 *77 * ACCURACY:78 *79 * Absolute error, when y0(x) < 1; else relative error:80 *81 * arithmetic domain # trials peak rms82 * DEC 0, 30 9400 7.0e-17 7.9e-1883 * IEEE 0, 30 30000 1.3e-15 1.6e-1684 *85 */86 87 46 88 47 /* … … 95 54 96 55 double j0( double ); 97 98 56 double j0(double x) { 99 57 … … 291 249 292 250 q = 1.0/x; 293 w = sqrt f(q);251 w = sqrt(q); 294 252 295 253 p = w * polevl( q, MO, 7); 296 254 w = q*q; 297 255 xn = q * polevl( w, PH, 7) - PIO4F; 298 p = p * cos f(xn + xx);256 p = p * cos(xn + xx); 299 257 return(p); 300 258 #endif -
sasmodels/models/lib/j1_cephes.c
rbfef528 re2af2a9 32 32 * IEEE 0, 30 30000 2.6e-16 1.1e-16 33 33 * 34 *35 */36 /* y1.c37 *38 * Bessel function of second kind of order one39 *40 *41 *42 * SYNOPSIS:43 *44 * double x, y, y1();45 *46 * y = y1( x );47 *48 *49 *50 * DESCRIPTION:51 *52 * Returns Bessel function of the second kind of order one53 * of the argument.54 *55 * The domain is divided into the intervals [0, 8] and56 * (8, infinity). In the first interval a 25 term Chebyshev57 * expansion is used, and a call to j1() is required.58 * In the second, the asymptotic trigonometric representation59 * is employed using two rational functions of degree 5/5.60 *61 *62 *63 * ACCURACY:64 *65 * Absolute error:66 * arithmetic domain # trials peak rms67 * DEC 0, 30 10000 8.6e-17 1.3e-1768 * IEEE 0, 30 30000 1.0e-15 1.3e-1669 *70 * (error criterion relative when |y1| > 1).71 34 * 72 35 */ -
sasmodels/models/lib/polevl.c
r3936ad3 re2af2a9 50 50 Direct inquiries to 30 Frost Street, Cambridge, MA 02140 51 51 */ 52 52 53 double polevl( double x, double coef[8], int N ); 53 54 double p1evl( double x, double coef[8], int N ); -
sasmodels/core.py
r7b3e62c r02e70ff 176 176 return value, weight 177 177 178 def call_kernel(kernel, pars, cutoff=0 ):178 def call_kernel(kernel, pars, cutoff=0, mono=False): 179 179 """ 180 180 Call *kernel* returned from :func:`make_kernel` with parameters *pars*. … … 189 189 fixed_pars = [pars.get(name, kernel.info['defaults'][name]) 190 190 for name in kernel.fixed_pars] 191 pd_pars = [get_weights(kernel.info, pars, name) for name in kernel.pd_pars] 191 if mono: 192 pd_pars = [( np.array([pars[name]]), np.array([1.0]) ) 193 for name in kernel.pd_pars] 194 else: 195 pd_pars = [get_weights(kernel.info, pars, name) for name in kernel.pd_pars] 192 196 return kernel(fixed_pars, pd_pars, cutoff=cutoff) 193 197 -
sasmodels/direct_model.py
r17bbadd r02e70ff 69 69 70 70 if self.data_type == 'sesans': 71 71 72 q = sesans.make_q(data.sample.zacceptance, data.Rmax) 72 73 index = slice(None, None) … … 77 78 Iq, dIq = None, None 78 79 #self._theory = np.zeros_like(q) 79 q_vectors = [q] 80 q_vectors = [q] 81 q_mono = sesans.make_all_q(data) 80 82 elif self.data_type == 'Iqxy': 81 83 if not partype['orientation'] and not partype['magnetic']: … … 96 98 #self._theory = np.zeros_like(self.Iq) 97 99 q_vectors = res.q_calc 100 q_mono = [] 98 101 elif self.data_type == 'Iq': 99 102 index = (data.x >= data.qmin) & (data.x <= data.qmax) … … 120 123 #self._theory = np.zeros_like(self.Iq) 121 124 q_vectors = [res.q_calc] 125 q_mono = [] 122 126 else: 123 127 raise ValueError("Unknown data type") # never gets here … … 125 129 # Remember function inputs so we can delay loading the function and 126 130 # so we can save/restore state 127 self._kernel_inputs = [v for v in q_vectors] 131 self._kernel_inputs = q_vectors 132 self._kernel_mono_inputs = q_mono 128 133 self._kernel = None 129 134 self.Iq, self.dIq, self.index = Iq, dIq, index … … 149 154 def _calc_theory(self, pars, cutoff=0.0): 150 155 if self._kernel is None: 151 self._kernel = make_kernel(self._model, self._kernel_inputs) # pylint: disable=attribute-defined-outside-init 156 self._kernel = make_kernel(self._model, self._kernel_inputs) # pylint: disable=attribute-dedata_type 157 self._kernel_mono = make_kernel(self._model, self._kernel_mono_inputs) if self._kernel_mono_inputs else None 152 158 153 159 Iq_calc = call_kernel(self._kernel, pars, cutoff=cutoff) 160 Iq_mono = call_kernel(self._kernel_mono, pars, mono=True) if self._kernel_mono_inputs else None 154 161 if self.data_type == 'sesans': 155 result = sesans. hankel(self._data.x, self._data.lam * 1e-9,156 self._ data.sample.thickness / 10,157 self._kernel_ inputs[0], Iq_calc)162 result = sesans.transform(self._data, 163 self._kernel_inputs[0], Iq_calc, 164 self._kernel_mono_inputs, Iq_mono) 158 165 else: 159 166 result = self.resolution.apply(Iq_calc) 160 return result 167 return result 161 168 162 169 -
sasmodels/sesans.py
r190fc2b r02e70ff 13 13 from numpy import pi, exp 14 14 from scipy.special import jv as besselj 15 15 #import direct_model.DataMixin as model 16 16 17 def make_q(q_max, Rmax): 17 18 r""" … … 21 22 q_min = dq = 0.1 * 2*pi / Rmax 22 23 return np.arange(q_min, q_max, dq) 24 25 def make_allq(data): 26 if not data.needs_all_q: 27 return [] 28 elif needs_Iqxy(data): 29 # compute qx, qy 30 Qx, Qy = np.meshgrid(qx, qy) 31 return [Qx, Qy] 32 else: 33 # else only need q 34 return [q] 23 35 36 def transform(data, q_calc, Iq_calc, qmono, Iq_mono): 37 nqmono = len(qmono) 38 if nqmono == 0: 39 result = call_hankel(data, q_calc, Iq_calc) 40 elif nqmono == 1: 41 q = qmono[0] 42 result = call_HankelAccept(data, q_calc, Iq_calc, q, Iq_mono) 43 else: 44 Qx, Qy = [qmono[0], qmono[1]] 45 Qx = np.reshape(Qx, nqx, nqy) 46 Qy = np.reshape(Qy, nqx, nqy) 47 Iq_mono = np.reshape(Iq_mono, nqx, nqy) 48 qx = Qx[0, :] 49 qy = Qy[:, 0] 50 result = call_Cosine2D(data, q_calc, Iq_calc, qx, qy, Iq_mono) 51 52 return result 53 54 def call_hankel(data, q_calc, Iq_calc): 55 return hankel(data.x, data.lam * 1e-9, 56 data.sample.thickness / 10, 57 q_calc, Iq_calc) 58 59 def call_HankelAccept(data, q_calc, Iq_calc, q_mono, Iq_mono): 60 return hankel(data.x, data.lam * 1e-9, 61 data.sample.thickness / 10, 62 q_calc, Iq_calc) 63 64 def Cosine2D(data, q_calc, Iq_calc, qx, qy, Iq_mono): 65 return hankel(data.x, data.y data.lam * 1e-9, 66 data.sample.thickness / 10, 67 q_calc, Iq_calc) 68 69 def TotalScatter(model, parameters): #Work in progress!! 70 # Calls a model with existing model parameters already in place, then integrate the product of q and I(q) from 0 to (4*pi/lambda) 71 allq = np.linspace(0,4*pi/wavelength,1000) 72 allIq = 73 integral = allq*allIq 74 75 76 77 def Cosine2D(wavelength, magfield, thickness, qy, qz, Iqy, Iqz, modelname): #Work in progress!! Needs to call model still 78 #============================================================================== 79 # 2D Cosine Transform if "wavelength" is a vector 80 #============================================================================== 81 #allq is the q-space needed to create the total scattering cross-section 82 83 Gprime = np.zeros_like(wavelength, 'd') 84 s = np.zeros_like(wavelength, 'd') 85 sd = np.zeros_like(wavelength, 'd') 86 Gprime = np.zeros_like(wavelength, 'd') 87 f = np.zeros_like(wavelength, 'd') 88 for i, wavelength_i in enumerate(wavelength): 89 z = magfield*wavelength_i 90 allq=np.linspace() #for calculating the Q-range of the scattering power integral 91 allIq=np.linspace() # This is the model applied to the allq q-space. Needs to refference the model somehow 92 alldq = (allq[1]-allq[0])*1e10 93 sigma[i]=wavelength[i]^2*thickness/2/pi*np.sum(allIq*allq*alldq) 94 s[i]=1-exp(-sigma) 95 for j, Iqy_j, qy_j in enumerate(qy): 96 for k, Iqz_k, qz_k in enumerate(qz): 97 Iq = np.sqrt(Iqy_j^2+Iqz_k^2) 98 q = np.sqrt(qy_j^2 + qz_k^2) 99 Gintegral = Iq*cos(z*Qz_k) 100 Gprime[i] += Gintegral 101 # sigma = wavelength^2*thickness/2/pi* allq[i]*allIq[i] 102 # s[i] += 1-exp(Totalscatter(modelname)*thickness) 103 # For now, work with standard 2-phase scatter 104 105 106 sd[i] += Iq 107 f[i] = 1-s[i]+sd[i] 108 P[i] = (1-sd[i]/f[i])+1/f[i]*Gprime[i] 109 110 111 112 113 def HankelAccept(wavelength, magfield, thickness, q, Iq, theta, modelname): 114 #============================================================================== 115 # HankelTransform with fixed circular acceptance angle (circular aperture) for Time of Flight SESANS 116 #============================================================================== 117 #acceptq is the q-space needed to create limited acceptance effect 118 SElength= wavelength*magfield 119 G = np.zeros_like(SElength, 'd') 120 threshold=2*pi*theta/wavelength 121 for i, SElength_i in enumerate(SElength): 122 allq=np.linspace() #for calculating the Q-range of the scattering power integral 123 allIq=np.linspace() # This is the model applied to the allq q-space. Needs to refference the model somehow 124 alldq = (allq[1]-allq[0])*1e10 125 sigma[i]=wavelength[i]^2*thickness/2/pi*np.sum(allIq*allq*alldq) 126 s[i]=1-exp(-sigma) 127 128 dq = (q[1]-q[0])*1e10 129 a = (x<threshold) 130 acceptq = a*q 131 acceptIq = a*Iq 132 133 G[i] = np.sum(besselj(0, acceptq*SElength_i)*acceptIq*acceptq*dq) 134 135 # G[i]=np.sum(integral) 136 137 G *= dq*1e10*2*pi 138 139 P = exp(thickness*wavelength**2/(4*pi**2)*(G-G[0])) 140 24 141 def hankel(SElength, wavelength, thickness, q, Iq): 25 142 r""" … … 44 161 """ 45 162 G = np.zeros_like(SElength, 'd') 163 #============================================================================== 164 # Hankel Transform method if "wavelength" is a scalar; mono-chromatic SESANS 165 #============================================================================== 46 166 for i, SElength_i in enumerate(SElength): 47 167 integral = besselj(0, q*SElength_i)*Iq*q
Note: See TracChangeset
for help on using the changeset viewer.