Changeset 4d76711 in sasmodels for sasmodels/core.py
- Timestamp:
- Apr 5, 2016 10:33:44 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:
- 3a45c2c, c4e7a5f
- Parents:
- cd0a808
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/core.py
rb7172bb r4d76711 7 7 ] 8 8 9 10 9 from os.path import basename, dirname, join as joinpath, splitext 11 10 from glob import glob 12 import imp13 11 14 12 import numpy as np … … 40 38 return [np.asarray(v) for v in args] 41 39 40 # TODO: refactor composite model support 41 # The current load_model_info/build_model does not reuse existing model 42 # definitions when loading a composite model, instead reloading and 43 # rebuilding the kernel for each component model in the expression. This 44 # is fine in a scripting environment where the model is built when the script 45 # starts and is thrown away when the script ends, but may not be the best 46 # solution in a long-lived application. This affects the following functions: 47 # 48 # load_model 49 # load_model_info 50 # build_model 42 51 43 52 def list_models(): … … 64 73 return build_model(load_model_info(model_name), **kw) 65 74 66 def load_model_info_from_path(path):67 # Pull off the last .ext if it exists; there may be others68 name = basename(splitext(path)[0])69 70 # Not cleaning name since don't need to be able to reload this71 # model later72 # Should probably turf the model from sys.modules after we are done...73 74 # Placing the model in the 'sasmodels.custom' name space, even75 # though it doesn't actually exist. imp.load_source doesn't seem76 # to care.77 kernel_module = imp.load_source('sasmodels.custom.'+name, path)78 79 # Now that we have the module, we can load it as usual80 model_info = generate.make_model_info(kernel_module)81 return model_info82 75 83 76 def load_model_info(model_name): … … 102 95 return product.make_product_info(P_info, Q_info) 103 96 104 #import sys; print "\n".join(sys.path) 105 __import__('sasmodels.models.'+model_name) 106 kernel_module = getattr(models, model_name, None) 97 kernel_module = generate.load_kernel_module(model_name) 107 98 return generate.make_model_info(kernel_module) 108 99 … … 179 170 180 171 181 def make_kernel(model, q_vectors):182 """183 Return a computation kernel from the model definition and the q input.184 """185 return model(q_vectors)186 187 172 def get_weights(model_info, pars, name): 188 173 """ … … 220 205 def call_kernel(kernel, pars, cutoff=0, mono=False): 221 206 """ 222 Call *kernel* returned from :func:`make_kernel`with parameters *pars*.207 Call *kernel* returned from *model.make_kernel* with parameters *pars*. 223 208 224 209 *cutoff* is the limiting value for the product of dispersion weights used … … 228 213 with an error of about 1%, which is usually less than the measurement 229 214 uncertainty. 215 216 *mono* is True if polydispersity should be set to none on all parameters. 230 217 """ 231 218 fixed_pars = [pars.get(name, kernel.info['defaults'][name]) … … 259 246 260 247 261 def call_ER( info, pars):262 """ 263 Call the model ER function using * pars*.264 * info* is either *model.info* if you have a loaded model, or *kernel.info*265 if youhave a model kernel prepared for evaluation.266 """ 267 ER = info.get('ER', None)248 def call_ER(model_info, values): 249 """ 250 Call the model ER function using *values*. *model_info* is either 251 *model.info* if you have a loaded model, or *kernel.info* if you 252 have a model kernel prepared for evaluation. 253 """ 254 ER = model_info.get('ER', None) 268 255 if ER is None: 269 256 return 1.0 270 257 else: 271 vol_pars = [get_weights( info, pars, name)272 for name in info['partype']['volume']]258 vol_pars = [get_weights(model_info, values, name) 259 for name in model_info['partype']['volume']] 273 260 value, weight = dispersion_mesh(vol_pars) 274 261 individual_radii = ER(*value) … … 276 263 return np.sum(weight*individual_radii) / np.sum(weight) 277 264 278 def call_VR( info, pars):265 def call_VR(model_info, values): 279 266 """ 280 267 Call the model VR function using *pars*. … … 282 269 if you have a model kernel prepared for evaluation. 283 270 """ 284 VR = info.get('VR', None)271 VR = model_info.get('VR', None) 285 272 if VR is None: 286 273 return 1.0 287 274 else: 288 vol_pars = [get_weights( info, pars, name)289 for name in info['partype']['volume']]275 vol_pars = [get_weights(model_info, values, name) 276 for name in model_info['partype']['volume']] 290 277 value, weight = dispersion_mesh(vol_pars) 291 278 whole, part = VR(*value)
Note: See TracChangeset
for help on using the changeset viewer.