Created
May 6, 2013 23:44
-
-
Save anonymous/5529209 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from scipy.optimize import curve_fit | |
| from numpy import * | |
| from matplotlib.pyplot import * | |
| x,y=loadtxt("7.675cm.txt",unpack=True) | |
| def Gau(x1, height, mu, sigma): | |
| return height*exp(-1/2*((x1-mu)/sigma)**2) | |
| #First peak | |
| x1=x[24:39] | |
| y1=y[24:39] | |
| p_guess = array([1, 1, 1])# initial guesses for peak | |
| popt, pcov = curve_fit(Gau, x1, y1, p_guess) # do fit | |
| plot(x1, Gau(x1, *popt), 'r-') # plot fit | |
| plot(x,y, 'b.') | |
| print'First Peak' | |
| print 'Height: ', popt[0], '+/-', sqrt(pcov.diagonal()[0]) # the fitted values | |
| print 'Mu: ', popt[1], '+/-', sqrt(pcov.diagonal()[1]) # the fitted values | |
| print 'Sigma: ', popt[2], '+/-', sqrt(pcov.diagonal()[2]) # the fitted values | |
| #Second Peak | |
| x2=x[14.5:15.5] | |
| y2=y[14.5:15.5] | |
| p_guess = array([1, 550, 50]) # initial guess for peak | |
| popt, pcov = curve_fit(Gau, x2, y2, p_guess) # do fit | |
| plot(x2, Gau(x2, *popt), 'g-') # plot fit | |
| print'Second Peak' | |
| print 'Height: ', popt[0], '+/-', sqrt(pcov.diagonal()[0]) # the fitted values | |
| print 'Mu: ', popt[1], '+/-', sqrt(pcov.diagonal()[1]) # the fitted values | |
| print 'Sigma: ', popt[2], '+/-', sqrt(pcov.diagonal()[2]) # the fitted values |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment