-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxi.py
More file actions
180 lines (129 loc) · 5.5 KB
/
Copy pathxi.py
File metadata and controls
180 lines (129 loc) · 5.5 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import numpy as np
import treecorr
import sys
from scipy.signal import savgol_filter
import Corrfunc
from Corrfunc.io import read_catalog
from Corrfunc.theory.xi import xi
def read_halo_catalogue(model_no, step_no, bin_no):
mass_cut = np.arange(13.0,15.0,0.1)
filename = "/Users/jkwan/emulators/TitanU/xi/M{:0>3d}/STEP{:3d}/halo_catalogue_M{:0>3d}_L2100_sod_0.4985_{:4.2f}.dat".format(int(model_no), int(step_no), int(model_no), mass_cut[int(bin_no)])
x,y,z = np.loadtxt(filename).T
print(filename)
# x,y,z,npart = np.loadtxt('/Users/jkwan/emulators/TitanU/halo_power/M026/halo_catalogue_M026_L2100_fof_1.0000_9.dat').T
#Only take a subsample
if (x.size > 1e8):
index = np.random.randint(x.size, size=int(0.1*x.size))
x_sub = x[index]
y_sub = y[index]
z_sub = z[index]
x = x_sub
y = y_sub
z = z_sub
return x,y,z
def read_matter_particles(model_no, step_no, sub):
filename="/Users/jkwan/emulators/TitanU/density/M{:0>3}/STEP{:3}/particle_subsample_M{:0>3}_L2100_1.0000_0.dat".format(model_no, step_no, model_no)
p = np.fromfile(filename,dtype='f')
p_new = np.reshape(p,(p.size/6,6))
# there are 6 fields for struct particle_data
x_m = p_new[:,0]
y_m = p_new[:,1]
z_m = p_new[:,2]
# the rest are velocities
#Only take a subsample
if (sub):
# x_sub = x_m[(x_m < 0.5) & (y_m < 0.5) & (z_m < 0.5)]
# y_sub = y_m[(x_m < 0.5) & (y_m < 0.5) & (z_m < 0.5)]
# z_sub = z_m[(x_m < 0.5) & (y_m < 0.5) & (z_m < 0.5)]
index = np.random.randint(x_m.size, size=int(0.1*x_m.size))
x_sub = x_m[index]
y_sub = y_m[index]
z_sub = z_m[index]
x_m = x_sub
y_m = y_sub
z_m = z_sub
return x_m, y_m, z_m
def setup_treecorr():
max_size = 100000
x_r = np.random.rand(10*max_size) # randoms
y_r = np.random.rand(10*max_size)
z_r = np.random.rand(10*max_size)
cat_r = treecorr.Catalog(x=x_r,y=y_r,z=z_r)
dd = treecorr.NNCorrelation(nbins=20,min_sep=0.001,max_sep=0.1,bin_slop=0.05)
dr = treecorr.NNCorrelation(nbins=20,min_sep=0.001,max_sep=0.1,bin_slop=0.05)
rr = treecorr.NNCorrelation(nbins=20,min_sep=0.001,max_sep=0.1,bin_slop=0.05)
rr.process(cat_r)
return cat_r, dd, dr, rr
if __name__ == "__main__":
model_no = sys.argv[1]
step_no = sys.argv[2]
nthreads = 2
jk_no = 2
mass_cut = np.arange(13.0,15.0,0.1)
rmin = 1.
rmax = 200.
rbins = 20
BoxSize = 2100.
log_rbins = np.logspace(np.log10(rmin),np.log10(rmax),rbins+1)
#These are things that stay the same with every run
cat_r, dd, dr, rr = setup_treecorr()
nbins = 16
for bin_no in range(4,5):
x,y,z = read_halo_catalogue(model_no, step_no, bin_no)
# x,y,z = read_matter_particles(model_no, step_no,False)
#Divide sim into 1/8 cubes
if jk_no == 0:
indices = np.where((x < 0.5) & (y < 0.5) & (z < 0.5))
x_sub = x[indices[0]]
y_sub = y[indices[0]]
z_sub = z[indices[0]]
if jk_no == 1:
indices = np.where((x < 0.5) & (y < 0.5) & (z > 0.5))
x_sub = x[indices[0]]
y_sub = y[indices[0]]
z_sub = z[indices[0]]-0.5 # Recenter the subcube. This has to change depending on the subsample taken
if jk_no == 2:
indices = np.where((x < 0.5) & (y > 0.5) & (z < 0.5))
x_sub = x[indices[0]]
y_sub = y[indices[0]]-0.5
z_sub = z[indices[0]]
if jk_no == 3:
indices = np.where((x < 0.5) & (y > 0.5) & (z > 0.5))
x_sub = x[indices[0]]
y_sub = y[indices[0]]-0.5
z_sub = z[indices[0]]-0.5
if jk_no == 4:
indices = np.where((x > 0.5) & (y < 0.5) & (z < 0.5))
x_sub = x[indices[0]]-0.5
y_sub = y[indices[0]]
z_sub = z[indices[0]]
if jk_no == 5:
indices = np.where((x > 0.5) & (y < 0.5) & (z > 0.5))
x_sub = x[indices[0]]-0.5
y_sub = y[indices[0]]
z_sub = z[indices[0]]-0.5
if jk_no == 6:
indices = np.where((x > 0.5) & (y > 0.5) & (z < 0.5))
x_sub = x[indices[0]]-0.5
y_sub = y[indices[0]]-0.5
z_sub = z[indices[0]]
if jk_no == 7:
indices = np.where((x > 0.5) & (y > 0.5) & (z > 0.5))
x_sub = x[indices[0]]-0.5
y_sub = y[indices[0]]-0.5
z_sub = z[indices[0]]-0.5
x_sub *= BoxSize
y_sub *= BoxSize
z_sub *= BoxSize
# cat = treecorr.Catalog(x=x,y=y,z=z)
#units are arcmin by default, but pretend MPc
# dd.process(cat)
# dr.process(cat,cat_r)
# xi,varxi = dd.calculateXi(rr,dr)
# xi_smooth = savgol_filter(xi, 11, 5)
# r = np.exp(dd.logr)
results = xi(0.5*BoxSize, nthreads, log_rbins, x_sub,y_sub,z_sub,output_ravg=True)
output_filename = "/Users/jkwan/emulators/TitanU/xi/M{:0>3}/STEP{:3}/xi_M{:0>3}_L2100_sod_0.4985_{:4.2f}_test.{}.dat".format(model_no, step_no, model_no, mass_cut[int(bin_no)],jk_no)
# output_filename = "/Users/jkwan/emulators/TitanU/xi/M{:0>3}/STEP{:3}/xi_mm_M{:0>3}_L5000_1.0000_test.dat".format(model_no, step_no, model_no)
# np.savetxt(output_filename, np.column_stack([r*BoxSize, xi]))
np.savetxt(output_filename, np.column_stack([results['ravg'], results['xi'], results['npairs']]))