-
Notifications
You must be signed in to change notification settings - Fork 0
/
spectrum.py
50 lines (36 loc) · 1.26 KB
/
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
import pymaster as nmt
from utils import timer
NSIDE = 512
NPIX = 12 * NSIDE * NSIDE
@timer
def get_mask_apo(hits_map, min_hits: int, aposize: float):
# Define the mask by cutting above a hit threshold
mask = hits_map > min_hits
# Apodize the mask
mask = nmt.mask_apodization(mask, aposize, apotype="C1")
return mask
def get_binning(delta_ell: int):
# Initialize binning scheme
b = nmt.NmtBin.from_nside_linear(NSIDE, delta_ell)
return b
def compute_spectra(m, mask_apo, binning):
# Check input shape
iqu = m.shape[0] == 3
if iqu:
# Initialize a spin-0 and spin-2 field
f_0 = nmt.NmtField(mask_apo, [m[0]])
f_2 = nmt.NmtField(mask_apo, m[1:])
# Compute MASTER estimator
# spin-0 x spin-0
cl_00 = nmt.compute_full_master(f_0, f_0, binning)
# spin-0 x spin-2
cl_02 = nmt.compute_full_master(f_0, f_2, binning)
# spin-2 x spin-2
cl_22 = nmt.compute_full_master(f_2, f_2, binning)
return {"cl_00": cl_00, "cl_02": cl_02, "cl_22": cl_22}
else:
# Assume we only have Q and U maps
f_2 = nmt.NmtField(mask_apo, m)
# spin-2 x spin-2
cl_22 = nmt.compute_full_master(f_2, f_2, binning)
return {"cl_22": cl_22}