Changeset 8698a0d in sasmodels for sasmodels/details.py
- Timestamp:
- Oct 17, 2017 9:53:01 PM (6 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 32f87a5
- Parents:
- becded3
- git-author:
- Paul Kienzle <pkienzle@…> (10/17/17 16:23:09)
- git-committer:
- Paul Kienzle <pkienzle@…> (10/17/17 21:53:01)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/details.py
rf39759c r8698a0d 219 219 220 220 ZEROS = tuple([0.]*31) 221 def make_kernel_args(kernel, pairs):221 def make_kernel_args(kernel, mesh): 222 222 # type: (Kernel, Tuple[List[np.ndarray], List[np.ndarray]]) -> Tuple[CallDetails, np.ndarray, bool] 223 223 """ 224 Converts (value, weight) pairs into parameters for the kernel call.224 Converts (value, dispersity, weight) for each parameter into kernel pars. 225 225 226 226 Returns a CallDetails object indicating the polydispersity, a data object … … 231 231 npars = kernel.info.parameters.npars 232 232 nvalues = kernel.info.parameters.nvalues 233 scalars = [ (v[0] if len(v) else np.NaN) for v, w in pairs]233 scalars = [value for value, dispersity, weight in mesh] 234 234 # skipping scale and background when building values and weights 235 values, weights = zip(*pairs[2:npars+2]) if npars else ((), ())236 weights = correct_theta_weights(kernel.info.parameters, values, weights)235 values, dispersity, weights = zip(*mesh[2:npars+2]) if npars else ((), (), ()) 236 #weights = correct_theta_weights(kernel.info.parameters, values, weights) 237 237 length = np.array([len(w) for w in weights]) 238 238 offset = np.cumsum(np.hstack((0, length))) 239 239 call_details = make_details(kernel.info, length, offset[:-1], offset[-1]) 240 240 # Pad value array to a 32 value boundaryd 241 data_len = nvalues + 2*sum(len(v) for v in values)241 data_len = nvalues + 2*sum(len(v) for v in dispersity) 242 242 extra = (32 - data_len%32)%32 243 data = np.hstack((scalars,) + values+ weights + ZEROS[:extra])243 data = np.hstack((scalars,) + dispersity + weights + ZEROS[:extra]) 244 244 data = data.astype(kernel.dtype) 245 245 is_magnetic = convert_magnetism(kernel.info.parameters, data) … … 294 294 295 295 296 def dispersion_mesh(model_info, pars):296 def dispersion_mesh(model_info, mesh): 297 297 # type: (ModelInfo) -> Tuple[List[np.ndarray], List[np.ndarray]] 298 298 """ 299 299 Create a mesh grid of dispersion parameters and weights. 300 300 301 pars is a list of pairs (values, weights), where the values are the302 individual parameter values at which to evaluate the polydispersity303 distribution and weights are the weights associated with each value.301 *mesh* is a list of (value, dispersity, weights), where the values 302 are the individual parameter values, and (dispersity, weights) is 303 the distribution of parameter values. 304 304 305 305 Only the volume parameters should be included in this list. Orientation 306 306 parameters do not affect the calculation of effective radius or volume 307 ratio. 307 ratio. This is convenient since it avoids the distinction between 308 value and dispersity that is present in orientation parameters but not 309 shape parameters. 308 310 309 311 Returns [p1,p2,...],w where pj is a vector of values for parameter j … … 311 313 parameter set in the vector. 312 314 """ 313 value, weight = zip(*pars)315 value, dispersity, weight = zip(*mesh) 314 316 #weight = [w if len(w)>0 else [1.] for w in weight] 315 317 weight = np.vstack([v.flatten() for v in meshgrid(*weight)]) 316 318 weight = np.prod(weight, axis=0) 317 value = [v.flatten() for v in meshgrid(*value)]319 dispersity = [v.flatten() for v in meshgrid(*dispersity)] 318 320 lengths = [par.length for par in model_info.parameters.kernel_parameters 319 321 if par.type == 'volume'] … … 322 324 offset = 0 323 325 for n in lengths: 324 pars.append(np.vstack( value[offset:offset+n])325 if n > 1 else value[offset])326 pars.append(np.vstack(dispersity[offset:offset+n]) 327 if n > 1 else dispersity[offset]) 326 328 offset += n 327 value= pars328 return value, weight329 dispersity = pars 330 return dispersity, weight
Note: See TracChangeset
for help on using the changeset viewer.