Changeset 3c56da87 in sasmodels for sasmodels/kernelpy.py
- Timestamp:
- Mar 4, 2015 10:55:38 PM (9 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:
- 3a45c2c
- Parents:
- b89f519
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/kernelpy.py
rc85db69 r3c56da87 7 7 def __init__(self, info): 8 8 self.info = info 9 def __call__(self, input_value): 10 kernel = self.info['Iqxy'] if input_value.is_2D else self.info['Iq'] 11 return PyKernel(kernel, self.info, input_value) 9 10 def __call__(self, q_input): 11 kernel = self.info['Iqxy'] if q_input.is_2D else self.info['Iq'] 12 return PyKernel(kernel, self.info, q_input) 13 14 # pylint: disable=no-self-use 12 15 def make_input(self, q_vectors): 13 16 return PyInput(q_vectors, dtype=F64) 17 14 18 def release(self): 15 19 pass … … 52 56 *info* is the module information 53 57 54 * input* is the DllInput q vectors at which the kernel should be58 *q_input* is the DllInput q vectors at which the kernel should be 55 59 evaluated. 56 60 … … 63 67 Call :meth:`release` when done with the kernel instance. 64 68 """ 65 def __init__(self, kernel, info, input):69 def __init__(self, kernel, info, q_input): 66 70 self.info = info 67 self. input =input68 self.res = np.empty( input.nq,input.dtype)69 dim = '2d' if input.is_2D else '1d'71 self.q_input = q_input 72 self.res = np.empty(q_input.nq, q_input.dtype) 73 dim = '2d' if q_input.is_2D else '1d' 70 74 # Loop over q unless user promises that the kernel is vectorized by 71 75 # taggining it with vectorized=True … … 73 77 if dim == '2d': 74 78 def vector_kernel(qx, qy, *args): 75 return np.array([kernel(qxi, qyi, *args) for qxi, qyi in zip(qx, qy)]) 79 return np.array([kernel(qxi, qyi, *args) 80 for qxi, qyi in zip(qx, qy)]) 76 81 else: 77 82 def vector_kernel(q, *args): 78 return np.array([kernel(qi, *args) for qi in q]) 83 return np.array([kernel(qi, *args) 84 for qi in q]) 79 85 self.kernel = vector_kernel 80 86 else: … … 86 92 # First two fixed pars are scale and background 87 93 pars = [p[0] for p in info['parameters'][2:]] 88 offset = len(self.input.q_vectors) 89 self.args = self.input.q_vectors + [None] * len(pars) 90 self.fixed_index = np.array([pars.index(p) + offset for p in fixed_pars[2:]]) 91 self.pd_index = np.array([pars.index(p) + offset for p in pd_pars]) 92 self.vol_index = np.array([pars.index(p) + offset for p in vol_pars]) 94 offset = len(self.q_input.q_vectors) 95 self.args = self.q_input.q_vectors + [None] * len(pars) 96 self.fixed_index = np.array([pars.index(p) + offset 97 for p in fixed_pars[2:]]) 98 self.pd_index = np.array([pars.index(p) + offset 99 for p in pd_pars]) 100 self.vol_index = np.array([pars.index(p) + offset 101 for p in vol_pars]) 93 102 try: self.theta_index = pars.index('theta') + offset 94 103 except ValueError: self.theta_index = -1 … … 113 122 114 123 def release(self): 115 self. input = None124 self.q_input = None 116 125 117 126 def _loops(form, form_volume, cutoff, scale, background, … … 194 203 args[pd_index[0]] = fast_value[fast_index] 195 204 weight[0] = fast_weight[fast_index] 196 # This computes the weight, and if it is sufficient, calls the scattering197 # function and adds it to the total. If there is a volume normalization,198 # it will also be added here.205 # This computes the weight, and if it is sufficient, calls the 206 # scattering function and adds it to the total. If there is a volume 207 # normalization, it will also be added here. 199 208 # Note: make sure this is consistent with the code in PY_LOOP_BODY!! 200 209 # Note: can precompute w1*w2*...*wn … … 204 213 positive = (I >= 0.0) 205 214 206 # Note: can precompute spherical correction if theta_index is not the fast index 207 # Correction factor for spherical integration p(theta) I(q) sin(theta) dtheta 208 #spherical_correction = abs(sin(pi*args[theta_index])) if theta_index>=0 else 1.0 209 spherical_correction = abs(cos(pi * args[theta_index])) * pi / 2 if theta_index >= 0 else 1.0 215 # Note: can precompute spherical correction if theta_index is not 216 # the fast index. Correction factor for spherical integration 217 #spherical_correction = abs(cos(pi*args[phi_index])) if phi_index>=0 else 1.0 218 spherical_correction = (abs(cos(pi * args[theta_index])) * pi / 2 219 if theta_index >= 0 else 1.0) 210 220 #spherical_correction = 1.0 211 221 ret += w * I * spherical_correction * positive … … 213 223 214 224 # Volume normalization. 215 # If there are "volume" polydispersity parameters, then these will be used216 # to call the form_volume function from the user supplied kernel, and accumulate217 # a normalized weight.218 # Note: can precompute volume norm if the fast index is not a volume index225 # If there are "volume" polydispersity parameters, then these 226 # will be used to call the form_volume function from the user 227 # supplied kernel, and accumulate a normalized weight. 228 # Note: can precompute volume norm if fast index is not a volume 219 229 if form_volume: 220 230 vol_args = [args[index] for index in vol_index]
Note: See TracChangeset
for help on using the changeset viewer.