Changeset 84db7a5 in sasmodels
- Timestamp:
- Mar 17, 2016 10:47:47 AM (9 years ago)
- 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:
- 6824af5
- Parents:
- 4373d62
- Files:
-
- 1 added
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
example/sesans_parameters_css-hs.py
ra98958b r84db7a5 8 8 # Enter the model name to use 9 9 model_name = "core_shell_sphere*hardsphere" 10 11 # DO NOT MODIFY THIS LINE 12 model = sesansfit.get_bumps_model(model_name) 10 13 11 14 # Enter any custom parameters … … 19 22 # Initial parameter values (if other than defaults) 20 23 initial_vals = { 21 "scale" : 0.09,22 24 "core_sld" : 1.0592, 23 25 "solvent_sld" : 2.88, 24 "shell_sld" : 2.88,25 26 "radius" : 890, 26 "thickness" : 130, 27 "volfraction" : 0.45 27 "thickness" : 130 28 28 } 29 29 … … 36 36 } 37 37 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 38 46 # Send to the fitting engine 39 47 problem = sesansfit.sesans_fit(sesans_file, model_name, initial_vals, custom_params, param_range) -
example/sesans_parameters_sphere.py
ra98958b r84db7a5 9 9 model_name = "sphere" 10 10 11 # DO NOT MODIFY THIS LINE 12 model = sesansfit.get_bumps_model(model_name) 13 11 14 # Enter any custom parameters 15 # name = Parameter(initial_value, name='name') 12 16 phi = Parameter(0.10, name='phi') 17 # Add the parameters to this list that should be displayed in the fitting window 13 18 custom_params = {"phi" : phi} 14 19 15 # SESANS data file 20 # SESANS data file name 16 21 sesans_file = "sphere.ses" 17 22 18 23 # Initial parameter values (if other than defaults) 24 # "model_parameter_name" : value 19 25 initial_vals = { 20 "scale" : phi*(1 - phi),21 26 "sld" : 7.0, 27 "radius" : 1000, 22 28 "solvent_sld" : 1.0, 23 "radius" : 1000,24 29 } 25 30 26 31 # Ranges for parameters if other than default 32 # "model_parameter_name" : [min, max] 27 33 param_range = { 28 34 "phi" : [0.001, 0.5], … … 30 36 } 31 37 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 32 44 # 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 46 problem = 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 constraints3 4 1 from bumps.names import * 5 from sasmodels import core, bumps_model 2 from sasmodels import core, bumps_model, sesans 6 3 7 4 HAS_CONVERTER = True … … 11 8 HAS_CONVERTER = False 12 9 13 def sesans_fit(file, model_name, initial_vals={}, custom_params={}, param_range=[]): 10 def get_bumps_model(model_name): 11 kernel = core.load_model(model_name) 12 model = bumps_model.Model(kernel) 13 return model 14 15 def sesans_fit(file, model, initial_vals={}, custom_params={}, param_range=[]): 14 16 """ 15 16 17 @param file: SESANS file location 17 @param model _name: model name string- can be model, model_1 * model_2, and/or model_1 + model_218 @param model: Bumps model object or model name - can be model, model_1 * model_2, and/or model_1 + model_2 18 19 @param initial_vals: dictionary of {param_name : initial_value} 19 20 @param custom_params: dictionary of {custom_parameter_name : Parameter() object} 20 21 @param param_range: dictionary of {parameter_name : [minimum, maximum]} 22 @param constraints: dictionary of {parameter_name : constraint} 21 23 @return: FitProblem for Bumps usage 22 24 """ … … 29 31 default_unit = "A" 30 32 data_conv_q = Converter(data._xunit) 33 for x in data.x: 34 print x 31 35 data.x = data_conv_q(data.x, units=default_unit) 36 for x in data.x: 37 print x 32 38 data._xunit = default_unit 33 39 … … 51 57 data = SESANSData1D() 52 58 53 radius = 1000 59 if "radius" in initial_vals: 60 radius = initial_vals.get("radius") 61 else: 62 radius = 1000 54 63 data.Rmax = 3*radius # [A] 55 64 56 kernel = core.load_model(model_name)57 model = bumps_model.Model(kernel)65 if isinstance(model, basestring): 66 model = get_bumps_model(model) 58 67 59 # Load custom parameters, initial values and parameter constraints68 # Load custom parameters, initial values and parameter ranges 60 69 for k, v in custom_params.items(): 61 70 setattr(model, k, v) … … 69 78 setattr(param.bounds, "limits", v) 70 79 71 if False: # have sans data80 if False: # for future implementation 72 81 M_sesans = bumps_model.Experiment(data=data, model=model) 73 82 M_sans = bumps_model.Experiment(data=sans_data, model=model) -
sasmodels/data.py
r7824276 r84db7a5 440 440 441 441 if use_data or use_theory: 442 is_tof = np.any(data.lam!=data.lam[0]) 442 443 if num_plots > 1: 443 444 plt.subplot(1, num_plots, 1) 444 445 if use_data: 445 plt.errorbar(data.x, data.y, yerr=data.dy) 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) 446 450 if theory is not None: 447 plt.plot(data.x, theory, '-', hold=True) 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) 448 455 if limits is not None: 449 456 plt.ylim(*limits) 450 plt.xlabel('spin echo length (nm)') 451 plt.ylabel('polarization (P/P0)') 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 452 464 453 465 if resid is not None: … … 455 467 plt.subplot(1, num_plots, (use_data or use_theory) + 1) 456 468 plt.plot(data.x, resid, 'x') 457 plt.xlabel('spin echo length ( nm)')469 plt.xlabel('spin echo length ({})'.format(data._xunit)) 458 470 plt.ylabel('residuals (P/P0)') 459 471 -
sasmodels/models/hardsphere.py
raa2edb2 r84db7a5 7 7 the maths needs to be modified (no \Beta(Q) correction yet in sasview). 8 8 9 radius_effectiveis the effective hard sphere radius.9 effect_radius is the effective hard sphere radius. 10 10 volfraction is the volume fraction occupied by the spheres. 11 11 … … 53 53 systems. Though strictly the maths needs to be modified - 54 54 which sasview does not do yet. 55 radius_effectiveis the hard sphere radius55 effect_radius is the hard sphere radius 56 56 volfraction is the volume fraction occupied by the spheres. 57 57 """ … … 60 60 61 61 # ["name", "units", default, [lower, upper], "type","description"], 62 parameters = [[" radius_effective", "Ang", 50.0, [0, inf], "volume",62 parameters = [["effect_radius", "Ang", 50.0, [0, inf], "volume", 63 63 "effective radius of hard sphere"], 64 64 ["volfraction", "", 0.2, [0, 0.74], "", … … 75 75 double D,A,B,G,X,X2,X4,S,C,FF,HARDSPH; 76 76 77 if(fabs( radius_effective) < 1.E-12) {77 if(fabs(effect_radius) < 1.E-12) { 78 78 HARDSPH=1.0; 79 79 return(HARDSPH); … … 84 84 A= (1.+2.*volfraction)*D; 85 85 A *=A; 86 X=fabs(q* radius_effective*2.0);86 X=fabs(q*effect_radius*2.0); 87 87 88 88 if(X < 5.E-06) { … … 147 147 # VR defaults to 1.0 148 148 149 demo = dict( radius_effective=200, volfraction=0.2, radius_effective_pd=0.1, radius_effective_pd_n=40)149 demo = dict(effect_radius=200, volfraction=0.2, effect_radius_pd=0.1, effect_radius_pd_n=40) 150 150 oldname = 'HardsphereStructure' 151 oldpars = dict( radius_effective="effect_radius",radius_effective_pd="effect_radius_pd",radius_effective_pd_n="effect_radius_pd_n")151 oldpars = dict(effect_radius="effect_radius",effect_radius_pd="effect_radius_pd",effect_radius_pd_n="effect_radius_pd_n") 152 152 # Q=0.001 is in the Taylor series, low Q part, so add Q=0.1, assuming double precision sasview is correct 153 153 tests = [ 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]]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]] 156 156 ] 157 157 # 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.