Changeset 0076d6e in sasmodels
- Timestamp:
- Jul 5, 2018 7:22:13 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:
- e262dd6
- Parents:
- 757a3ff
- Location:
- explore/beta
- Files:
-
- 3 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
explore/beta/sasfit_compare.py
r757a3ff r0076d6e 170 170 for k, qk in enumerate(q): 171 171 r = sqrt(radius_equatorial**2*(1-((z+1)/2)**2)+radius_polar**2*((z+1)/2)**2) 172 F2i = ((sld-sld_solvent)*volume*sas_3j1x_x(qk*r))**2 173 F2[k] = np.sum(w*F2i) 174 F1i = (sld-sld_solvent)*volume*sas_3j1x_x(qk*r) 175 F1[k] = np.sum(w*F1i) 172 form = (sld-sld_solvent)*volume*sas_3j1x_x(qk*r) 173 F2[k] = np.sum(w*form**2) 174 F1[k] = np.sum(w*form) 176 175 #the 1/2 comes from the change of variables mentioned above 177 176 F2 = F2/2.0 … … 205 204 elif radius_equatorial_pd_type == 'schulz': 206 205 Re_val, Re_prob = schulz_distribution(radius_equatorial, radius_equatorial_pd*radius_equatorial, 0, inf) 207 Normalization= 0208 F1,F2 = np.zeros_like(q), np.zeros_like(q)209 radius_eff = total_weight = 0206 total_weight = total_volume = 0 207 radius_eff = 0 208 F1, F2 = np.zeros_like(q), np.zeros_like(q) 210 209 for k, Rpk in enumerate(Rp_val): 211 210 for i, Rei in enumerate(Re_val): 212 211 theory = ellipsoid_theta(q,Rpk,Rei,sld,sld_solvent) 213 212 volume = ellipsoid_volume(Rpk, Rei) 214 if norm == 'sasfit': 215 Normalization += Rp_prob[k]*Re_prob[i] 216 elif norm == 'sasview' or norm == 'yun': 217 Normalization += Rp_prob[k]*Re_prob[i]*volume 218 F1 += theory.F1*Rp_prob[k]*Re_prob[i] 219 F2 += theory.F2*Rp_prob[k]*Re_prob[i] 220 radius_eff += Rp_prob[k]*Re_prob[i]*ER_ellipsoid(Rpk,Rei) 221 total_weight += Rp_prob[k]*Re_prob[i] 222 F1 = F1/Normalization 223 F2 = F2/Normalization 213 weight = Rp_prob[k]*Re_prob[i] 214 total_weight += weight 215 total_volume += weight*volume 216 F1 += theory.F1*weight 217 F2 += theory.F2*weight 218 radius_eff += weight*ER_ellipsoid(Rpk,Rei) 219 F1 /= total_weight 220 F2 /= total_weight 221 average_volume = total_volume/total_weight 224 222 if radius_effective is None: 225 223 radius_effective = radius_eff/total_weight 226 224 SQ = hardsphere_simple(q, radius_effective, volfraction) 227 SQ_EFF = 1 + F1**2/F2*(SQ - 1)228 volume = ellipsoid_volume(radius_polar, radius_equatorial)229 225 if norm == 'sasfit': 226 beta = F1**2/F2 227 SQ_EFF = 1 + beta*(SQ - 1) 230 228 IQD = F2 231 229 IQSD = IQD*SQ 232 230 IQBD = IQD*SQ_EFF 233 231 elif norm == 'sasview': 234 IQD = F2*1e-4*volfraction 232 SQ_EFF = None 233 # Note: internally, sasview uses F2/total_volume because: 234 # average_volume = total_volume/total_weight 235 # F2/total_weight / average_volume 236 # = F2/total_weight / total_volume/total_weight 237 # = F2/total_volume 238 IQD = F2/average_volume*1e-4*volfraction 235 239 IQSD = IQD*SQ 236 IQBD = IQD*SQ_EFF240 IQBD = None 237 241 elif norm == 'yun': 238 SQ_EFF = 1 + Normalization*F1**2/F2*(SQ - 1) 239 F2 = F2/volume 240 IQD = F2 242 #F1 /= average_volume 243 #F2 /= average_volume**2 244 F1 *= 1e-6 # Yun is using sld in 1/A^2, not 1e-6/A^2 245 F2 *= 1e-12 246 beta = F1**2/F2 247 SQ_EFF = 1 + beta*(SQ - 1) 248 IQD = F2/average_volume*1e8*volfraction 241 249 IQSD = IQD*SQ 242 250 IQBD = IQD*SQ_EFF … … 255 263 elif radius_pd_type == 'schulz': 256 264 radius_val, radius_prob = schulz_distribution(radius, radius_pd*radius, 0, inf) 257 Normalization=0265 total_weight = total_volume = 0 258 266 F1 = np.zeros_like(q) 259 267 F2 = np.zeros_like(q) 260 268 for k, rk in enumerate(radius_val): 261 269 volume = 4./3.*pi*rk**3 262 if norm == 'sasfit': 263 Normalization += radius_prob[k] 264 elif norm == 'sasview' or norm == 'yun': 265 Normalization += radius_prob[k]*volume 266 F2k = ((sld-sld_solvent)*volume*sas_3j1x_x(q*rk))**2 267 F1k = (sld-sld_solvent)*volume*sas_3j1x_x(q*rk) 268 F2 += radius_prob[k]*F2k 269 F1 += radius_prob[k]*F1k 270 271 F2 = F2/Normalization 272 F1 = F1/Normalization 270 total_weight += radius_prob[k] 271 total_volume += radius_prob[k]*volume 272 form = (sld-sld_solvent)*volume*sas_3j1x_x(q*rk) 273 F2 += radius_prob[k]*form**2 274 F1 += radius_prob[k]*form 275 F1 /= total_weight 276 F2 /= total_weight 277 average_volume = total_volume/total_weight 278 273 279 if radius_effective is None: 274 280 radius_effective = radius 275 281 SQ = hardsphere_simple(q, radius_effective, volfraction) 276 SQ_EFF = 1 + F1**2/F2*(SQ - 1)277 282 volume = 4./3.*pi*radius**3 283 average_volume = total_volume/total_weight 278 284 if norm == 'sasfit': 285 beta = F1**2/F2 286 SQ_EFF = 1 + beta*(SQ - 1) 279 287 IQD = F2 280 288 IQSD = IQD*SQ 281 289 IQBD = IQD*SQ_EFF 282 290 elif norm == 'sasview': 283 IQD = F2*1e-4*volfraction 291 SQ_EFF = None 292 IQD = F2/average_volume*1e-4*volfraction 284 293 IQSD = IQD*SQ 285 IQBD = IQD*SQ_EFF294 IQBD = None 286 295 elif norm == 'yun': 287 SQ_EFF = 1 + Normalization*F1**2/F2*(SQ - 1) 288 F2 = F2/volume 289 IQD = F2 296 # Note: yun uses gauss limits from R0/10 to R0 + 5 sigma steps sigma/100 297 # With pd = 0.1, that's 14 sigma, or 1400 points. 298 F1 *= 1e-6 # Yun is using sld in 1/A^2, not 1e-6/A^2 299 F2 *= 1e-12 300 beta = F1**2/F2 301 SQ_EFF = 1 + beta*(SQ - 1) 302 IQD = F2/average_volume*1e8*volfraction 290 303 IQSD = IQD*SQ 291 304 IQBD = IQD*SQ_EFF … … 364 377 plt.legend(loc='lower left') 365 378 plt.subplot(rows, 2, 2*row+2) 366 #plt.semilogx(Q, I2/I1 - 1, label="relative error")367 plt.semilogx(Q, I1/I2 - 1, label="relative error")379 plt.semilogx(Q, I2/I1 - 1, label="relative error") 380 #plt.semilogx(Q, I1/I2 - 1, label="relative error") 368 381 plt.tight_layout() 369 382 plt.suptitle(title) … … 412 425 title = " ".join(("sasmodels", model, pd_type)) 413 426 compare(title, target, actual) 414 COMPARISON[('sasview','ellipsoid','gaussian')] = lambda: compare_sasview_ sphere(pd_type='gaussian')415 COMPARISON[('sasview','ellipsoid','schulz')] = lambda: compare_sasview_ sphere(pd_type='schulz')427 COMPARISON[('sasview','ellipsoid','gaussian')] = lambda: compare_sasview_ellipsoid(pd_type='gaussian') 428 COMPARISON[('sasview','ellipsoid','schulz')] = lambda: compare_sasview_ellipsoid(pd_type='schulz') 416 429 417 430 def compare_yun_ellipsoid_mono(): … … 425 438 'radius_effective': 12.59921049894873, 426 439 } 427 volume = ellipsoid_volume(pars['radius_polar'], pars['radius_equatorial'])428 440 429 441 data = np.loadtxt(data_file('yun_ellipsoid.dat'),skiprows=2).T 430 442 Q = data[0] 431 443 F1 = data[1] 432 F2 = data[3]444 P = data[3]*pars['volfraction'] 433 445 S = data[5] 434 446 Seff = data[6] 435 P = F2 436 I = P*S 437 Ibeta = P*Seff 438 P = I = Ibeta = None 439 target = Theory(Q=Q, F1=F1, F2=F2, P=P, S=S, I=I, Seff=Seff, Ibeta=Ibeta) 447 target = Theory(Q=Q, F1=F1, P=P, S=S, Seff=Seff) 440 448 actual = ellipsoid_pe(Q, norm='yun', **pars) 441 449 title = " ".join(("yun", "ellipsoid", "no pd")) … … 444 452 COMPARISON[('yun','ellipsoid','gaussian')] = compare_yun_ellipsoid_mono 445 453 COMPARISON[('yun','ellipsoid','schulz')] = compare_yun_ellipsoid_mono 454 455 def compare_yun_sphere_gauss(): 456 pars = { 457 'radius': 20, 'radius_pd': 0.1, 'radius_pd_type': 'gaussian', 458 'sld': 6, 'sld_solvent': 0, 459 'volfraction': 0.1, 460 } 461 462 data = np.loadtxt(data_file('testPolydisperseGaussianSphere.dat'),skiprows=2).T 463 Q = data[0] 464 F1 = data[1] 465 P = data[3] 466 S = data[5] 467 Seff = data[6] 468 target = Theory(Q=Q, F1=F1, P=P, S=S, Seff=Seff) 469 actual = sphere_r(Q, norm='yun', **pars) 470 title = " ".join(("yun", "sphere", "10% dispersion 10% Vf")) 471 compare(title, target, actual) 472 data = np.loadtxt(data_file('testPolydisperseGaussianSphere2.dat'),skiprows=2).T 473 pars.update(radius_pd=0.15) 474 Q = data[0] 475 F1 = data[1] 476 P = data[3] 477 S = data[5] 478 Seff = data[6] 479 target = Theory(Q=Q, F1=F1, P=P, S=S, Seff=Seff) 480 actual = sphere_r(Q, norm='yun', **pars) 481 title = " ".join(("yun", "sphere", "15% dispersion 10% Vf")) 482 compare(title, target, actual) 483 COMPARISON[('yun','sphere','gaussian')] = compare_yun_sphere_gauss 484 446 485 447 486 def compare_sasfit_sphere_gauss(): … … 452 491 'volfraction': 0.3, 453 492 } 454 volume = 4./3.*pi*pars['radius']**3 493 455 494 Q, IQ = load_sasfit(data_file('sasfit_sphere_IQD.txt')) 456 495 Q, IQSD = load_sasfit(data_file('sasfit_sphere_IQSD.txt')) … … 474 513 'volfraction': 0.3, 475 514 } 476 volume = 4./3.*pi*pars['radius']**3477 515 478 516 Q, IQ = load_sasfit(data_file('richard_test.txt')) … … 496 534 'volfraction': 0.3, 'radius_effective': 13.1353356684, 497 535 } 498 volume = ellipsoid_volume(pars['radius_polar'], pars['radius_equatorial']) 536 499 537 Q, IQ = load_sasfit(data_file('richard_test4.txt')) 500 538 Q, IQSD = load_sasfit(data_file('richard_test5.txt'))
Note: See TracChangeset
for help on using the changeset viewer.