-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBT_noise.py
39 lines (32 loc) · 1.22 KB
/
BT_noise.py
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
# GET NOISE FROM IMAGE THROUGH A GAUSSIAN FIT
print 'Running BT_noise.py'
from astropy.modeling import models, fitting
def get_noise(data,fthreshold=5,savefigure=False):
# RETURNS THE SKY OFFSET AND THE NOISE STANDARD DEVIATION
# offset, noise = get_noise(data)
threshold=fthreshold*median(data)
data_values=data.reshape(1,size(data))
data_values=data_values[where(data_values<threshold)]
nbins=100
#
figure('noise')
clf()
counts, bins, patches=hist(data_values,bins=nbins,color='b')
meanbins=zeros(size(counts))
for i in range(size(counts)):
meanbins[i]=(bins[i]+bins[i+1])/2.
p_init = models.Gaussian1D(amplitude=counts.max(),mean=median(data),stddev=std(bins)/2.)
fit_p = fitting.LevMarLSQFitter()
with warnings.catch_warnings():
# Ignore model linearity warning from the fitter
warnings.simplefilter('ignore')
p = fit_p(p_init, meanbins, counts)
#
plot(meanbins,p(meanbins),color='r',linewidth=2)
title(r'offset = %g, noise = %g'%(p.mean.value, p.stddev.value))
print 'offset =', p.mean.value, 'noise =', p.stddev.value
#
if savefigure:
savefig('noise.pdf')
#
return p.mean.value, p.stddev.value