Changeset 6824af5 in sasmodels for example


Ignore:
Timestamp:
Mar 17, 2016 10:48:04 AM (8 years ago)
Author:
krzywon
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:
8898d0f, bdb653c
Parents:
84db7a5 (diff), 54954e1 (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.
Message:

Merge remote-tracking branch 'origin/master'

Location:
example
Files:
1 added
2 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • example/sesansfit.sh

    • Property mode changed from 100644 to 100755
    r5be92e8 r15bd6e7  
    88set -x 
    99 
    10 python -m bumps.cli $* 
     10pythonw -m bumps.cli $* 
  • example/sesans_parameters_css-hs.py

    ra98958b r84db7a5  
    88# Enter the model name to use 
    99model_name = "core_shell_sphere*hardsphere" 
     10 
     11# DO NOT MODIFY THIS LINE 
     12model = sesansfit.get_bumps_model(model_name) 
    1013 
    1114# Enter any custom parameters 
     
    1922# Initial parameter values (if other than defaults) 
    2023initial_vals = { 
    21     "scale" : 0.09, 
    2224    "core_sld" : 1.0592, 
    2325    "solvent_sld" : 2.88, 
    24     "shell_sld" : 2.88, 
    2526    "radius" : 890, 
    26     "thickness" : 130, 
    27     "volfraction" : 0.45 
     27    "thickness" : 130 
    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 
     42model.scale = phi*(1-phi) 
     43model.volfraction = phi 
     44model.shell_sld = pen*2.88 
     45 
    3846# Send to the fitting engine 
    3947problem = sesansfit.sesans_fit(sesans_file, model_name, initial_vals, custom_params, param_range) 
  • example/sesans_parameters_sphere.py

    ra98958b r84db7a5  
    99model_name = "sphere" 
    1010 
     11# DO NOT MODIFY THIS LINE 
     12model = sesansfit.get_bumps_model(model_name) 
     13 
    1114# Enter any custom parameters 
     15# name = Parameter(initial_value, name='name') 
    1216phi = Parameter(0.10, name='phi') 
     17# Add the parameters to this list that should be displayed in the fitting window 
    1318custom_params = {"phi" : phi} 
    1419 
    15 # SESANS data file 
     20# SESANS data file name 
    1621sesans_file = "sphere.ses" 
    1722 
    1823# Initial parameter values (if other than defaults) 
     24# "model_parameter_name" : value 
    1925initial_vals = { 
    20     "scale" : phi*(1 - phi), 
    2126    "sld" : 7.0, 
     27    "radius" : 1000, 
    2228    "solvent_sld" : 1.0, 
    23     "radius" : 1000, 
    2429} 
    2530 
    2631# Ranges for parameters if other than default 
     32# "model_parameter_name" : [min, max] 
    2733param_range = { 
    2834    "phi" : [0.001, 0.5], 
     
    3036} 
    3137 
     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 
     42model.scale = phi*(1-phi) 
     43 
    3244# Send to the fitting engine 
    33 problem = sesansfit.sesans_fit(sesans_file, model_name, initial_vals, custom_params, param_range) 
     45# DO NOT MODIFY THIS LINE 
     46problem = sesansfit.sesans_fit(sesans_file, model, initial_vals, custom_params, param_range) 
     47 
  • example/sesansfit.py

    ra98958b r84db7a5  
    1 #TODO: Convert units properly (nm -> A) 
    2 #TODO: Implement constraints 
    3  
    41from bumps.names import * 
    5 from sasmodels import core, bumps_model 
     2from sasmodels import core, bumps_model, sesans 
    63 
    74HAS_CONVERTER = True 
     
    118    HAS_CONVERTER = False 
    129 
    13 def sesans_fit(file, model_name, initial_vals={}, custom_params={}, param_range=[]): 
     10def get_bumps_model(model_name): 
     11    kernel = core.load_model(model_name) 
     12    model = bumps_model.Model(kernel) 
     13    return model 
     14 
     15def sesans_fit(file, model, initial_vals={}, custom_params={}, param_range=[]): 
    1416    """ 
    15  
    1617    @param file: SESANS file location 
    17     @param model_name: model name string - can be model, model_1 * model_2, and/or model_1 + model_2 
     18    @param model: Bumps model object or model name - can be model, model_1 * model_2, and/or model_1 + model_2 
    1819    @param initial_vals: dictionary of {param_name : initial_value} 
    1920    @param custom_params: dictionary of {custom_parameter_name : Parameter() object} 
    2021    @param param_range: dictionary of {parameter_name : [minimum, maximum]} 
     22    @param constraints: dictionary of {parameter_name : constraint} 
    2123    @return: FitProblem for Bumps usage 
    2224    """ 
     
    2931            default_unit = "A" 
    3032            data_conv_q = Converter(data._xunit) 
     33            for x in data.x: 
     34                print x 
    3135            data.x = data_conv_q(data.x, units=default_unit) 
     36            for x in data.x: 
     37                print x 
    3238            data._xunit = default_unit 
    3339 
     
    5157        data = SESANSData1D() 
    5258 
    53     radius = 1000 
     59    if "radius" in initial_vals: 
     60        radius = initial_vals.get("radius") 
     61    else: 
     62        radius = 1000 
    5463    data.Rmax = 3*radius # [A] 
    5564 
    56     kernel = core.load_model(model_name) 
    57     model = bumps_model.Model(kernel) 
     65    if isinstance(model, basestring): 
     66        model = get_bumps_model(model) 
    5867 
    59     # Load custom parameters, initial values and parameter constraints 
     68    # Load custom parameters, initial values and parameter ranges 
    6069    for k, v in custom_params.items(): 
    6170        setattr(model, k, v) 
     
    6978            setattr(param.bounds, "limits", v) 
    7079 
    71     if False: # have sans data 
     80    if False: # for future implementation 
    7281        M_sesans = bumps_model.Experiment(data=data, model=model) 
    7382        M_sans = bumps_model.Experiment(data=sans_data, model=model) 
Note: See TracChangeset for help on using the changeset viewer.