Changeset 7b0abf8 in sasmodels


Ignore:
Timestamp:
Aug 7, 2018 9:07:11 PM (2 weeks ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
beta_approx, beta_approx_lazy_results, beta_approx_new_R_eff
Children:
c036ddb
Parents:
502c7b8
Message:

linting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • explore/beta/sasfit_compare.py

    r502c7b8 r7b0abf8  
    33import sys, os 
    44BETA_DIR = os.path.dirname(os.path.realpath(__file__)) 
    5 #SASMODELS_DIR = os.path.dirname(os.path.dirname(BETA_DIR)) 
    6 SASMODELS_DIR = r"C:\Source\sasmodels" 
     5SASMODELS_DIR = os.path.dirname(os.path.dirname(BETA_DIR)) 
    76sys.path.insert(0, SASMODELS_DIR) 
    87 
     
    4140        y = x[index]**2 
    4241        c1 = -1.0/10.0 
    43         c2 =  1.0/280.0 
     42        c2 = +1.0/280.0 
    4443        c3 = -1.0/15120.0 
    45         c4 =  1.0/1330560.0 
     44        c4 = +1.0/1330560.0 
    4645        c5 = -1.0/172972800.0 
    4746        retvalue[index] = 1.0 + y*(c1 + y*(c2 + y*(c3 + y*(c4 + y*c5)))) 
     
    6766#gives the hardsphere structure factor that sasview uses 
    6867def _hardsphere_simple(q, radius_effective, volfraction): 
    69     CUTOFFHS=0.05 
     68    CUTOFFHS = 0.05 
    7069    if fabs(radius_effective) < 1.E-12: 
    71         HARDSPH=1.0 
     70        HARDSPH = 1.0 
    7271        return HARDSPH 
    73     X = 1.0/( 1.0 -volfraction) 
    74     D= X*X 
    75     A= (1.+2.*volfraction)*D 
    76     A *=A 
    77     X=fabs(q*radius_effective*2.0) 
     72    X = 1.0/(1.0 -volfraction) 
     73    D = X*X 
     74    A = (1.+2.*volfraction)*D 
     75    A *= A 
     76    X = fabs(q*radius_effective*2.0) 
    7877    if X < 5.E-06: 
    79         HARDSPH=1./A 
     78        HARDSPH = 1./A 
    8079        return HARDSPH 
    81     X2 =X*X 
     80    X2 = X*X 
    8281    B = (1.0 +0.5*volfraction)*D 
    8382    B *= B 
    8483    B *= -6.*volfraction 
    85     G=0.5*volfraction*A 
     84    G = 0.5*volfraction*A 
    8685    if X < CUTOFFHS: 
    8786        FF = 8.0*A +6.0*B + 4.0*G + ( -0.8*A -B/1.5 -0.5*G +(A/35. +0.0125*B +0.02*G)*X2)*X2 
    88         HARDSPH= 1./(1. + volfraction*FF ) 
     87        HARDSPH = 1./(1. + volfraction*FF ) 
    8988        return HARDSPH 
    90     X4=X2*X2 
     89    X4 = X2*X2 
    9190    S, C = sin(X), cos(X) 
    92     FF=  (( G*( (4.*X2 -24.)*X*S -(X4 -12.*X2 +24.)*C +24. )/X2 + B*(2.*X*S -(X2-2.)*C -2.) )/X + A*(S-X*C))/X 
    93     HARDSPH= 1./(1. + 24.*volfraction*FF/X2 ) 
     91    FF =  ((G*( (4.*X2 -24.)*X*S -(X4 -12.*X2 +24.)*C +24. )/X2 + B*(2.*X*S -(X2-2.)*C -2.) )/X + A*(S-X*C))/X 
     92    HARDSPH = 1./(1. + 24.*volfraction*FF/X2) 
    9493    return HARDSPH 
    9594 
     
    107106        nsigmas = NSIGMA_GAUSS 
    108107        x = np.linspace(center-sigma*nsigmas, center+sigma*nsigmas, num=N_GAUSS) 
    109         x= x[(x >= lb) & (x <= ub)] 
     108        x = x[(x >= lb) & (x <= ub)] 
    110109        px = np.exp((x-center)**2 / (-2.0 * sigma * sigma)) 
    111110        return x, px 
     
    119118        nsigmas = NSIGMA_SCHULZ 
    120119        x = np.linspace(center-sigma*nsigmas, center+sigma*nsigmas, num=N_SCHULZ) 
    121         x= x[(x >= lb) & (x <= ub)] 
     120        x = x[(x >= lb) & (x <= ub)] 
    122121        R = x/center 
    123122        z = (center/sigma)**2 
     
    137136    else: 
    138137        ee = 2*radius_polar 
    139     if (radius_polar * radius_equatorial != 0): 
     138    if radius_polar * radius_equatorial != 0: 
    140139        bd = 1.0 - ee 
    141140        e1 = np.sqrt(ee) 
     
    148147    return 0.5*ddd**(1.0 / 3.0) 
    149148 
    150 def ellipsoid_volume(radius_polar,radius_equatorial): 
     149def ellipsoid_volume(radius_polar, radius_equatorial): 
    151150    volume = (4./3.)*pi*radius_polar*radius_equatorial**2 
    152151    return volume 
     
    210209    for k, Rpk in enumerate(Rp_val): 
    211210        for i, Rei in enumerate(Re_val): 
    212             theory = ellipsoid_theta(q,Rpk,Rei,sld,sld_solvent) 
     211            theory = ellipsoid_theta(q, Rpk, Rei, sld, sld_solvent) 
    213212            volume = ellipsoid_volume(Rpk, Rei) 
    214213            weight = Rp_prob[k]*Re_prob[i] 
     
    217216            F1 += theory.F1*weight 
    218217            F2 += theory.F2*weight 
    219             radius_eff += weight*ER_ellipsoid(Rpk,Rei) 
     218            radius_eff += weight*ER_ellipsoid(Rpk, Rei) 
    220219    F1 /= total_weight 
    221220    F2 /= total_weight 
     
    344343    #Sq = Iq/Pq 
    345344    #Iq = None#= Sq = None 
    346     r=I._kernel.results 
     345    r = I._kernel.results 
    347346    return Theory(Q=q, F1=None, F2=None, P=Pq, S=None, I=None, Seff=r[1], Ibeta=Iq) 
    348347 
     
    383382    model = 'sphere' 
    384383    pars = dict( 
    385         radius=20,sld=4,sld_solvent=1, 
     384        radius=20, sld=4, sld_solvent=1, 
    386385        background=0, 
    387386        radius_pd=.1, radius_pd_type=pd_type, 
     
    393392    title = " ".join(("sasmodels", model, pd_type)) 
    394393    compare(title, target, actual) 
    395 COMPARISON[('sasview','sphere','gaussian')] = lambda: compare_sasview_sphere(pd_type='gaussian') 
    396 COMPARISON[('sasview','sphere','schulz')] = lambda: compare_sasview_sphere(pd_type='schulz') 
     394COMPARISON[('sasview', 'sphere', 'gaussian')] = lambda: compare_sasview_sphere(pd_type='gaussian') 
     395COMPARISON[('sasview', 'sphere', 'schulz')] = lambda: compare_sasview_sphere(pd_type='schulz') 
    397396 
    398397def compare_sasview_ellipsoid(pd_type='gaussian'): 
     
    400399    model = 'ellipsoid' 
    401400    pars = dict( 
    402         radius_polar=20,radius_equatorial=400,sld=4,sld_solvent=1, 
     401        radius_polar=20, radius_equatorial=400, sld=4, sld_solvent=1, 
    403402        background=0, 
    404403        radius_polar_pd=.1, radius_polar_pd_type=pd_type, 
     
    412411    title = " ".join(("sasmodels", model, pd_type)) 
    413412    compare(title, target, actual) 
    414 COMPARISON[('sasview','ellipsoid','gaussian')] = lambda: compare_sasview_ellipsoid(pd_type='gaussian') 
    415 COMPARISON[('sasview','ellipsoid','schulz')] = lambda: compare_sasview_ellipsoid(pd_type='schulz') 
     413COMPARISON[('sasview', 'ellipsoid', 'gaussian')] = lambda: compare_sasview_ellipsoid(pd_type='gaussian') 
     414COMPARISON[('sasview', 'ellipsoid', 'schulz')] = lambda: compare_sasview_ellipsoid(pd_type='schulz') 
    416415 
    417416def compare_yun_ellipsoid_mono(): 
     
    437436    #compare(title, target, actual, fields="P S I Seff Ibeta") 
    438437    compare(title, target, actual) 
    439 COMPARISON[('yun','ellipsoid','gaussian')] = compare_yun_ellipsoid_mono 
    440 COMPARISON[('yun','ellipsoid','schulz')] = compare_yun_ellipsoid_mono 
     438COMPARISON[('yun', 'ellipsoid', 'gaussian')] = compare_yun_ellipsoid_mono 
     439COMPARISON[('yun', 'ellipsoid', 'schulz')] = compare_yun_ellipsoid_mono 
    441440 
    442441def compare_yun_sphere_gauss(): 
     
    449448    } 
    450449 
    451     data = np.loadtxt(data_file('testPolydisperseGaussianSphere.dat'),skiprows=2).T 
     450    data = np.loadtxt(data_file('testPolydisperseGaussianSphere.dat'), skiprows=2).T 
    452451    Q = data[0] 
    453452    F1 = data[1] 
     
    460459    title = " ".join(("yun", "sphere", "10% dispersion 10% Vf")) 
    461460    compare(title, target, actual) 
    462     data = np.loadtxt(data_file('testPolydisperseGaussianSphere2.dat'),skiprows=2).T 
     461    data = np.loadtxt(data_file('testPolydisperseGaussianSphere2.dat'), skiprows=2).T 
    463462    pars.update(radius_pd=0.15) 
    464463    Q = data[0] 
     
    472471    title = " ".join(("yun", "sphere", "15% dispersion 10% Vf")) 
    473472    compare(title, target, actual) 
    474 COMPARISON[('yun','sphere','gaussian')] = compare_yun_sphere_gauss 
     473COMPARISON[('yun', 'sphere', 'gaussian')] = compare_yun_sphere_gauss 
    475474 
    476475 
     
    493492    compare(title, target, actual) 
    494493    #compare(title, target, actual, fields="P") 
    495 COMPARISON[('sasfit','sphere','gaussian')] = compare_sasfit_sphere_gauss 
     494COMPARISON[('sasfit', 'sphere', 'gaussian')] = compare_sasfit_sphere_gauss 
    496495 
    497496def compare_sasfit_sphere_schulz(): 
     
    512511    title = " ".join(("sasfit", "sphere", "pd=10% schulz")) 
    513512    compare(title, target, actual) 
    514 COMPARISON[('sasfit','sphere','schulz')] = compare_sasfit_sphere_schulz 
     513COMPARISON[('sasfit', 'sphere', 'schulz')] = compare_sasfit_sphere_schulz 
    515514 
    516515def compare_sasfit_ellipsoid_schulz(): 
     
    533532    title = " ".join(("sasfit", "ellipsoid", "pd=10% schulz")) 
    534533    compare(title, target, actual) 
    535 COMPARISON[('sasfit','ellipsoid','schulz')] = compare_sasfit_ellipsoid_schulz 
     534COMPARISON[('sasfit', 'ellipsoid', 'schulz')] = compare_sasfit_ellipsoid_schulz 
    536535 
    537536 
     
    653652    target = Theory(Q=Q, S=SQ, Seff=SQ_EFF) 
    654653    compare("sasfit ellipsoid P(Q) 60% Rp 60% Vf", target, actual); plt.show() 
    655 COMPARISON[('sasfit','ellipsoid','gaussian')] = compare_sasfit_ellipsoid_gaussian 
     654COMPARISON[('sasfit', 'ellipsoid', 'gaussian')] = compare_sasfit_ellipsoid_gaussian 
    656655 
    657656def main(): 
Note: See TracChangeset for help on using the changeset viewer.