Changeset d547f16 in sasmodels


Ignore:
Timestamp:
Feb 16, 2015 7:06:30 PM (9 years ago)
Author:
pkienzle
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
a503bfd
Parents:
10576d1
Message:

move demo parameters for compare.py into individual models

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • compare.py

    rf786ff3 rd547f16  
    44import sys 
    55import math 
     6from os.path import basename, dirname, join as joinpath 
     7import glob 
    68 
    79import numpy as np 
     
    1012from sasmodels import kernelcl, kerneldll 
    1113from sasmodels.convert import revert_model 
     14 
     15# List of available models 
     16ROOT = dirname(__file__) 
     17MODELS = [basename(f)[:-3] 
     18          for f in sorted(glob.glob(joinpath(ROOT,"sasmodels","models","[a-zA-Z]*.py")))] 
    1219 
    1320 
     
    295302    opts = [arg for arg in sys.argv[1:] if arg.startswith('-')] 
    296303    args = [arg for arg in sys.argv[1:] if not arg.startswith('-')] 
    297     models = "\n    ".join("%-7s: %s"%(k,v.__name__.replace('_',' ')) 
    298                            for k,v in sorted(MODELS.items())) 
     304    models = "\n    ".join("%-15s"%v for v in MODELS) 
    299305    if len(args) == 0: 
    300306        print(USAGE%models) 
     
    311317        sys.exit(1) 
    312318 
    313     name, pars = MODELS[args[0]]() 
     319    # Get demo parameters from model definition, or use default parameters 
     320    # if model does not define demo parameters 
     321    name = args[0] 
     322    import sasmodels.models 
     323    __import__('sasmodels.models.'+name) 
     324    model = getattr(sasmodels.models, name) 
     325    pars = getattr(model, 'demo', None) 
     326    if pars is None: pars = dict((p[0],p[2]) for p in model.parameters) 
     327 
    314328    Nopencl = int(args[1]) if len(args) > 1 else 5 
    315329    Nsasview = int(args[2]) if len(args) > 2 else 1 
     
    334348    compare(name, pars, Nsasview, Nopencl, opts, set_pars) 
    335349 
    336 # =========================================================================== 
    337 # 
    338  
    339 MODELS = {} 
    340 def model(name): 
    341     def gather_function(fn): 
    342         MODELS[name] = fn 
    343         return fn 
    344     return gather_function 
    345  
    346  
    347 @model('cyl') 
    348 def cylinder(): 
    349     pars = dict( 
    350         scale=1, background=0, 
    351         sld=6, solvent_sld=1, 
    352         #radius=5, length=20, 
    353         radius=260, length=290, 
    354         theta=30, phi=0, 
    355         radius_pd=.2, radius_pd_n=9, 
    356         length_pd=.2,length_pd_n=10, 
    357         theta_pd=15, theta_pd_n=45, 
    358         phi_pd=15, phi_pd_n=1, 
    359         ) 
    360     return 'cylinder', pars 
    361  
    362 @model('capcyl') 
    363 def capped_cylinder(): 
    364     pars = dict( 
    365         scale=1, background=0, 
    366         sld=6, solvent_sld=1, 
    367         radius=260, cap_radius=290, length=290, 
    368         theta=30, phi=15, 
    369         radius_pd=.2, radius_pd_n=1, 
    370         cap_radius_pd=.2, cap_radius_pd_n=1, 
    371         length_pd=.2, length_pd_n=10, 
    372         theta_pd=15, theta_pd_n=45, 
    373         phi_pd=15, phi_pd_n=1, 
    374         ) 
    375     return 'capped_cylinder', pars 
    376  
    377  
    378 @model('cscyl') 
    379 def core_shell_cylinder(): 
    380     pars = dict( 
    381         scale=1, background=0, 
    382         core_sld=6, shell_sld=8, solvent_sld=1, 
    383         radius=45, thickness=25, length=340, 
    384         theta=30, phi=15, 
    385         radius_pd=.2, radius_pd_n=1, 
    386         length_pd=.2, length_pd_n=10, 
    387         thickness_pd=.2, thickness_pd_n=10, 
    388         theta_pd=15, theta_pd_n=45, 
    389         phi_pd=15, phi_pd_n=1, 
    390         ) 
    391     return 'core_shell_cylinder', pars 
    392  
    393  
    394 @model('ell') 
    395 def ellipsoid(): 
    396     pars = dict( 
    397         scale=1, background=0, 
    398         sld=6, solvent_sld=1, 
    399         rpolar=50, requatorial=30, 
    400         theta=30, phi=15, 
    401         rpolar_pd=.2, rpolar_pd_n=15, 
    402         requatorial_pd=.2, requatorial_pd_n=15, 
    403         theta_pd=15, theta_pd_n=45, 
    404         phi_pd=15, phi_pd_n=1, 
    405         ) 
    406     return 'ellipsoid', pars 
    407  
    408  
    409 @model('ell3') 
    410 def triaxial_ellipsoid(): 
    411     pars = dict( 
    412         scale=1, background=0, 
    413         sld=6, solvent_sld=1, 
    414         theta=30, phi=15, psi=5, 
    415         req_minor=25, req_major=36, rpolar=50, 
    416         req_minor_pd=0, req_minor_pd_n=1, 
    417         req_major_pd=0, req_major_pd_n=1, 
    418         rpolar_pd=.2, rpolar_pd_n=30, 
    419         theta_pd=15, theta_pd_n=45, 
    420         phi_pd=15, phi_pd_n=1, 
    421         psi_pd=15, psi_pd_n=1, 
    422         ) 
    423     return 'triaxial_ellipsoid', pars 
    424  
    425 @model('sphpy') 
    426 def spherepy(): 
    427     pars = dict( 
    428         scale=1, background=0, 
    429         sld=6, solvent_sld=1, 
    430         radius=120, 
    431         radius_pd=.2, radius_pd_n=45, 
    432         ) 
    433     return 'spherepy', pars 
    434  
    435 @model('sph') 
    436 def sphere(): 
    437     pars = dict( 
    438         scale=1, background=0, 
    439         sld=6, solvent_sld=1, 
    440         radius=120, 
    441         radius_pd=.2, radius_pd_n=45, 
    442         ) 
    443     return 'sphere', pars 
    444  
    445 @model('lam') 
    446 def lamellar(): 
    447     pars = dict( 
    448         scale=1, background=0, 
    449         sld=6, solvent_sld=1, 
    450         thickness=40, 
    451         thickness_pd= 0.2, thickness_pd_n=40, 
    452         ) 
    453     return 'lamellar', pars 
    454  
    455350if __name__ == "__main__": 
    456351    main() 
  • sasmodels/models/capped_cylinder.py

    r19dcb933 rd547f16  
    162162 
    163163 
     164demo = dict( 
     165    scale=1, background=0, 
     166    sld=6, solvent_sld=1, 
     167    radius=260, cap_radius=290, length=290, 
     168    theta=30, phi=15, 
     169    radius_pd=.2, radius_pd_n=1, 
     170    cap_radius_pd=.2, cap_radius_pd_n=1, 
     171    length_pd=.2, length_pd_n=10, 
     172    theta_pd=15, theta_pd_n=45, 
     173    phi_pd=15, phi_pd_n=1, 
     174    ) 
    164175 
  • sasmodels/models/core_shell_cylinder.py

    r19dcb933 rd547f16  
    168168    return whole, whole-core 
    169169 
     170demo = dict( 
     171    scale=1, background=0, 
     172    core_sld=6, shell_sld=8, solvent_sld=1, 
     173    radius=45, thickness=25, length=340, 
     174    theta=30, phi=15, 
     175    radius_pd=.2, radius_pd_n=1, 
     176    length_pd=.2, length_pd_n=10, 
     177    thickness_pd=.2, thickness_pd_n=10, 
     178    theta_pd=15, theta_pd_n=45, 
     179    phi_pd=15, phi_pd_n=1, 
     180    ) 
  • sasmodels/models/cylinder.py

    r19dcb933 rd547f16  
    151151    return 0.5 * (ddd)**(1./3.) 
    152152 
     153# For testing against the old sasview models, include the converted parameter 
     154# names and the target sasview model name. 
     155oldname='CylinderModel' 
     156oldpars=dict(theta='cyl_theta', phi='cyl_phi', sld='sldCyl', solvent_sld='sldSolv') 
     157 
     158# parameters for demo 
     159demo = dict( 
     160    scale=1, background=0, 
     161    sld=6, solvent_sld=1, 
     162    #radius=5, length=20, 
     163    radius=260, length=290, 
     164    theta=30, phi=0, 
     165    radius_pd=.2, radius_pd_n=9, 
     166    length_pd=.2,length_pd_n=10, 
     167    theta_pd=15, theta_pd_n=45, 
     168    phi_pd=15, phi_pd_n=1, 
     169    ) 
     170 
  • sasmodels/models/ellipsoid.py

    r19dcb933 rd547f16  
    177177    ddd[valid] = 2.0*(delta+1.0)*rpolar*requatorial**2 
    178178    return 0.5*ddd**(1.0/3.0) 
     179 
     180 
     181demo = dict( 
     182        scale=1, background=0, 
     183        sld=6, solvent_sld=1, 
     184        rpolar=50, requatorial=30, 
     185        theta=30, phi=15, 
     186        rpolar_pd=.2, rpolar_pd_n=15, 
     187        requatorial_pd=.2, requatorial_pd_n=15, 
     188        theta_pd=15, theta_pd_n=45, 
     189        phi_pd=15, phi_pd_n=1, 
     190        ) 
  • sasmodels/models/lamellar.py

    r994d77f rd547f16  
    9494# ER defaults to 0.0 
    9595# VR defaults to 1.0 
     96 
     97demo = dict( 
     98        scale=1, background=0, 
     99        sld=6, solvent_sld=1, 
     100        thickness=40, 
     101        thickness_pd= 0.2, thickness_pd_n=40, 
     102        ) 
  • sasmodels/models/sphere.py

    r994d77f rd547f16  
    109109 
    110110# VR defaults to 1.0 
     111 
     112demo = dict( 
     113        scale=1, background=0, 
     114        sld=6, solvent_sld=1, 
     115        radius=120, 
     116        radius_pd=.2, radius_pd_n=45, 
     117        ) 
  • sasmodels/models/spherepy.py

    r10576d1 rd547f16  
    126126 
    127127# VR defaults to 1.0 
     128 
     129demo = dict( 
     130    scale=1, background=0, 
     131    sld=6, solvent_sld=1, 
     132    radius=120, 
     133    radius_pd=.2, radius_pd_n=45, 
     134    ) 
  • sasmodels/models/triaxial_ellipsoid.py

    r19dcb933 rd547f16  
    129129    return ellipsoid_ER(rpolar, np.sqrt(req_minor*req_major)) 
    130130 
     131demo = dict( 
     132        scale=1, background=0, 
     133        sld=6, solvent_sld=1, 
     134        theta=30, phi=15, psi=5, 
     135        req_minor=25, req_major=36, rpolar=50, 
     136        req_minor_pd=0, req_minor_pd_n=1, 
     137        req_major_pd=0, req_major_pd_n=1, 
     138        rpolar_pd=.2, rpolar_pd_n=30, 
     139        theta_pd=15, theta_pd_n=45, 
     140        phi_pd=15, phi_pd_n=1, 
     141        psi_pd=15, psi_pd_n=1, 
     142        ) 
Note: See TracChangeset for help on using the changeset viewer.