Changeset c1799d3 in sasmodels for sasmodels/direct_model.py
- Timestamp:
- Nov 9, 2018 12:16:05 PM (5 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- c11d09f
- Parents:
- 17695aa (diff), cf3d0ce (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/direct_model.py
rb6d1d52 rc1799d3 31 31 from . import resolution2d 32 32 from .details import make_kernel_args, dispersion_mesh 33 from .modelinfo import DEFAULT_BACKGROUND 34 from .product import RADIUS_MODE_ID 33 35 34 36 # pylint: disable=unused-import … … 63 65 return calculator(call_details, values, cutoff, is_magnetic) 64 66 65 def call_ER(model_info, pars): 66 # type: (ModelInfo, ParameterSet) -> float 67 """ 68 Call the model ER function using *values*. 69 70 *model_info* is either *model.info* if you have a loaded model, 71 or *kernel.info* if you have a model kernel prepared for evaluation. 72 """ 73 if model_info.ER is None: 74 return 1.0 75 elif not model_info.parameters.form_volume_parameters: 76 # handle the case where ER is provided but model is not polydisperse 77 return model_info.ER() 78 else: 79 value, weight = _vol_pars(model_info, pars) 80 individual_radii = model_info.ER(*value) 81 return np.sum(weight*individual_radii) / np.sum(weight) 82 83 84 def call_VR(model_info, pars): 85 # type: (ModelInfo, ParameterSet) -> float 86 """ 87 Call the model VR function using *pars*. 88 89 *model_info* is either *model.info* if you have a loaded model, 90 or *kernel.info* if you have a model kernel prepared for evaluation. 91 """ 92 if model_info.VR is None: 93 return 1.0 94 elif not model_info.parameters.form_volume_parameters: 95 # handle the case where ER is provided but model is not polydisperse 96 return model_info.VR() 97 else: 98 value, weight = _vol_pars(model_info, pars) 99 whole, part = model_info.VR(*value) 100 return np.sum(weight*part)/np.sum(weight*whole) 101 102 103 def call_profile(model_info, **pars): 104 # type: (ModelInfo, ...) -> Tuple[np.ndarray, np.ndarray, Tuple[str, str]] 67 def call_Fq(calculator, pars, cutoff=0., mono=False): 68 # type: (Kernel, ParameterSet, float, bool) -> np.ndarray 69 """ 70 Like :func:`call_kernel`, but returning F, F^2, R_eff, V_shell, V_form/V_shell. 71 72 For solid objects V_shell is equal to V_form and the volume ratio is 1. 73 74 Use parameter *radius_effective_mode* to select the effective radius 75 calculation. 76 """ 77 R_eff_type = int(pars.pop(RADIUS_MODE_ID, 1.0)) 78 mesh = get_mesh(calculator.info, pars, dim=calculator.dim, mono=mono) 79 #print("pars", list(zip(*mesh))[0]) 80 call_details, values, is_magnetic = make_kernel_args(calculator, mesh) 81 #print("values:", values) 82 return calculator.Fq(call_details, values, cutoff, is_magnetic, R_eff_type) 83 84 def call_profile(model_info, pars=None): 85 # type: (ModelInfo, ParameterSet) -> Tuple[np.ndarray, np.ndarray, Tuple[str, str]] 105 86 """ 106 87 Returns the profile *x, y, (xlabel, ylabel)* representing the model. 107 88 """ 89 if pars is None: 90 pars = {} 108 91 args = {} 109 92 for p in model_info.parameters.kernel_parameters: … … 403 386 Generate a plottable profile. 404 387 """ 405 return call_profile(self.model.info, **pars)388 return call_profile(self.model.info, pars) 406 389 407 390 def main(): … … 419 402 model_name = sys.argv[1] 420 403 call = sys.argv[2].upper() 421 if call != "ER_VR": 422 try: 423 values = [float(v) for v in call.split(',')] 424 except ValueError: 425 values = [] 426 if len(values) == 1: 427 q, = values 428 data = empty_data1D([q]) 429 elif len(values) == 2: 430 qx, qy = values 431 data = empty_data2D([qx], [qy]) 432 else: 433 print("use q or qx,qy or ER or VR") 434 sys.exit(1) 404 try: 405 values = [float(v) for v in call.split(',')] 406 except ValueError: 407 values = [] 408 if len(values) == 1: 409 q, = values 410 data = empty_data1D([q]) 411 elif len(values) == 2: 412 qx, qy = values 413 data = empty_data2D([qx], [qy]) 435 414 else: 436 data = empty_data1D([0.001]) # Data not used in ER/VR 415 print("use q or qx,qy") 416 sys.exit(1) 437 417 438 418 model_info = load_model_info(model_name) … … 442 422 for pair in sys.argv[3:] 443 423 for k, v in [pair.split('=')]) 444 if call == "ER_VR": 445 ER = call_ER(model_info, pars) 446 VR = call_VR(model_info, pars) 447 print(ER, VR) 448 else: 449 Iq = calculator(**pars) 450 print(Iq[0]) 424 Iq = calculator(**pars) 425 print(Iq[0]) 451 426 452 427 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.