Changes in / [6824af5:54954e1] in sasmodels


Ignore:
Files:
2 added
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • example/sesans_parameters_css-hs.py

    r84db7a5 ra98958b  
    88# Enter the model name to use 
    99model_name = "core_shell_sphere*hardsphere" 
    10  
    11 # DO NOT MODIFY THIS LINE 
    12 model = sesansfit.get_bumps_model(model_name) 
    1310 
    1411# Enter any custom parameters 
     
    2219# Initial parameter values (if other than defaults) 
    2320initial_vals = { 
     21    "scale" : 0.09, 
    2422    "core_sld" : 1.0592, 
    2523    "solvent_sld" : 2.88, 
     24    "shell_sld" : 2.88, 
    2625    "radius" : 890, 
    27     "thickness" : 130 
     26    "thickness" : 130, 
     27    "volfraction" : 0.45 
    2828} 
    2929 
     
    3636} 
    3737 
    38 # Constraints 
    39 # model.param_name = f(other params) 
    40 # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius and scale are model functions and phi is 
    41 # a custom parameter 
    42 model.scale = phi*(1-phi) 
    43 model.volfraction = phi 
    44 model.shell_sld = pen*2.88 
    45  
    4638# Send to the fitting engine 
    4739problem = sesansfit.sesans_fit(sesans_file, model_name, initial_vals, custom_params, param_range) 
  • example/sesans_parameters_sphere.py

    r84db7a5 ra98958b  
    99model_name = "sphere" 
    1010 
    11 # DO NOT MODIFY THIS LINE 
    12 model = sesansfit.get_bumps_model(model_name) 
    13  
    1411# Enter any custom parameters 
    15 # name = Parameter(initial_value, name='name') 
    1612phi = Parameter(0.10, name='phi') 
    17 # Add the parameters to this list that should be displayed in the fitting window 
    1813custom_params = {"phi" : phi} 
    1914 
    20 # SESANS data file name 
     15# SESANS data file 
    2116sesans_file = "sphere.ses" 
    2217 
    2318# Initial parameter values (if other than defaults) 
    24 # "model_parameter_name" : value 
    2519initial_vals = { 
     20    "scale" : phi*(1 - phi), 
    2621    "sld" : 7.0, 
     22    "solvent_sld" : 1.0, 
    2723    "radius" : 1000, 
    28     "solvent_sld" : 1.0, 
    2924} 
    3025 
    3126# Ranges for parameters if other than default 
    32 # "model_parameter_name" : [min, max] 
    3327param_range = { 
    3428    "phi" : [0.001, 0.5], 
     
    3630} 
    3731 
    38 # Constraints 
    39 # model.param_name = f(other params) 
    40 # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius and scale are model functions and phi is 
    41 # a custom parameter 
    42 model.scale = phi*(1-phi) 
    43  
    4432# Send to the fitting engine 
    45 # DO NOT MODIFY THIS LINE 
    46 problem = sesansfit.sesans_fit(sesans_file, model, initial_vals, custom_params, param_range) 
    47  
     33problem = sesansfit.sesans_fit(sesans_file, model_name, initial_vals, custom_params, param_range) 
  • example/sesansfit.py

    r84db7a5 ra98958b  
     1#TODO: Convert units properly (nm -> A) 
     2#TODO: Implement constraints 
     3 
    14from bumps.names import * 
    2 from sasmodels import core, bumps_model, sesans 
     5from sasmodels import core, bumps_model 
    36 
    47HAS_CONVERTER = True 
     
    811    HAS_CONVERTER = False 
    912 
    10 def get_bumps_model(model_name): 
    11     kernel = core.load_model(model_name) 
    12     model = bumps_model.Model(kernel) 
    13     return model 
     13def sesans_fit(file, model_name, initial_vals={}, custom_params={}, param_range=[]): 
     14    """ 
    1415 
    15 def sesans_fit(file, model, initial_vals={}, custom_params={}, param_range=[]): 
    16     """ 
    1716    @param file: SESANS file location 
    18     @param model: Bumps model object or model name - can be model, model_1 * model_2, and/or model_1 + model_2 
     17    @param model_name: model name string - can be model, model_1 * model_2, and/or model_1 + model_2 
    1918    @param initial_vals: dictionary of {param_name : initial_value} 
    2019    @param custom_params: dictionary of {custom_parameter_name : Parameter() object} 
    2120    @param param_range: dictionary of {parameter_name : [minimum, maximum]} 
    22     @param constraints: dictionary of {parameter_name : constraint} 
    2321    @return: FitProblem for Bumps usage 
    2422    """ 
     
    3129            default_unit = "A" 
    3230            data_conv_q = Converter(data._xunit) 
    33             for x in data.x: 
    34                 print x 
    3531            data.x = data_conv_q(data.x, units=default_unit) 
    36             for x in data.x: 
    37                 print x 
    3832            data._xunit = default_unit 
    3933 
     
    5751        data = SESANSData1D() 
    5852 
    59     if "radius" in initial_vals: 
    60         radius = initial_vals.get("radius") 
    61     else: 
    62         radius = 1000 
     53    radius = 1000 
    6354    data.Rmax = 3*radius # [A] 
    6455 
    65     if isinstance(model, basestring): 
    66         model = get_bumps_model(model) 
     56    kernel = core.load_model(model_name) 
     57    model = bumps_model.Model(kernel) 
    6758 
    68     # Load custom parameters, initial values and parameter ranges 
     59    # Load custom parameters, initial values and parameter constraints 
    6960    for k, v in custom_params.items(): 
    7061        setattr(model, k, v) 
     
    7869            setattr(param.bounds, "limits", v) 
    7970 
    80     if False: # for future implementation 
     71    if False: # have sans data 
    8172        M_sesans = bumps_model.Experiment(data=data, model=model) 
    8273        M_sans = bumps_model.Experiment(data=sans_data, model=model) 
  • sasmodels/data.py

    r84db7a5 r7824276  
    440440 
    441441    if use_data or use_theory: 
    442         is_tof = np.any(data.lam!=data.lam[0]) 
    443442        if num_plots > 1: 
    444443            plt.subplot(1, num_plots, 1) 
    445444        if use_data: 
    446             if is_tof: 
    447                 plt.errorbar(data.x, np.log(data.y)/(data.lam*data.lam), yerr=data.dy/data.y/(data.lam*data.lam)) 
    448             else: 
    449                 plt.errorbar(data.x, data.y, yerr=data.dy) 
     445            plt.errorbar(data.x, data.y, yerr=data.dy) 
    450446        if theory is not None: 
    451             if is_tof: 
    452                 plt.plot(data.x, np.log(theory)/(data.lam*data.lam), '-', hold=True) 
    453             else: 
    454                 plt.plot(data.x, theory, '-', hold=True) 
     447            plt.plot(data.x, theory, '-', hold=True) 
    455448        if limits is not None: 
    456449            plt.ylim(*limits) 
    457  
    458         plt.xlabel('spin echo length ({})'.format(data._xunit)) 
    459         if is_tof: 
    460             plt.ylabel('(Log (P/P$_0$))/$\lambda^2$') 
    461         else: 
    462             plt.ylabel('polarization (P/P0)') 
    463  
     450        plt.xlabel('spin echo length (nm)') 
     451        plt.ylabel('polarization (P/P0)') 
    464452 
    465453    if resid is not None: 
     
    467455            plt.subplot(1, num_plots, (use_data or use_theory) + 1) 
    468456        plt.plot(data.x, resid, 'x') 
    469         plt.xlabel('spin echo length ({})'.format(data._xunit)) 
     457        plt.xlabel('spin echo length (nm)') 
    470458        plt.ylabel('residuals (P/P0)') 
    471459 
  • sasmodels/models/hardsphere.py

    r84db7a5 raa2edb2  
    77the maths needs to be modified (no \Beta(Q) correction yet in sasview). 
    88 
    9 effect_radius is the effective hard sphere radius. 
     9radius_effective is the effective hard sphere radius. 
    1010volfraction is the volume fraction occupied by the spheres. 
    1111 
     
    5353        systems. Though strictly the maths needs to be modified - 
    5454    which sasview does not do yet. 
    55     effect_radius is the hard sphere radius 
     55    radius_effective is the hard sphere radius 
    5656    volfraction is the volume fraction occupied by the spheres. 
    5757""" 
     
    6060 
    6161#             ["name", "units", default, [lower, upper], "type","description"], 
    62 parameters = [["effect_radius", "Ang", 50.0, [0, inf], "volume", 
     62parameters = [["radius_effective", "Ang", 50.0, [0, inf], "volume", 
    6363               "effective radius of hard sphere"], 
    6464              ["volfraction", "", 0.2, [0, 0.74], "", 
     
    7575      double D,A,B,G,X,X2,X4,S,C,FF,HARDSPH; 
    7676 
    77       if(fabs(effect_radius) < 1.E-12) { 
     77      if(fabs(radius_effective) < 1.E-12) { 
    7878               HARDSPH=1.0; 
    7979               return(HARDSPH); 
     
    8484      A= (1.+2.*volfraction)*D; 
    8585      A *=A; 
    86       X=fabs(q*effect_radius*2.0); 
     86      X=fabs(q*radius_effective*2.0); 
    8787 
    8888      if(X < 5.E-06) { 
     
    147147# VR defaults to 1.0 
    148148 
    149 demo = dict(effect_radius=200, volfraction=0.2, effect_radius_pd=0.1, effect_radius_pd_n=40) 
     149demo = dict(radius_effective=200, volfraction=0.2, radius_effective_pd=0.1, radius_effective_pd_n=40) 
    150150oldname = 'HardsphereStructure' 
    151 oldpars = dict(effect_radius="effect_radius",effect_radius_pd="effect_radius_pd",effect_radius_pd_n="effect_radius_pd_n") 
     151oldpars = dict(radius_effective="effect_radius",radius_effective_pd="effect_radius_pd",radius_effective_pd_n="effect_radius_pd_n") 
    152152# Q=0.001 is in the Taylor series, low Q part, so add Q=0.1, assuming double precision sasview is correct 
    153153tests = [ 
    154         [ {'scale': 1.0, 'background' : 0.0, 'effect_radius' : 50.0, 'volfraction' : 0.2, 
    155            'effect_radius_pd' : 0}, [0.001,0.1], [0.209128,0.930587]] 
     154        [ {'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0, 'volfraction' : 0.2, 
     155           'radius_effective_pd' : 0}, [0.001,0.1], [0.209128,0.930587]] 
    156156        ] 
    157157# ADDED by: RKH  ON: 16Mar2016  using equations from FISH as better than orig sasview, see notes above. Added Taylor expansions at small Q,  
Note: See TracChangeset for help on using the changeset viewer.