Changeset aa44a6a in sasmodels for sasmodels/product.py
- Timestamp:
- Aug 21, 2018 9:38:57 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:
- 3d6526d
- Parents:
- 6e7ba14 (diff), d32de68 (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/product.py
r6e7ba14 raa44a6a 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, Union 25 27 except ImportError: 26 28 pass … … 40 42 pars = [] 41 43 if p_info.have_Fq: 42 par = Parameter("structure_factor_mode", "", 0, [["P*S","P*(1+beta*(S-1))"]], "",44 par = Parameter("structure_factor_mode", ["P*S","P*(1+beta*(S-1))"], 0, None, "", 43 45 "Structure factor calculation") 44 46 pars.append(par) 45 47 if p_info.effective_radius_type is not None: 46 par = Parameter("radius_effective_mode", "", 0, 47 [["unconstrained"] + p_info.effective_radius_type], 48 "", "Effective radius calculation") 48 par = Parameter("radius_effective_mode", ["unconstrained"] + p_info.effective_radius_type, 0, None, "", 49 "Effective radius calculation") 49 50 pars.append(par) 50 51 return pars … … 157 158 return par 158 159 160 def _intermediates(P, S, effective_radius): 161 # type: (np.ndarray, np.ndarray, float) -> OrderedDict[str, np.ndarray] 162 """ 163 Returns intermediate results for standard product (P(Q)*S(Q)) 164 """ 165 return OrderedDict(( 166 ("P(Q)", P), 167 ("S(Q)", S), 168 ("effective_radius", effective_radius), 169 )) 170 171 def _intermediates_beta(F1, F2, S, scale, bg, effective_radius): 172 # type: (np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray, float) -> OrderedDict[str, Union[np.ndarray, float]] 173 """ 174 Returns intermediate results for beta approximation-enabled product. The result may be an array or a float. 175 """ 176 # TODO: 1. include calculated Q vector 177 # TODO: 2. consider implications if there are intermediate results in P(Q) 178 return OrderedDict(( 179 ("P(Q)", scale*F2), 180 ("S(Q)", S), 181 ("beta(Q)", F1**2 / F2), 182 ("S_eff(Q)", 1 + (F1**2 / F2)*(S-1)), 183 ("effective_radius", effective_radius), 184 # ("I(Q)", scale*(F2 + (F1**2)*(S-1)) + bg), 185 )) 186 159 187 class ProductModel(KernelModel): 160 188 def __init__(self, model_info, P, S): … … 276 304 s_result = self.s_kernel.Iq(s_details, s_values, cutoff, False) 277 305 combined_scale = scale*volfrac/volume_avg 278 # Define lazy results based on intermediate values. 279 # The return value for the calculation should be an ordered 280 # dictionary containing any result the user might want to see 281 # at the end of the calculation, including scalars, strings, 282 # and plottable data. Don't want to build this structure during 283 # fits, only when displaying the final result (or a one-off 284 # computation which asks for it). 285 # Do not use the current hack of storing the intermediate values 286 # in self.results since that leads to awkward threading issues. 287 # Instead return the function along with the bundle of inputs. 288 # P and Q may themselves have intermediate results they want to 289 # include, such as A and B if P = A + B. Might use this mechanism 290 # to return the computed effective radius as well. 291 #def lazy_results(Q, S, F1, F2, scale): 292 # """ 293 # beta = F1**2 / F2 # what about divide by zero errors? 294 # return { 295 # 'P' : Data1D(Q, scale*F2), 296 # 'beta': Data1D(Q, beta), 297 # 'S' : Data1D(Q, S), 298 # 'Seff': Data1D(Q, 1 + beta*(S-1)), 299 # 'I' : Data1D(Q, scale*(F2 + (F1**2)*(S-1)) + background), 300 # } 301 #lazy_pars = s_result, F1, F2, combined_scale 302 self.results = [F2*volfrac/volume_avg, s_result] 306 307 self.results = lambda: _intermediates_beta(F1, F2, s_result, volfrac/volume_avg, background, effective_radius) 303 308 final_result = combined_scale*(F2 + (F1**2)*(s_result - 1)) + background 309 304 310 else: 305 311 p_result, effective_radius = self.p_kernel.Pq_Reff( … … 309 315 s_result = self.s_kernel.Iq(s_details, s_values, cutoff, False) 310 316 # remember the parts for plotting later 311 self.results = [p_result, s_result]317 self.results = lambda: _intermediates(p_result, s_result, effective_radius) 312 318 final_result = scale*(p_result*s_result) + background 313 319
Note: See TracChangeset
for help on using the changeset viewer.