-
Notifications
You must be signed in to change notification settings - Fork 1
/
smoothing.py
41 lines (28 loc) · 878 Bytes
/
smoothing.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
40
41
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
data = np.loadtxt('onerun.txt', delimiter=',')
data = data.T
redshifts = data[0]
rhos = (data[1]/np.mean(data[1]))-1.
sigma = .01
def kernel(X0, X):
return np.exp(-((X0-X)**2)/(2*sigma**2))
#n = 50
#spacing = len(redshifts)/n
#smoothzs = [np.mean(redshifts[(spacing*x):(spacing*x)+spacing]) for x in range(0, n)]
#smoothrhos = [np.mean(rhos[(spacing*x):(spacing*x)+spacing]) for x in range(0, n)]
smoothrhos = np.zeros(len(rhos))
for i in range(0, len(rhos)):
sum1 = 0
sum2 = 0
for j in range(max(0,i-100), min(len(rhos)-1,i+100)):
k = kernel(redshifts[i], redshifts[j])
sum1 += k*rhos[j]
sum2 += k
smoothrhos[i] = sum1/sum2
print smoothrhos
plt.plot(redshifts, rhos)
plt.plot(redshifts, smoothrhos)
plt.savefig('smoothing.png')