-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBNT_cosmosis.py
111 lines (78 loc) · 3.6 KB
/
BNT_cosmosis.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
import numpy as np
from cosmosis.datablock import names, option_section
from BNT import BNT
from math import pi as pi
def setup(options):
BNT_path = options.get(option_section, 'BNT_path')
run_mode = options.get(option_section, 'run_mode')
BNT_matrix = np.loadtxt(BNT_path)
return BNT_matrix, run_mode
def execute(block, config):
BNT_matrix, run_mode = config
nbins = BNT_matrix.shape[0]
#k-cut in harmonic space
if run_mode == 'harmonic':
#load and format data from the bloc
ell = block['shear_cl', 'ell']
ell_shape = ell.shape[0]
cl_data = np.zeros((nbins, nbins, ell_shape))
for i in range(nbins):
for j in range(nbins):
if i >= j:
cl_data[i,j,:] = block['shear_cl', 'bin_%s_%s' %(i+1, j+1)]
cl_data[j,i,:] = cl_data[i,j,:]
#make the BNT transformation
cl_data_new = np.zeros((nbins, nbins, ell_shape))
for l in range(ell_shape):
cl_data_new[:,:,l] = np.dot(np.dot(BNT_matrix, cl_data[:,:,l]), BNT_matrix.T)
#save back to the block
for i in range(nbins):
for j in range(nbins):
if i >= j:
block['shear_cl', 'bin_%s_%s' %(i+1, j+1)] = cl_data_new[i,j,:]
#x-cut in configuration space
elif run_mode == 'configuration':
#load and format data from the bloc
try:
fmat = 'new'
theta = block['shear_xi_plus', 'theta']
except:
fmat = 'old'
theta = block['shear_xi', 'theta']
theta_shape = theta.shape[0]
xi_p_data = np.zeros((nbins, nbins, theta_shape))
xi_m_data = np.zeros((nbins, nbins, theta_shape))
xi_p_data_new = np.zeros((nbins, nbins, theta_shape))
xi_m_data_new = np.zeros((nbins, nbins, theta_shape))
for i in range(nbins):
for j in range(nbins):
if i >= j:
if fmat == 'new':
xi_p_data[i,j,:] = block['shear_xi_plus', 'bin_%s_%s' %(i+1, j+1)]
xi_p_data[j,i,:] = xi_p_data[i,j,:]
xi_m_data[i,j,:] = block['shear_xi_minus', 'bin_%s_%s' %(i+1, j+1)]
xi_m_data[j,i,:] = xi_m_data[i,j,:]
elif fmat == 'old':
xi_p_data[i,j,:] = block['shear_xi', 'xiplus_%s_%s' %(i+1, j+1)]
xi_p_data[j,i,:] = xi_p_data[i,j,:]
xi_m_data[i,j,:] = block['shear_xi', 'ximinus_%s_%s' %(i+1, j+1)]
xi_m_data[j,i,:] = xi_m_data[i,j,:]
#make the BNT transformation and cut
for t in range(theta_shape):
xi_p_data_new[:,:,t] = np.dot(np.dot(BNT_matrix, xi_p_data[:,:,t]), BNT_matrix.T)
xi_m_data_new[:,:,t] = np.dot(np.dot(BNT_matrix, xi_m_data[:,:,t]), BNT_matrix.T)
#save back to the block
for i in range(nbins):
for j in range(nbins):
if i >= j:
if fmat == 'new':
block['shear_xi_plus', 'bin_%s_%s' %(i+1, j+1)] = xi_p_data_new[i,j,:]
block['shear_xi_minus', 'bin_%s_%s' %(i+1, j+1)] = xi_m_data_new[i,j,:]
elif fmat == 'old':
block['shear_xi', 'xiplus_%s_%s' %(i+1, j+1)] = xi_p_data_new[i,j,:]
block['shear_xi', 'ximinus_%s_%s' %(i+1, j+1)] = xi_m_data_new[i,j,:]
else:
print ('run-mode must be either harmonic or configuration')
return 0.
def cleanup(config):
return 0.