Changeset 7e923c2 in sasmodels for sasmodels/product.py
- Timestamp:
- Aug 7, 2018 8:45:52 PM (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:
- 1a7ddc9
- Parents:
- c036ddb (diff), e9b17b18 (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
r2d81cfe rc036ddb 16 16 import numpy as np # type: ignore 17 17 18 from .modelinfo import ParameterTable, ModelInfo 18 from .modelinfo import ParameterTable, ModelInfo, Parameter 19 19 from .kernel import KernelModel, Kernel 20 20 from .details import make_details, dispersion_mesh … … 37 37 ER_ID = "radius_effective" 38 38 VF_ID = "volfraction" 39 BETA_DEFINITION = ("beta_mode", "", 0, [["P*S"],["P*(1+beta*(S-1))"]], "", 40 "Structure factor dispersion calculation mode") 39 41 40 42 # TODO: core_shell_sphere model has suppressed the volume ratio calculation … … 74 76 translate_name = dict((old.id, new.id) for old, new 75 77 in zip(s_pars.kernel_parameters[1:], s_list)) 76 combined_pars = p_pars.kernel_parameters + s_list 78 beta = [Parameter(*BETA_DEFINITION)] if p_info.have_Fq else [] 79 combined_pars = p_pars.kernel_parameters + s_list + beta 77 80 parameters = ParameterTable(combined_pars) 78 81 parameters.max_pd = p_pars.max_pd + s_pars.max_pd … … 151 154 #: Structure factor modelling interaction between particles. 152 155 self.S = S 156 153 157 #: Model precision. This is not really relevant, since it is the 154 158 #: individual P and S models that control the effective dtype, … … 168 172 # in opencl; or both in opencl, but one in single precision and the 169 173 # other in double precision). 174 170 175 p_kernel = self.P.make_kernel(q_vectors) 171 176 s_kernel = self.S.make_kernel(q_vectors) … … 211 216 p_offset = call_details.offset[:p_npars] 212 217 p_details = make_details(p_info, p_length, p_offset, nweights) 218 213 219 # Set p scale to the volume fraction in s, which is the first of the 214 220 # 'S' parameters in the parameter list, or 2+np in 0-origin. … … 254 260 s_values = np.hstack(s_values).astype(self.s_kernel.dtype) 255 261 262 # beta mode is the first parameter after the structure factor pars 263 beta_index = 2+p_npars+s_npars 264 beta_mode = values[beta_index] 265 256 266 # Call the kernels 257 p_result = self.p_kernel(p_details, p_values, cutoff, magnetic) 258 s_result = self.s_kernel(s_details, s_values, cutoff, False) 259 260 #print("p_npars",p_npars,s_npars,p_er,s_vr,values[2+p_npars+1:2+p_npars+s_npars]) 267 s_result = self.s_kernel.Iq(s_details, s_values, cutoff, False) 268 scale, background = values[0], values[1] 269 if beta_mode: 270 F1, F2, volume_avg = self.p_kernel.beta(p_details, p_values, cutoff, magnetic) 271 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, s_result] 297 final_result = combined_scale*(F2 + (F1**2)*(s_result - 1)) + background 298 else: 299 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] 302 final_result = scale*(p_result*s_result) + background 303 261 304 #call_details.show(values) 262 305 #print("values", values) … … 265 308 #s_details.show(s_values) 266 309 #print("=>", s_result) 267 268 # remember the parts for plotting later269 self.results = [p_result, s_result]270 271 310 #import pylab as plt 272 311 #plt.subplot(211); plt.loglog(self.p_kernel.q_input.q, p_result, '-') 273 312 #plt.subplot(212); plt.loglog(self.s_kernel.q_input.q, s_result, '-') 274 313 #plt.figure() 275 276 return values[0]*(p_result*s_result) + values[1] 314 return final_result 277 315 278 316 def release(self):
Note: See TracChangeset
for help on using the changeset viewer.