Changeset 117c02a in sasmodels
- Timestamp:
- Sep 3, 2018 7:20:35 AM (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:
- c0131d44
- Parents:
- bad3093
- Location:
- sasmodels
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/product.py
r6d90684 r117c02a 13 13 from __future__ import print_function, division 14 14 15 from collections import OrderedDict 16 15 17 from copy import copy 16 18 import numpy as np # type: ignore … … 22 24 # pylint: disable=unused-import 23 25 try: 24 from typing import Tuple 26 from typing import Tuple, Callable 25 27 except ImportError: 26 28 pass … … 37 39 ER_ID = "radius_effective" 38 40 VF_ID = "volfraction" 39 BETA_DEFINITION = ("beta_mode", "", 0, [["P*S"],["P*(1+beta*(S-1))"]], "",41 BETA_DEFINITION = ("beta_mode", ["P*S", "P*(1+beta*(S-1))"], 0, (None, None), "", 40 42 "Structure factor dispersion calculation mode") 43 def make_extra_pars(p_info): 44 pars = [] 45 if p_info.have_Fq: 46 par = Parameter("structure_factor_mode", ["P*S","P*(1+beta*(S-1))"], 0, (None, None), "", 47 "Structure factor calculation") 48 pars.append(par) 49 return pars 41 50 42 51 # TODO: core_shell_sphere model has suppressed the volume ratio calculation … … 76 85 translate_name = dict((old.id, new.id) for old, new 77 86 in zip(s_pars.kernel_parameters[1:], s_list)) 78 beta = [Parameter(*BETA_DEFINITION)] if p_info.have_Fq else [] 79 combined_pars = p_pars.kernel_parameters + s_list + beta 87 combined_pars = p_pars.kernel_parameters + s_list + make_extra_pars(p_info) 80 88 parameters = ParameterTable(combined_pars) 81 89 parameters.max_pd = p_pars.max_pd + s_pars.max_pd … … 145 153 return par 146 154 155 def _intermediates(P, S): 156 # type: (np.ndarray, np.ndarray) -> OrderedDict[str, np.ndarray] 157 """ 158 Returns intermediate results for standard product (P(Q)*S(Q)) 159 """ 160 return OrderedDict(( 161 ("P(Q)", P), 162 ("S(Q)", S), 163 )) 164 165 def _intermediates_beta(F1, F2, S, scale, bg): 166 # type: (np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray) -> OrderedDict[str, np.ndarray] 167 """ 168 Returns intermediate results for beta approximation-enabled product 169 """ 170 # TODO: 1. include calculated Q vector 171 # TODO: 2. consider implications if there are intermediate results in P(Q) 172 return OrderedDict(( 173 ("P(Q)", scale*F2), 174 ("S(Q)", S), 175 ("beta(Q)", F1**2 / F2), 176 ("S_eff(Q)", 1 + (F1**2 / F2)*(S-1)), 177 # ("I(Q)", scale*(F2 + (F1**2)*(S-1)) + bg), 178 )) 179 147 180 class ProductModel(KernelModel): 148 181 def __init__(self, model_info, P, S): … … 270 303 F1, F2, volume_avg = self.p_kernel.beta(p_details, p_values, cutoff, magnetic) 271 304 combined_scale = scale*volfrac/volume_avg 272 # Define lazy results based on intermediate values. 273 # The return value for the calculation should be an ordered 274 # dictionary containing any result the user might want to see 275 # at the end of the calculation, including scalars, strings, 276 # and plottable data. Don't want to build this structure during 277 # fits, only when displaying the final result (or a one-off 278 # computation which asks for it). 279 # Do not use the current hack of storing the intermediate values 280 # in self.results since that leads to awkward threading issues. 281 # Instead return the function along with the bundle of inputs. 282 # P and Q may themselves have intermediate results they want to 283 # include, such as A and B if P = A + B. Might use this mechanism 284 # to return the computed effective radius as well. 285 #def lazy_results(Q, S, F1, F2, scale): 286 # """ 287 # beta = F1**2 / F2 # what about divide by zero errors? 288 # return { 289 # 'P' : Data1D(Q, scale*F2), 290 # 'beta': Data1D(Q, beta), 291 # 'S' : Data1D(Q, S), 292 # 'Seff': Data1D(Q, 1 + beta*(S-1)), 293 # 'I' : Data1D(Q, scale*(F2 + (F1**2)*(S-1)) + background), 294 # } 295 #lazy_pars = s_result, F1, F2, combined_scale 296 self.results = [F2*volfrac/volume_avg, s_result] 305 306 self.results = lambda: _intermediates_beta(F1, F2, s_result, volfrac/volume_avg, background) 297 307 final_result = combined_scale*(F2 + (F1**2)*(s_result - 1)) + background 308 298 309 else: 299 310 p_result = self.p_kernel.Iq(p_details, p_values, cutoff, magnetic) 300 # remember the parts for plotting later 301 self.results = [p_result, s_result]311 312 self.results = lambda: _intermediates(p_result, s_result) 302 313 final_result = scale*(p_result*s_result) + background 303 314 -
sasmodels/sasview_model.py
rd533590 r117c02a 381 381 continue 382 382 self.params[p.name] = p.default 383 self.details[p.id] = [p.units, p.limits[0], p.limits[1]] 383 if p.limits is not None: 384 self.details[p.id] = [p.units if not p.choices else p.choices, p.limits[0], p.limits[1]] 385 else: 386 self.details[p.id] = [p.units if not p.choices else p.choices, None, None] 384 387 if p.polydisperse: 385 388 self.details[p.id+".width"] = [ … … 616 619 # so that it returns a results object containing all the bits: 617 620 # the A, B, C, ... of the composition model (and any subcomponents?) 618 # the P and S of the product model ,621 # the P and S of the product model 619 622 # the combined model before resolution smearing, 620 623 # the sasmodel before sesans conversion, … … 638 641 with calculation_lock: 639 642 self._calculate_Iq(qx) 640 return self._intermediate_results 643 # for compatibility with sasview 4.3 644 results = self._intermediate_results() 645 return results["P(Q)"], results["S(Q)"] 641 646 else: 642 647 return None
Note: See TracChangeset
for help on using the changeset viewer.