Changeset d32de68 in sasmodels
- Timestamp:
- Aug 21, 2018 4:43:34 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:
- c11d09f
- Parents:
- d3ffeb7
- Location:
- sasmodels
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/product.py
rd3ffeb7 rd32de68 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 … … 145 147 return par 146 148 149 def _intermediates(P, S): 150 # type: (np.ndarray, np.ndarray) -> OrderedDict[str, np.ndarray] 151 """ 152 Returns intermediate results for standard product (P(Q)*S(Q)) 153 """ 154 return OrderedDict(( 155 ("P(Q)", P), 156 ("S(Q)", S), 157 )) 158 159 def _intermediates_beta(F1, F2, S, scale, bg): 160 # type: (np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray) -> OrderedDict[str, np.ndarray] 161 """ 162 Returns intermediate results for beta approximation-enabled product 163 """ 164 # TODO: 1. include calculated Q vector 165 # TODO: 2. consider implications if there are intermediate results in P(Q) 166 return OrderedDict(( 167 ("P(Q)", scale*F2), 168 ("S(Q)", S), 169 ("beta(Q)", F1**2 / F2), 170 ("S_eff(Q)", 1 + (F1**2 / F2)*(S-1)), 171 # ("I(Q)", scale*(F2 + (F1**2)*(S-1)) + bg), 172 )) 173 147 174 class ProductModel(KernelModel): 148 175 def __init__(self, model_info, P, S): … … 270 297 F1, F2, volume_avg = self.p_kernel.beta(p_details, p_values, cutoff, magnetic) 271 298 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 297 # self.results = [F2*volfrac/volume_avg, s_result] 299 300 self.results = lambda: _intermediates_beta(F1, F2, s_result, volfrac/volume_avg, background) 298 301 final_result = combined_scale*(F2 + (F1**2)*(s_result - 1)) + background 299 300 # TODO: 1. include calculated Q vector301 # TODO: 2. consider implications if there are intermediate results in P(Q)302 # def lazy(F1, F2, S, scale, bg):303 def lazy(F1, F2, S, scale):304 return {305 "P(Q)": lambda: scale*F2,306 "S(Q)": lambda: S,307 "beta(Q)": lambda: F1**2 / F2,308 "S_eff(Q)": lambda: 1 + (F1**2 / F2)*(S-1),309 # "I(Q)": lambda: scale*(F2 + (F1**2)*(S-1)) + bg,310 }311 312 self.results = lazy(F1, F2, s_result, volfrac/volume_avg)313 302 314 303 else: 315 304 p_result = self.p_kernel.Iq(p_details, p_values, cutoff, magnetic) 316 # remember the parts for plotting later 317 # self.results = [p_result, s_result]305 306 self.results = lambda: _intermediates(p_result, s_result) 318 307 final_result = scale*(p_result*s_result) + background 319 320 def lazy(P, S):321 return {322 "P(Q)": lambda: P,323 "S(Q)": lambda: S,324 }325 326 self.results = lazy(p_result, s_result)327 308 328 309 #call_details.show(values) -
sasmodels/sasview_model.py
rd3ffeb7 rd32de68 616 616 # so that it returns a results object containing all the bits: 617 617 # the A, B, C, ... of the composition model (and any subcomponents?) 618 # the P and S of the product model ,618 # the P and S of the product model 619 619 # the combined model before resolution smearing, 620 620 # the sasmodel before sesans conversion, … … 638 638 with calculation_lock: 639 639 self._calculate_Iq(qx) 640 return self._intermediate_results 640 # for compatibility with sasview 4.3 641 results = self._intermediate_results() 642 return results["P(Q)"], results["S(Q)"] 641 643 else: 642 644 return None
Note: See TracChangeset
for help on using the changeset viewer.