## Dark Frames:

 Exposure time (s) Image Mean (sigma)

## Histogram Fitting Code/ test

```
from astropy.io import fits
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
file = fits.open('300s_DarkFrame.fit')
file0 = file[0]
data1 = file0.data
#print(data1[0][:])
#print(np.shape(data1))
inten = data1.flatten()
#print(inten)
plt.close()
#hist = np.histogram(inten, bins = 'auto' )
plt.figure(1, facecolor = 'white')
h = plt.hist(inten, 100, (900, 1000), alpha=0.3, label = 'Histogram')
y = h[0]
xedge = h[1]
xcentre = (xedge + np.roll(xedge, -1))/2.0
x = xcentre[0:len(y)]
n = len(x) #the number of data
mean = sum(x)/n #note this correction
def func(x,a,x0,sigma):
<span style="white-space: pre;">   </span>return a*np.exp(-(x-x0)**2/(2*sigma**2))
print(len(y))
print(len(x))
#plt.figure(2)
#plt.plot(x, y)
popt, pcov = curve_fit(func, x, y, (1, mean, 1))
sx0 = str(round(popt[1],1))
ssigma = str(round((2*popt[2])**2,1))
plt.scatter(x, func(x, *popt), color = 'red', label = 'Fitted Gaussian \$y =\$'+ str(np.round(popt[0],1))+'\$e^{-(x - ' +sx0 +')^{2} / '+ ssigma +'}\$')
plt.legend()
plt.title('Constant temperature, Exposure ~300sec, Histogram fitted with Gaussian')
plt.xlabel('bins')
plt.ylabel('counts')
plt.axis([900, 1000, 0, 100000])
plt.show()

```

-- BekiChafer - 12 Oct 2017

Topic attachments
I Attachment History Action Size Date Who Comment
zip HistogramFitGraphs.zip r1 manage 315.1 K 12 Oct 2017 - 23:11 LunaMarieBorella1
Edit | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | More topic actions

Physics WebpagesRHUL WebpagesCampus Connect • Royal Holloway, University of London, Egham, Surrey TW20 0EX; Tel/Fax +44 (0)1784 434455/437520

Topic revision: r3 - 12 Oct 2017 - LunaMarieBorella1

 Home Public Web P P P P P View Edit Account
Copyright © 2008-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding RHUL Physics Department TWiki? Send feedback