source: sasmodels/example/multiscatfit.py @ b171acd

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since b171acd was 2c4a190, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

simplify use of multiple scattering in bumps fits

  • Property mode set to 100644
File size: 2.7 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3"""
4Fit model using multiple scattering.
5
6As of this writing, multiscattering isn't integrated into sasmodels, and a
7number of hacks are required to get it running as a fit.
8
9The appropriate items need to be on the python path.  These include
10sasview (for reading the data), sasmodels and bumps.  The multiscat module
11(currently in the sasmodels/explore directory) is also needed, either beside
12this example fit file, or by putting sasmdoels/explore on the python path.
13
14On Unix/Mac running as developer I do::
15
16    # Show the model without fitting
17    PYTHONPATH=..:../../bumps:../../sasview/src python multiscatfit.py
18
19    # Run the fit
20    PYTHONPATH=..:../../bumps:../../sasview/src ../../bumps/run.py \
21    multiscatfit.py --store=/tmp/t1
22
23You may be able to run multiscatfit.py against the distributed sasview
24application (if it is new enough, and if you have multiscat.py in the
25same directory).  You probably need a command such as::
26
27    sasview.exe bumps.cli multiscatfit.py --store=t1
28"""
29
30import sys
31from bumps.names import *
32from sasmodels.core import load_model
33from sasmodels.bumps_model import Model, Experiment
34from sasmodels.data import load_data, set_beam_stop, set_top
35
36from sasmodels.multiscat import MultipleScattering
37
38## Load the data
39#data = load_data('DEC07267.DAT')
40#set_beam_stop(data, 0.003, outer=0.025)
41data = load_data('latex_smeared.xml', index=0)
42
43## Define the model
44kernel = load_model("ellipsoid")
45
46model = Model(
47    kernel,
48    scale=0.005, background=0.05,
49    radius_polar=2200, radius_equatorial=2200,
50    sld=.291, sld_solvent=7.105,
51    #theta=90, theta_pd=0, theta_pd_n=0, theta_pd_nsigma=3,
52    #phi=90, phi_pd=0, phi_pd_n=20, phi_pd_nsigma=3,
53    radius_polar_pd=0.222296, radius_polar_pd_n=1, radius_polar_pd_nsigma=0,
54    radius_equatorial_pd=.000128, radius_equatorial_pd_n=1, radius_equatorial_pd_nsigma=0,
55    )
56
57# Tie the model to the data
58M = Experiment(data=data, model=model)
59
60# Stack mulitple scattering on top of the existing resolution function.
61M.resolution = MultipleScattering(resolution=M.resolution, probability=0.)
62
63# SET THE FITTING PARAMETERS
64model.radius_polar.range(15, 3000)
65model.radius_equatorial.range(15, 3000)
66#model.theta.range(0, 90)
67#model.theta_pd.range(0,10)
68#model.phi_pd.range(0,20)
69#model.phi.range(0, 180)
70model.background.range(0,1000)
71model.scale.range(0, 0.1)
72
73# The multiple scattering probability parameter is in the resolution function
74# instead of the scattering function, so access it through M.resolution
75M.scattering_probability.range(0.0, 0.9)
76
77# Let bumps know that we are fitting this experiment
78problem = FitProblem(M)
79
80if __name__ == "__main__":
81    #M.theory()
82    M.plot()
83    import pylab; pylab.show()
Note: See TracBrowser for help on using the repository browser.