-
Notifications
You must be signed in to change notification settings - Fork 0
/
020518_ngal_wp_vpf_Pcic_ds_fisher.py
160 lines (112 loc) · 5.56 KB
/
020518_ngal_wp_vpf_Pcic_ds_fisher.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
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
import sys
import argparse
parser = argparse.ArgumentParser(description='#')
parser.add_argument('--Lbox',type=int,required=True,dest='Lbox')
parser.add_argument('--simname',required=True,dest='simname')
parser.add_argument('--version',default='halotools_v0p4',dest='version')
parser.add_argument('--redshift',type=float,default=0.,dest='redshift')
parser.add_argument('--halofinder',default='rockstar',dest='halofinder')
parser.add_argument('--Nparam',type=int,required=True,dest='Nparam')
parser.add_argument('--Nsidejk',type=int,required=True,dest='Nsidejk')
parser.add_argument('--vpfcen',required=True,dest='vpfcen')
parser.add_argument('--ptclpos',required=True,dest='ptclpos')
parser.add_argument('--infile',required=True,dest='infile')
parser.add_argument('--outfile',required=True,dest='outfile')
parser.add_argument('--parallel',type=int,default=55,dest='nproc')
args = parser.parse_args()
import collections
import gc
import numpy as np
from concurrent.futures import ProcessPoolExecutor as Pool
from datetime import datetime
from halotools.sim_manager import CachedHaloCatalog
from HOD_models import decorated_hod_model
from halotools.empirical_models import MockFactory
from halotools.mock_observables import return_xyz_formatted_array
from helpers.CorrelationFunction import ngal_wp_vpf_Pcic_ds_jk
##########################################################
param_names = ('alpha','logM1','sigma_logM','logM0','logMmin','mean_occupation_centrals_assembias_param1','mean_occupation_satellites_assembias_param1')
output_names = ('func_all','func_all_cov','param')
##########################################################
Lbox = args.Lbox
pi_max = 60
r_wp = np.logspace(-1, 1.5, 20)
##wp
r_vpf = np.logspace(0,1.,15)
num_sphere = int(1e5)
vpf_centers = np.loadtxt(args.vpfcen)
##vpf
proj_search_radius = 2.0 ##a cylinder of radius 2 Mpc/h
cylinder_half_length = 10.0 ##half-length 10 Mpc/h
##cic
ptclpos = np.loadtxt(args.ptclpos)
rp_bins_ggl = np.logspace(-1, 1.5, 21)
num_ptcls_to_use = len(ptclpos)
##ggl
##########################################################
def calc_all_observables(param):
model.param_dict.update(dict(zip(param_names, param))) ##update model.param_dict with pairs (param_names:params)
try:
model.mock.populate()
except:
model.populate_mock(halocat)
gc.collect()
output = []
pos_gals_d = return_xyz_formatted_array(*(model.mock.galaxy_table[ax] for ax in 'xyz'), \
velocity=model.mock.galaxy_table['vz'], velocity_distortion_dimension='z',\
period=Lbox) ##redshift space distorted
pos_gals_d = np.array(pos_gals_d,dtype=float)
pos_gals = return_xyz_formatted_array(*(model.mock.galaxy_table[ax] for ax in 'xyz'), period=Lbox)
pos_gals = np.array(pos_gals,dtype=float)
total_num_ptcls_in_snapshot = halocat.num_ptcl_per_dim**3
downsampling_factor = total_num_ptcls_in_snapshot/float(num_ptcls_to_use)
particle_masses = halocat.particle_mass*downsampling_factor
func,funccov = ngal_wp_vpf_Pcic_ds_jk(pos_gals_d, r_wp, pi_max, r_vpf, vpf_centers, proj_search_radius, cylinder_half_length, pos_gals, ptclpos, particle_masses, rp_bins_ggl, Lbox, args.Nsidejk)
output.append(func)
output.append(funccov)
# parameter set
output.append(param)
return output
############################################################
consuelo20_box_list = ['0_4001','0_4002','0_4003','0_4004','0_4020','0_4026','0_4027','0_4028','0_4029','0_4030',\
'0_4032','0_4033','0_4034','0_4035','0_4036','0_4037','0_4038','0_4039','0_4040']
def main(model_gen_func, params_fname, output_fname):
global model
model = model_gen_func()
median_w = np.median(np.loadtxt(params_fname, usecols=range(7)),axis=0)
params = median_w*np.ones((args.Nparam,7)) ##take medians
output_dict = collections.defaultdict(list)
nproc = args.nproc
global halocat
with Pool(nproc) as pool:
if args.simname=='consuelo20' and args.version=='all':
for box in consuelo20_box_list:
halocat = CachedHaloCatalog(simname = args.simname, version_name = box,redshift = args.redshift, \
halo_finder = args.halofinder)
model.populate_mock(halocat)
for i, output_data in enumerate(pool.map(calc_all_observables, params)):
if 1:
print i
print str(datetime.now())
for name, data in zip(output_names, output_data):
output_dict[name].append(data)
print box
else:
halocat = CachedHaloCatalog(simname = args.simname, version_name = args.version,redshift = args.redshift, \
halo_finder = args.halofinder)
model.populate_mock(halocat)
for i, output_data in enumerate(pool.map(calc_all_observables, params)):
if 1:
print i
print str(datetime.now())
for name, data in zip(output_names, output_data):
output_dict[name].append(data)
for name in output_names:
output_dict[name] = np.array(output_dict[name])
np.savez(output_fname, **output_dict)
if __name__ == '__main__':
main(decorated_hod_model, args.infile, args.outfile)
with open(args.outfile+'_log','w') as f:
f.write(sys.argv[0]+'\n')
for arg in vars(args):
f.write(str(arg)+':'+str(getattr(args, arg))+'\n')