-
Notifications
You must be signed in to change notification settings - Fork 0
/
power_spectrum.py
181 lines (159 loc) · 9.32 KB
/
power_spectrum.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import numpy as np
from scipy import special
from scipy import interpolate
from numpy import trapz
class foregrounds:
def __init__(
self,
shot_correlations,
color_corr,
calibration,
ell,
mh,
redshift,
instance_HOD,
instance_200,
dV_dz,
shot_noise,
emission
):
self.shot_correlations = shot_correlations
self.color_corr = color_corr
self.calibration = calibration
self.ell = ell
self.mass = mh
self.redshift = redshift
self.instance_HOD = instance_HOD
self.instance_200 = instance_200
self.dV_dz = dV_dz
self.shot_noise = shot_noise
self.emission = emission
def halo_terms_CIB_addison(self):
#compute the conversion factors
cf_cib = []
for nu, i in enumerate(self.emission.unit):
if i=='muK^2':
cf_cib.append(1 /self.emission.dBdT_num_dust[nu])
else:
cf_cib.append(1.0)
cf_cib = np.array(cf_cib)
# define the initial
intmass_2h_EP = np.zeros([len(self.instance_200.kh), len(self.redshift), len(self.mass)])
intmass_1h_EP = np.zeros([len(self.instance_200.kh), len(self.redshift), len(self.mass)])
intmass_2h_LP = np.zeros([len(self.instance_200.kh), len(self.redshift), len(self.mass)])
intmass_1h_LP = np.zeros([len(self.instance_200.kh), len(self.redshift), len(self.mass)])
intmass_1h_mix = np.zeros([len(self.instance_200.kh), len(self.redshift), len(self.mass)])
intred_2h_EP = np.zeros([len(self.instance_200.kh), len(self.redshift)])
intred_1h_EP = np.zeros([len(self.instance_200.kh), len(self.redshift)])
intred_2h_LP = np.zeros([len(self.instance_200.kh), len(self.redshift)])
intred_1h_LP = np.zeros([len(self.instance_200.kh), len(self.redshift)])
intred_1h_mix = np.zeros([len(self.instance_200.kh), len(self.redshift)])
intred_2h_mix = np.zeros([len(self.instance_200.kh), len(self.redshift)])
Cl_2h_EP = np.zeros([self.emission.n_spec, len(self.instance_200.kh)])
Cl_1h_EP = np.zeros([self.emission.n_spec, len(self.instance_200.kh)])
Cl_2h_LP = np.zeros([self.emission.n_spec, len(self.instance_200.kh)])
Cl_1h_LP = np.zeros([self.emission.n_spec, len(self.instance_200.kh)])
Cl_2h_mix = np.zeros([self.emission.n_spec, len(self.instance_200.kh)])
Cl_1h_mix = np.zeros([self.emission.n_spec, len(self.instance_200.kh)])
# compute the one and two halo terms
minred = 5 # lower limit on redshift as in Addison 2012 (z>0.25)
spec = 0
for nu1 in range(self.emission.n_nu):
for nu2 in range(nu1, self.emission.n_nu):
emission_EP = ( self.emission.j_nu_EP_step[nu1] * self.emission.j_nu_EP_step[nu2]) * 1.0 / (self.instance_HOD.ngal_EP_200c * self.dV_dz) ** 2
emission_LP = ( self.emission.j_nu_LP_step[nu1] * self.emission.j_nu_LP_step[nu2]) * 1.0 / (self.instance_HOD.ngal_LP_200c * self.dV_dz) ** 2
emission_mix = ( self.emission.j_nu_EP_step[nu1]*self.emission.j_nu_LP_step[nu2] + self.emission.j_nu_EP_step[nu2]*self.emission.j_nu_LP_step[nu1]) * 1.0 / (self.instance_HOD.ngal_EP_200c * self.instance_HOD.ngal_LP_200c * self.dV_dz**2)
for k in range(len(self.instance_200.kh)):
intmass_2h_EP[k, :, :] = (
self.instance_200.dndM
* self.instance_200.bias_cib
* self.instance_HOD.Nbra_EP[np.newaxis, :]
* self.instance_200.u_c[:, :, k]
)
intmass_1h_EP[k, :, :] = self.instance_200.dndM * (
2
* self.instance_HOD.Ncent_EP[np.newaxis, :]
* self.instance_HOD.Nsat_EP[np.newaxis, :]
* self.instance_200.u_c[:, :, k]
+ self.instance_HOD.Nsat_EP[np.newaxis, :] ** 2 * self.instance_200.u_c[:, :, k] ** 2
)
intmass_2h_LP[k, :, :] = (
self.instance_200.dndM
* self.instance_200.bias_cib
* self.instance_HOD.Nbra_LP[np.newaxis, :]
* self.instance_200.u_c[:, :, k]
)
intmass_1h_LP[k, :, :] = self.instance_200.dndM * (
2
* self.instance_HOD.Ncent_LP[np.newaxis, :]
* self.instance_HOD.Nsat_LP[np.newaxis, :]
* self.instance_200.u_c[:, :, k]
+ self.instance_HOD.Nsat_LP[np.newaxis, :] ** 2 * self.instance_200.u_c[:, :, k] ** 2
)
intmass_1h_mix[k,:,:] = self.instance_200.dndM * (((
self.instance_HOD.Ncent_EP[np.newaxis, :]
* self.instance_HOD.Nsat_LP[np.newaxis, :] +
self.instance_HOD.Ncent_LP[np.newaxis,:]
* self.instance_HOD.Nsat_EP[np.newaxis,:])
* self.instance_200.u_c[:, :, k]
+ self.instance_HOD.Nsat_EP[np.newaxis, :] * self.instance_HOD.Nsat_LP[np.newaxis,:] * self.instance_200.u_c[:, :, k] ** 2 )
)
intred_2h_EP[k, :] = (
self.dV_dz
* self.instance_200.Pk[:, k]
* (trapz(intmass_2h_EP[k, :, :], self.mass, axis=-1)) ** 2
)
intred_1h_EP[k, :] = self.dV_dz * trapz(
intmass_1h_EP[k, :, :], self.mass, axis=-1
)
intred_2h_LP[k, :] = (
self.dV_dz
* self.instance_200.Pk[:, k]
* (trapz(intmass_2h_LP[k, :, :], self.mass, axis=-1)) ** 2
)
intred_1h_LP[k, :] = self.dV_dz * trapz(
intmass_1h_LP[k, :, :], self.mass, axis=-1
)
intred_1h_mix[k, :] = self.dV_dz * trapz(intmass_1h_mix[k, :, :], self.mass, axis=-1)
intred_2h_mix[k, :] = self.dV_dz * self.instance_200.Pk[:, k] * trapz(intmass_2h_EP[k, :, :], self.mass, axis=-1) * trapz(intmass_2h_LP[k, :, :], self.mass, axis=-1)
Cl_2h_EP[spec, k] = trapz(
emission_EP[minred:] * intred_2h_EP[k, minred:],
self.redshift[minred:],
) * cf_cib[nu1] * cf_cib[nu2] * np.sqrt(self.calibration[nu1] * self.calibration[nu2]) * self.color_corr[nu1] * self.color_corr[nu2]
Cl_1h_EP[spec, k] = trapz(
emission_EP[minred:] * intred_1h_EP[k, minred:],
self.redshift[minred:],
) * cf_cib[nu1] * cf_cib[nu2] * np.sqrt(self.calibration[nu1] * self.calibration[nu2]) * self.color_corr[nu1] * self.color_corr[nu2]
Cl_2h_LP[spec, k] = trapz(
emission_LP[minred:] * intred_2h_LP[k, minred:],
self.redshift[minred:],
) * cf_cib[nu1] * cf_cib[nu2] * np.sqrt(self.calibration[nu1] * self.calibration[nu2]) * self.color_corr[nu1] * self.color_corr[nu2]
Cl_1h_LP[spec, k] = trapz(
emission_LP[minred:] * intred_1h_LP[k, minred:],
self.redshift[minred:],
) * cf_cib[nu1] * cf_cib[nu2] * np.sqrt(self.calibration[nu1] * self.calibration[nu2]) * self.color_corr[nu1] * self.color_corr[nu2]
Cl_2h_mix[spec, k] = trapz(
emission_mix[minred:] * intred_2h_mix[k,minred],
self.redshift[minred:],
) * cf_cib[nu1] * cf_cib[nu2] * np.sqrt(self.calibration[nu1] * self.calibration[nu2]) * self.color_corr[nu1] * self.color_corr[nu2]
Cl_1h_mix[spec, k] = trapz(
emission_mix[minred:] * intred_1h_mix[k,minred],
self.redshift[minred:],
) * cf_cib[nu1] * cf_cib[nu2] * np.sqrt(self.calibration[nu1] * self.calibration[nu2]) * self.color_corr[nu1] * self.color_corr[nu2]
spec = spec + 1
return Cl_1h_EP, Cl_2h_EP, Cl_1h_LP, Cl_2h_LP, Cl_1h_mix, Cl_2h_mix
def CIB_poisson(self):
cf_cib = []
for nu, i in enumerate(self.emission.unit):
if i=='muK^2':
cf_cib.append(1 /self.emission.dBdT_num_dust[nu])
else:
cf_cib.append(1.0)
cf_cib = np.array(cf_cib)
cl_cibp = np.zeros([self.emission.n_spec, len(self.ell)])
spec = 0
for nu1 in range(self.emission.n_nu):
for nu2 in range(nu1, self.emission.n_nu):
cl_cibp[spec, :] = cf_cib[nu1] * cf_cib[nu2] * self.shot_correlations[nu1, nu2] * np.sqrt(self.shot_noise[nu1] * self.shot_noise[nu2]) * np.sqrt(self.calibration[nu1] * self.calibration[nu2]) * self.color_corr[nu1] * self.color_corr[nu2]
spec = spec + 1
return cl_cibp