-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_cosmolike_wrapper_3x2pt.py
126 lines (124 loc) · 3.7 KB
/
run_cosmolike_wrapper_3x2pt.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
import sys
import os.path
import argparse
import yaml
import numpy as np
from run_cosmolike_3x2pt import *
def make_mask(params, MASK):
nl = params['lbins']
ell = np.zeros(nl)
l_min = params['lbounds'][0]
l_max = params['lbounds'][1]
dlgl = (np.log(l_max) - np.log(l_min))/nl
for i in range(0,nl):
lmin = np.exp(np.log(l_min)+i*dlgl)
lmax = np.exp(np.log(l_min)+(i+1)*dlgl)
ell[i] = 2./3.*(lmax*lmax*lmax-lmin*lmin*lmin)/(lmax*lmax-lmin*lmin)
ntomo_source = params['ntomo_source']
ntomo_lens = params['ntomo_lens']
ndata = 0
mask = []
if "xip" in params['twoptnames']:
for i in range(0,ntomo_source):
for j in range(i,ntomo_source):
param = "angle_range_xip_{}_{}".format(i+1,j+1)
tmin, tmax = params[param]
for k in range(0,ntheta):
if ((theta[k] < tmin) | (theta[k] > tmax)):
mask.append(0.)
else:
mask.append(1.)
ndata += 1
else:
for i in range(0,ntomo_source):
for j in range(i,ntomo_source):
for k in range(0,ntheta):
mask.append(0.)
if "xim" in params['twoptnames']:
for i in range(0,ntomo_source):
for j in range(i,ntomo_source):
param = "angle_range_xim_{}_{}".format(i+1,j+1)
tmin, tmax = params[param]
for k in range(0,ntheta):
if ((theta[k] < tmin) | (theta[k] > tmax)):
mask.append(0.)
else:
mask.append(1.)
ndata += 1
else:
for i in range(0,ntomo_source):
for j in range(i,ntomo_source):
for k in range(0,ntheta):
mask.append(0.)
if "gammat" in params['twoptnames']:
for i in range(0,ntomo_lens):
for j in range(0,ntomo_source):
# if ggltomo[i*ntomo_source+j,2]:
param = "angle_range_gammat_{}_{}".format(i+1,j+1)
tmin, tmax = params[param]
for k in range(0,ntheta):
if ((theta[k] < tmin) | (theta[k] > tmax)):
mask.append(0.)
else:
mask.append(1.)
ndata += 1
else:
for i in range(0,ntomo_lens):
for j in range(0,ntomo_source):
#if ggltomo[i*ntomo_source+j,2]:
for k in range(0,ntheta):
mask.append(0.)
if "wtheta" in params['twoptnames']:
for i in range(0,ntomo_lens):
param = "angle_range_wtheta_{}_{}".format(i+1,i+1)
tmin, tmax = params[param]
for k in range(0,ntheta):
if ((theta[k] < tmin) | (theta[k] > tmax)):
mask.append(0.)
else:
mask.append(1.)
ndata += 1
else:
for i in range(0,ntomo_lens):
for k in range(0,ntheta):
mask.append(0.)
params['mask_checksum'] = ndata
if MASK:
f = open(params['mask_file'],"w")
for i in range(0,len(mask)):
f.write("%d %.1f\n"%(i, mask[i]))
f.close()
print("Wrote make_file %s\nEXIT\n"%(params['mask_file']))
exit(1)
#params['new_mask_file'] =maskfile
########## main #######
parser = argparse.ArgumentParser(description='call run_cosmolike_mpp outside the pipeline')
parser.add_argument("parameter_file", help="YAML configuration file")
parser.add_argument('-mask',dest = "mask", action='store_true',help ="create mask file only")
args = parser.parse_args()
try:
param_file = args.parameter_file
print(param_file)
except SystemExit:
sys.exit(1)
load_yaml = 1
try:
params = yaml.load(open(param_file), Loader=yaml.FullLoader)
for sc in params.get("scale_cuts", []):
params.update(yaml.load(open(sc)))
except:
load_yaml = 0
if (not load_yaml):
try:
params = yaml.full_load(open(param_file))
for sc in params.get("scale_cuts", []):
params.update(yaml.full_load(open(sc)))
except:
print("Could not read yaml file\n")
exit(1)
if ((not os.path.isfile(params['mask_file'])) and (not args.mask)):
print("\nmask_file %s doesn't exist!\nRerun \"run_cosmolike_wrapper.py YAML_FILE -mask\" to create mask_file from scale cuts\n"%(params['mask_file']))
exit(1)
# make_mask(params, args.mask)
print("Alive")
run_cosmolike(params)