source: sasmodels/example/simul_fit.py @ 39a06c9

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 39a06c9 was 74b0495, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

update oriented sesans and simultaneous fit examples

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[1a4d4c0]1from bumps.names import *
2from sasmodels.core import load_model
3from sasmodels.bumps_model import Model, Experiment
4from sasmodels.data import load_data, plot_data
5
[74b0495]6# latex data, same sample usans and sans
7# particles radius ~2300, uniform dispersity
8datasets = load_data('latex_smeared.xml', index='all')
9#[print(data) for data in datasets]
10
11# A single sphere model to share between the datasets.  We will use
12# FreeVariables below to set the parameters that are independent between
13# the datasets.
14kernel = load_model('sphere')
15pars = dict(scale=0.01, background=0.0, sld=5.0, sld_solvent=0.0, radius=1500.,
16            #radius_pd=0.1, radius_pd_n=35,
17            )
[1a4d4c0]18model = Model(kernel, **pars)
19
[74b0495]20# radius and polydispersity (if any) are shared
21model.radius.range(0, inf)
22#model.radius_pd.range(0, 1)
23
24# Contrast and dilution are the same for both measurements, but are not
25# separable with a single measurement (i.e., I(q) ~ F(q) contrast^2 Vf),
26# so fit one of scale, sld or solvent sld.  With absolute scaling from
27# data reduction, can use the same parameter for both datasets.
28model.scale.range(0, inf)
29#model.sld.range(-inf, inf)
30#model.sld_solvent.range(-inf, inf)
31
32# Background is different for sans and usans so set it as a free variable
33# in the model.
[1a4d4c0]34free = FreeVariables(
[74b0495]35    names=[data.run[0] for data in datasets],
[1a4d4c0]36    background=model.background,
37    )
38free.background.range(-inf, inf)
39
[74b0495]40# Note: can access the parameters for the individual models using
41# free.background[0] and free.background[1], setting constraints or
42# ranges as appropriate.
43
44# For more complex systems where different datasets require independent models,
45# separate models can be defined, with parameters tied together using
46# constraint expressions.  For example, the following could be used to fit
47# data set 1 to spheres and data set 2 to cylinders of the same volume:
48#    model1 = Model(load_model('sphere'))
49#    model2 = Model(load_model('cylinder'))
50#    model1.sld = model2.sld
51#    model1.sld_solvent = model2.sld_solvent
52#    model1.scale = model2.scale
53#    # set cylinders and spheres to the same volume
54#    model1.radius = (3/4*model2.radius**2*model2.length)**(1/3)
55#    model1.background.range(0, 2)
56#    model2.background.range(0, 2)
57
58# Setup the experiments, sharing the same model across all datasets.
59M = [Experiment(data=data, model=model, name=data.run[0]) for data in datasets]
60
61problem = FitProblem(M, freevars=free)
Note: See TracBrowser for help on using the repository browser.