|
1 | 1 | """ |
2 | 2 | This is a data file used to load in sesans data and fit it using the bumps engine |
| 3 | +
|
| 4 | +Usage: |
| 5 | +
|
| 6 | + bumps sesans_sphere_2micron.py |
3 | 7 | """ |
4 | | -import sesansfit |
5 | | -from bumps.names import Parameter |
| 8 | +from bumps.names import FitProblem, Parameter |
6 | 9 |
|
7 | | -# Enter the model name to use |
8 | | -model_name = "sphere" |
| 10 | +from sasdata import data_path |
9 | 11 |
|
10 | | -# DO NOT MODIFY THIS LINE |
11 | | -model = sesansfit.get_bumps_model(model_name) |
| 12 | +from sasmodels.bumps_model import Experiment, Model |
| 13 | +from sasmodels.core import load_model |
| 14 | +from sasmodels.data import load_data |
12 | 15 |
|
13 | | -# Enter any custom parameters |
14 | | -# name = Parameter(initial_value, name='name') |
15 | | -phi = Parameter(0.0855, name='phi') |
16 | | -# Add the parameters to this list that should be displayed in the fitting window |
17 | | -custom_params = {"phi" : phi} |
| 16 | +# Enter the model name and the datafile path |
| 17 | +model_name = "sphere" |
| 18 | +data_file = data_path / "sesans_data" / "sphere2micron.ses" |
18 | 19 |
|
19 | | -# SESANS data file name |
20 | | -sesans_file = "spheres2micron.ses" |
| 20 | +# Custom parameters for use in expressions |
| 21 | +# name = Parameter(initial_value, name='name') |
| 22 | +phi = Parameter(0.0855, name='phi') # scale = phi*(1-phi) |
21 | 23 |
|
22 | | -# Initial parameter values (if other than defaults) |
23 | | -# "model_parameter_name" : value |
24 | | -initial_vals = { |
| 24 | +# Initial parameter values and expressions (if other than defaults) |
| 25 | +# "model_parameter_name" : value or expression |
| 26 | +pars = { |
| 27 | + "scale": phi*(1-phi), |
25 | 28 | "sld" : 1.41, |
26 | 29 | "radius" : 10000, |
27 | 30 | "sld_solvent" : 2.70, |
28 | 31 | } |
29 | 32 |
|
30 | | -# Ranges for parameters if other than default |
31 | | -# "model_parameter_name" : [min, max] |
32 | | -param_range = { |
33 | | - "phi" : [0.001, 0.5], |
34 | | - "radius" : [100, 100000] |
35 | | -} |
| 33 | +# DO NOT MODIFY THIS LINE |
| 34 | +model = Model(load_model(model_name), **pars) |
36 | 35 |
|
37 | | -# Constraints |
| 36 | +# Bounds constraints |
38 | 37 | # model.param_name = f(other params) |
39 | | -# EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius |
40 | | -# and scale are model functions and phi is a custom parameter |
41 | | -model.scale = phi*(1-phi) |
| 38 | +model.radius.range(100, 100000) |
| 39 | +phi.range(0.001, 0.5) |
| 40 | + |
42 | 41 |
|
43 | 42 | # Send to the fitting engine |
44 | | -# DO NOT MODIFY THIS LINE |
45 | | -problem = sesansfit.sesans_fit(sesans_file, model, initial_vals, custom_params, param_range) |
| 43 | +# DO NOT MODIFY THESE LINES |
| 44 | +data = load_data(str(data_file)) |
| 45 | +M = Experiment(data=data, model=model) |
| 46 | +problem = FitProblem([M]) |
| 47 | + |
| 48 | +if __name__ == "__main__": |
| 49 | + import matplotlib.pyplot as plt |
| 50 | + |
| 51 | + print(f"==== {model_name} model for {data_file.name} has χ² = {problem.chisq_str()} ====") |
| 52 | + print(problem.summarize()) |
| 53 | + problem.plot() |
| 54 | + plt.show() |
0 commit comments