-
Notifications
You must be signed in to change notification settings - Fork 0
/
mean.py
84 lines (59 loc) · 2.95 KB
/
mean.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import numpy as np
import sys,os
root = '/home/landerson/src/LyA-InvertPhase/20Mpc_256/'
################################## INPUT #######################################
realizations = 50
redshifts = [2,3,4]
prefix = 'Pk_cdm' #'MF','Pk'
################################################################################
fout_folder = root+'/mean/'
if not(os.path.exists(fout_folder)): os.system('mkdir '+fout_folder)
for z in redshifts:
Pk,Pk_NCV = [], []
for i in xrange(realizations):
k, Pk_real = np.loadtxt(root+'%d/%s_z=%d.txt'%(i,prefix,z),
unpack=True)
Pk.append(Pk_real)
k, Pk_real1 = np.loadtxt(root+'NCV_0_%d/%s_z=%d.txt'%(i,prefix,z),
unpack=True)
k, Pk_real2 = np.loadtxt(root+'NCV_1_%d/%s_z=%d.txt'%(i,prefix,z),
unpack=True)
Pk_NCV.append(0.5*(Pk_real1 + Pk_real2))
Pk = np.array(Pk); Pk_NCV = np.array(Pk_NCV)
f = open(fout_folder+'%s_mean_z=%d.txt'%(prefix,z), 'w')
g = open(fout_folder+'%s_mean_NCV_z=%d.txt'%(prefix,z), 'w')
for j in xrange(k.shape[0]):
f.write(str(k[j])+' '+str(np.mean(Pk[:,j]))+' '+str(np.std(Pk[:,j]))+\
'\n')
g.write(str(k[j])+' '+str(np.mean(Pk_NCV[:,j]))+' '+str(np.std(Pk_NCV[:,j]))+\
'\n')
f.close(); g.close()
root = '/home/landerson/src/LyA-InvertPhase/40Mpc_512/'
################################## INPUT #######################################
realizations = 50
redshifts = [2,3,4]
prefix = 'Pk_cdm' #'MF','Pk'
################################################################################
fout_folder = root+'/mean/'
if not(os.path.exists(fout_folder)): os.system('mkdir '+fout_folder)
for z in redshifts:
Pk,Pk_NCV = [], []
for i in xrange(realizations):
k, Pk_real = np.loadtxt(root+'%d/%s_z=%d.txt'%(i,prefix,z),
unpack=True)
Pk.append(Pk_real)
if i < 25:
k, Pk_real1 = np.loadtxt(root+'NCV_0_%d/%s_z=%d.txt'%(i,prefix,z),
unpack=True)
k, Pk_real2 = np.loadtxt(root+'NCV_1_%d/%s_z=%d.txt'%(i,prefix,z),
unpack=True)
Pk_NCV.append(0.5*(Pk_real1 + Pk_real2))
Pk = np.array(Pk); Pk_NCV = np.array(Pk_NCV)
f = open(fout_folder+'%s_mean_z=%d.txt'%(prefix,z), 'w')
g = open(fout_folder+'%s_mean_NCV_z=%d.txt'%(prefix,z), 'w')
for j in xrange(k.shape[0]):
f.write(str(k[j])+' '+str(np.mean(Pk[:,j]))+' '+str(np.std(Pk[:,j]))+\
'\n')
g.write(str(k[j])+' '+str(np.mean(Pk_NCV[:,j]))+' '+str(np.std(Pk_NCV[:,j]))+\
'\n')
f.close(); g.close()