forked from diffpy/diffpy.srfit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplerecipe.py
More file actions
63 lines (46 loc) · 1.69 KB
/
simplerecipe.py
File metadata and controls
63 lines (46 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
########################################################################
#
# diffpy.srfit by DANSE Diffraction group
# Simon J. L. Billinge
# (c) 2009 The Trustees of Columbia University
# in the City of New York. All rights reserved.
#
# File coded by: Chris Farrow
#
# See AUTHORS.txt for a list of people who contributed.
# See LICENSE_DANSE.txt for license information.
#
########################################################################
"""Example of simplified fitting.
This is like gaussianrecipe.py, but it uses the SimpleRecipe, which
integrates the FitContribution and Profile objects for simple recipe
creation.
"""
from diffpy.srfit.fitbase import SimpleRecipe
######
# Example Code
def main():
"""Set up a simple recipe in a few lines."""
# The SimpleRecipe class is a type of FitRecipe. It provides attribute-like
# access to variables and a residual function that can be minimized.
recipe = SimpleRecipe()
# Load text from file.
recipe.loadtxt("data/gaussian.dat")
# Set the equation. The variable "x" is taken from the data that was just
# loaded. The other variables, "A", "x0" and "sigma" are turned into
# attributes with an initial value of 0.
recipe.setEquation("A * exp(-0.5*(x-x0)**2/sigma**2)")
# We can give them other values here.
recipe.A = 1
recipe.x0 = 5
recipe.sigma = 1
# We explicitly optimize the residual method of the SimpleRecipe
from scipy.optimize import leastsq
leastsq(recipe.residual, recipe.values)
# Print the results
recipe.printResults()
return
if __name__ == "__main__":
main()
# End of file