-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmw.py
91 lines (76 loc) · 2.39 KB
/
mw.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
import healpy as hp
from pys2let import *
import math
import matplotlib.pyplot as plt
import os
import numpy as np
L = 32
spin = 0
# fname = '/Users/bl/Dropbox/Astrodata/SDSS/Fields/Planck_EBV_256rQ.fits'
fname = os.path.join(
os.path.dirname(__file__),
os.pardir,
os.pardir,
os.pardir,
"data",
"somecmbsimu_hpx_128.fits",
)
# Read healpix map and compute alms.
# f_lm has size L*(L+1)/2
f_hpx = hp.read_map(fname) # Initial map
f_lm = hp.map2alm(f_hpx, lmax=L - 1) # Its alms
# Convert to MW sampling from spherical harmonics
f_mw = alm2map_mw(f_lm, L, spin)
f_lm_rec = map2alm_mw(f_mw, L, spin)
f_mw_rec = alm2map_mw(f_lm, L, spin)
Lpix = 3 * L
f_mw = alm2map_mw(f_lm, L, spin)
f_lm_rec = map2alm_mw(f_mw, L, spin)
f_mw_rec = alm2map_mw(f_lm, L, spin)
def zeropad(flm, Lin, Lout):
f_lm_out = np.zeros(
[
int(Lout * (Lout + 1) / 2),
],
dtype=complex,
)
for el in range(Lin):
for em in range(el + 1):
f_lm_out[healpy_lm(el, em, Lout)] = f_lm[healpy_lm(el, em, Lin)]
return f_lm_out
f_lm_ext = zeropad(f_lm, L, Lpix)
f_mw_ext = alm2map_mw(f_lm_ext, Lpix, spin)
# f_mw_ext2 = alm2map_mw_bl(f_lm, 0, L, Lpix, spin)
# f_lm_ext2 = map2alm_mw_bl(f_mw_ext2, 0, L, Lpix, spin)
# f_mw_rec2 = alm2map_mw(f_lm_ext2, L, spin)
# Home made plotting routine! inputs : function f (1D array of MW signal), bandlimit L, plot axis ax, and title
def myplot(f, L, ax, title=""):
# Compute the theta and phi values of the MW equiangular grid.
thetas, phis = mw_sampling(L)
ntheta = len(thetas)
nphi = len(phis)
arr = f.reshape((ntheta, nphi))
ax.imshow(arr.real, vmin=0, vmax=1)
if L > 10:
step_phi = int(L / 4)
step_theta = int(L / 4)
else:
step_phi = 3
step_theta = 3
selec = np.arange(0, nphi, step_phi) # subset of phi tick labels
ax.set_xticks(selec)
ax.set_xticklabels(["%.1f" % x for x in phis[selec]])
ax.set_xlabel(r"$\phi$")
selec = np.arange(0, ntheta, step_theta) # subset of theta tick labels
ax.set_yticks(selec)
ax.set_yticklabels(["%.1f" % x for x in thetas[selec]])
ax.set_ylabel(r"$\theta$")
ax.set_title(title)
# Plot equiangular map
fig, axs = plt.subplots(1, 2)
axs = axs.ravel()
myplot(f_mw, L, axs[0], "L")
myplot(f_mw_ext, Lpix, axs[1], "Lpix")
# myplot(f_mw_ext2, Lpix, axs[2], 'Lpix')
# myplot(f_mw_rec2, L, axs[3], 'L')
plt.show()