source: sasmodels/example/fit.py @ 49d1d42f

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 49d1d42f was 5d3d7b4, checked in by Paul Kienzle <pkienzle@…>, 10 years ago

fix tangential and simultaneous fit in example

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