source: sasmodels/example/fit.py @ 1105286

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 1105286 was 1182da5, checked in by Paul Kienzle <pkienzle@…>, 9 years ago

fix parameter names in bumps examples

  • Property mode set to 100644
File size: 5.7 KB
RevLine 
[5378e40]1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
[87985ca]4import sys
[5378e40]5from bumps.names import *
[346bc88]6from sasmodels.core import load_model
[7cf2cfd]7from sasmodels.bumps_model import Model, Experiment
8from sasmodels.data import load_data, set_beam_stop, set_top
[d772f5d]9
10""" IMPORT THE DATA USED """
[7cf2cfd]11radial_data = load_data('DEC07267.DAT')
12set_beam_stop(radial_data, 0.00669, outer=0.025)
13set_top(radial_data, -.0185)
[87985ca]14
[7cf2cfd]15tan_data = load_data('DEC07266.DAT')
16set_beam_stop(tan_data, 0.00669, outer=0.025)
17set_top(tan_data, -.0185)
[87985ca]18#sas.set_half(tan_data, 'right')
19
20name = "ellipsoid" if len(sys.argv) < 2 else sys.argv[1]
21section = "radial" if len(sys.argv) < 3 else sys.argv[2]
[5d3d7b4]22if section not in ("radial","tangential","both"):
23    raise ValueError("section %r should be 'radial', 'tangential' or 'both'"
24            % section)
25data = radial_data if section != "tangential" else tan_data
26phi = 0 if section != "tangential" else 90
[346bc88]27kernel = load_model(name, dtype="single")
[abb22f4]28cutoff = 1e-3
[87985ca]29
30if name == "ellipsoid":
[7cf2cfd]31    model = Model(kernel,
[346bc88]32        scale=0.08,
[1182da5]33        r_polar=15, r_equatorial=800,
34        sld=.291, sld_solvent=7.105,
[346bc88]35        background=0,
36        theta=90, phi=phi,
37        theta_pd=15, theta_pd_n=40, theta_pd_nsigma=3,
[1182da5]38        r_polar_pd=0.222296, r_polar_pd_n=1, r_polar_pd_nsigma=0,
39        r_equatorial_pd=.000128, r_equatorial_pd_n=1, r_equatorial_pd_nsigma=0,
[346bc88]40        phi_pd=0, phi_pd_n=20, phi_pd_nsigma=3,
41        )
[8cdb9f1]42
43
44    # SET THE FITTING PARAMETERS
[1182da5]45    model.r_polar.range(15, 1000)
46    model.r_equatorial.range(15, 1000)
[346bc88]47    model.theta_pd.range(0, 360)
48    model.background.range(0,1000)
[abb22f4]49    model.scale.range(0, 10)
[8cdb9f1]50
51
[346bc88]52
[87985ca]53elif name == "lamellar":
[7cf2cfd]54    model = Model(kernel,
[346bc88]55        scale=0.08,
56        thickness=19.2946,
57        sld=5.38,sld_sol=7.105,
58        background=0.003,
59        thickness_pd= 0.37765, thickness_pd_n=10, thickness_pd_nsigma=3,
60        )
61
[8cdb9f1]62
63    # SET THE FITTING PARAMETERS
[87985ca]64    #model.thickness.range(0, 1000)
[8cdb9f1]65    #model.scale.range(0, 1)
[87985ca]66    #model.thickness_pd.range(0, 1000)
[8cdb9f1]67    #model.background.range(0, 1000)
[87985ca]68    model.sld.range(0, 1)
[8cdb9f1]69
70
[87985ca]71elif name == "cylinder":
[1726b21]72    """
73    pars = dict(scale=0.0023, radius=92.5, length=798.3,
[87985ca]74        sld=.29, solvent_sld=7.105, background=5,
[5d3d7b4]75        theta=0, phi=phi,
[87985ca]76        theta_pd=22.11, theta_pd_n=5, theta_pd_nsigma=3,
[1726b21]77        radius_pd=.0084, radius_pd_n=10, radius_pd_nsigma=3,
78        length_pd=0.493, length_pd_n=10, length_pd_nsigma=3,
[87985ca]79        phi_pd=0, phi_pd_n=5, phi_pd_nsigma=3,)
[1726b21]80        """
81    pars = dict(
[abb22f4]82        scale=.01, background=35,
[1182da5]83        sld=.291, sld_solvent=5.77,
[abb22f4]84        radius=250, length=178, 
[5d3d7b4]85        theta=90, phi=phi,
[abb22f4]86        radius_pd=0.1, radius_pd_n=5, radius_pd_nsigma=3,
[1726b21]87        length_pd=0.1,length_pd_n=5, length_pd_nsigma=3,
[abb22f4]88        theta_pd=10, theta_pd_n=50, theta_pd_nsigma=3,
89        phi_pd=0, phi_pd_n=10, phi_pd_nsigma=3)
[7cf2cfd]90    model = Model(kernel, **pars)
[a42fec0]91
92    # SET THE FITTING PARAMETERS
[1726b21]93    model.radius.range(1, 500)
[4001d6e]94    model.length.range(1, 5000)
[abb22f4]95    model.theta.range(-90,100)
96    model.theta_pd.range(0, 30)
97    model.theta_pd_n = model.theta_pd + 5
98    model.radius_pd.range(0, 1)
99    model.length_pd.range(0, 2)
100    model.scale.range(0, 10)
101    model.background.range(0, 100)
[a42fec0]102
103
[87985ca]104elif name == "core_shell_cylinder":
[7cf2cfd]105    model = Model(kernel,
[346bc88]106        scale= .031, radius=19.5, thickness=30, length=22,
[1182da5]107        sld_core=7.105, sld_shell=.291, sdl_solvent=7.105,
[346bc88]108        background=0, theta=0, phi=phi,
109
110        radius_pd=0.26, radius_pd_n=10, radius_pd_nsigma=3,
111        length_pd=0.26, length_pd_n=10, length_pd_nsigma=3,
112        thickness_pd=1, thickness_pd_n=1, thickness_pd_nsigma=1,
113        theta_pd=1, theta_pd_n=10, theta_pd_nsigma=3,
114        phi_pd=0.1, phi_pd_n=1, phi_pd_nsigma=1,
115        )
[a42fec0]116
117    # SET THE FITTING PARAMETERS
118    #model.radius.range(115, 1000)
119    #model.length.range(0, 2500)
120    #model.thickness.range(18, 38)
121    #model.thickness_pd.range(0, 1)
[87985ca]122    #model.phi.range(0, 90)
[a42fec0]123    #model.radius_pd.range(0, 1)
124    #model.length_pd.range(0, 1)
[87985ca]125    #model.theta_pd.range(0, 360)
[a42fec0]126    #model.background.range(0,5)
127    model.scale.range(0, 1)
[09e15be]128
[8faffcd]129
[ca6c007]130
[87985ca]131elif name == "capped_cylinder":
[7cf2cfd]132    model = Model(kernel,
[346bc88]133        scale=.08, radius=20, cap_radius=40, length=400,
[1182da5]134        sld=1, sld_solvent=6.3,
[346bc88]135        background=0, theta=0, phi=phi,
136        radius_pd=.1, radius_pd_n=5, radius_pd_nsigma=3,
137        cap_radius_pd=.1, cap_radius_pd_n=5, cap_radius_pd_nsigma=3,
138        length_pd=.1, length_pd_n=1, length_pd_nsigma=0,
139        theta_pd=.1, theta_pd_n=1, theta_pd_nsigma=0,
140        phi_pd=.1, phi_pd_n=1, phi_pd_nsigma=0,
141        )
[8cdb9f1]142
143    model.scale.range(0, 1)
144
145
[87985ca]146elif name == "triaxial_ellipsoid":
[7cf2cfd]147    model = Model(kernel,
[346bc88]148        scale=0.08, req_minor=15, req_major=20, rpolar=500,
[1182da5]149        sld=7.105, solvent_sld=.291,
[346bc88]150        background=5, theta=0, phi=phi, psi=0,
151        theta_pd=20, theta_pd_n=40, theta_pd_nsigma=3,
152        phi_pd=.1, phi_pd_n=1, phi_pd_nsigma=0,
153        psi_pd=30, psi_pd_n=1, psi_pd_nsigma=0,
154        req_minor_pd=.1, req_minor_pd_n=1, req_minor_pd_nsigma=0,
155        req_major_pd=.1, req_major_pd_n=1, req_major_pd_nsigma=0,
156        rpolar_pd=.1, rpolar_pd_n=1, rpolar_pd_nsigma=0,
157        )
[8cdb9f1]158
159    # SET THE FITTING PARAMETERS
[87985ca]160    model.req_minor.range(15, 1000)
161    model.req_major.range(15, 1000)
162    #model.rpolar.range(15, 1000)
[8cdb9f1]163    #model.background.range(0,1000)
164    #model.theta_pd.range(0, 360)
165    #model.phi_pd.range(0, 360)
166    #model.psi_pd.range(0, 360)
167
[87985ca]168else:
169    print "No parameters for %s"%name
170    sys.exit(1)
[8cdb9f1]171
[abb22f4]172model.cutoff = cutoff
[7cf2cfd]173M = Experiment(data=data, model=model)
[5d3d7b4]174if section == "both":
[7cf2cfd]175   tan_model = Model(model.kernel, **model.parameters())
[87985ca]176   tan_model.phi = model.phi - 90
[5d3d7b4]177   tan_model.cutoff = cutoff
[7cf2cfd]178   tan_M = Experiment(data=tan_data, model=tan_model)
[346bc88]179   problem = FitProblem([M, tan_M])
[87985ca]180else:
[346bc88]181   problem = FitProblem(M)
Note: See TracBrowser for help on using the repository browser.