|
| 1 | +""" |
| 2 | +Read the Planck beam files and save the beam as tables in .dat files. |
| 3 | +both the intensity, the polarisation and the leakage beam files |
| 4 | +""" |
| 5 | + |
| 6 | +import sys |
| 7 | + |
| 8 | +import numpy as np |
| 9 | +import pylab as plt |
| 10 | +import healpy as hp |
| 11 | +from astropy.io import fits |
| 12 | +from pspy import pspy_utils, so_dict |
| 13 | +from pspipe_utils import log |
| 14 | + |
| 15 | +d = so_dict.so_dict() |
| 16 | +d.read_from_file(sys.argv[1]) |
| 17 | +log = log.get_logger(**d) |
| 18 | + |
| 19 | +planck_fits_beam_path = d["planck_fits_beam_path"] |
| 20 | +beam_dir_d = d["beam_dir"] |
| 21 | + |
| 22 | +freqs = [100, 143, 217, 353] |
| 23 | +lmax = 3030 |
| 24 | +lmax_for_plot = 2000 |
| 25 | +releases = ["legacy", "npipe_DR6_AxB"] |
| 26 | + |
| 27 | +for release in releases: |
| 28 | + |
| 29 | + beam_dir = beam_dir_d + f"/{release}" |
| 30 | + pspy_utils.create_directory(beam_dir) |
| 31 | + |
| 32 | + for freq in freqs: |
| 33 | + |
| 34 | + if release == "npipe_DR6_AxB": |
| 35 | + s1, s2 = "A", "B" |
| 36 | + if freq != 353: |
| 37 | + Wl = fits.open(f"{planck_fits_beam_path}/QP_dr6_pa6_f150/Wl_npipe6v20_{freq}{s1}x{freq}{s2}.fits") |
| 38 | + else: |
| 39 | + print(f"use full sky beam for {freq} GHz") |
| 40 | + Wl = fits.open(f"{planck_fits_beam_path}/quickpol/Wl_npipe6v20_{freq}{s1}x{freq}{s2}.fits") |
| 41 | + |
| 42 | + if release == "legacy": |
| 43 | + s1, s2 = "hm1", "hm2" |
| 44 | + if freq != 353: |
| 45 | + Wl = fits.open(f"{planck_fits_beam_path}/BeamWf_HFI_R3.01/Wl_R3.01_plikmask_{freq}{s1}x{freq}{s2}.fits") |
| 46 | + else: |
| 47 | + print(f"use full sky beam for {freq} GHz") |
| 48 | + Wl = fits.open(f"{planck_fits_beam_path}/BeamWf_HFI_R3.01/Wl_R3.01_fullsky_{freq}{s1}x{freq}{s2}.fits") |
| 49 | + |
| 50 | + l = np.arange(lmax) |
| 51 | + |
| 52 | + Wl_TT_2_TT = Wl[1].data["TT_2_TT"][0, :lmax] |
| 53 | + Wl_EE_2_EE = Wl[2].data["EE_2_EE"][0, :lmax] |
| 54 | + |
| 55 | + # extract beam and polarised beam |
| 56 | + bl_T = np.sqrt(Wl_TT_2_TT) |
| 57 | + bl_pol = np.sqrt(Wl_EE_2_EE) |
| 58 | + |
| 59 | + plt.figure(figsize=(12,8)) |
| 60 | + plt.subplot(2, 1, 1) |
| 61 | + plt.plot(l[:lmax_for_plot], bl_T[:lmax_for_plot], label="temperature beam", color="lightblue") |
| 62 | + plt.errorbar(l[:lmax_for_plot], bl_pol[:lmax_for_plot], fmt="+", markevery=50, label="pol beam", color="red") |
| 63 | + plt.ylabel(r"$ B_{\ell}$", fontsize=14) |
| 64 | + plt.legend() |
| 65 | + plt.subplot(2, 1, 2) |
| 66 | + plt.plot(l[:lmax_for_plot], (bl_T[:lmax_for_plot] / bl_pol[:lmax_for_plot]) ** 2) |
| 67 | + plt.ylabel(r"$ (B^{\rm T}_{\ell}/B^{\rm pol}_{\ell})^{2} $", fontsize=14) |
| 68 | + plt.xlabel(r"$\ell$", fontsize=14) |
| 69 | + plt.savefig(f"{beam_dir}/beam_{freq}.png") |
| 70 | + plt.clf() |
| 71 | + plt.close() |
| 72 | + |
| 73 | + np.savetxt(f"{beam_dir}/bl_T_{release}_{freq}{s1}x{freq}{s2}.dat", np.transpose([l, bl_T])) |
| 74 | + np.savetxt(f"{beam_dir}/bl_pol_{release}_{freq}{s1}x{freq}{s2}.dat", np.transpose([l, bl_pol])) |
| 75 | + |
| 76 | + # extract leakage beam |
| 77 | + Wl_TE_2_TE = Wl[4].data["TE_2_TE"][0, :lmax] |
| 78 | + gamma_TE = Wl[1].data["TT_2_TE"][0, :lmax] / Wl_TE_2_TE |
| 79 | + gamma_ET = Wl[1].data["TT_2_ET"][0, :lmax] / Wl_TE_2_TE |
| 80 | + |
| 81 | + gamma_TB = Wl[1].data["TT_2_TB"][0, :lmax] / Wl_TE_2_TE |
| 82 | + gamma_BT = Wl[1].data["TT_2_BT"][0, :lmax] / Wl_TE_2_TE |
| 83 | + |
| 84 | + plt.figure(figsize=(12,8)) |
| 85 | + plt.title(f"{freq} GHz x {freq} GHz", fontsize=14) |
| 86 | + plt.errorbar(l[:lmax_for_plot], 100 * gamma_TE[:lmax_for_plot], label=r"%s $T_{\rm %s} \ x \ E_{\rm %s}$" % (release, s1, s2), color="blue", fmt="-", markevery=50) |
| 87 | + plt.errorbar(l[:lmax_for_plot], 100 * gamma_ET[:lmax_for_plot], label=r"%s $T_{\rm %s} \ x \ E_{\rm %s}$" % (release, s2, s1), color="navy", fmt="+", markevery=50) |
| 88 | + plt.errorbar(l[:lmax_for_plot], 100 * (gamma_TE[:lmax_for_plot] + gamma_ET[:lmax_for_plot]) / 2, label=r"%s $T \ x \ E$" % (release), color="black", fmt="--", markevery=50) |
| 89 | + |
| 90 | + plt.errorbar(l[:lmax_for_plot], 100 * gamma_TB[:lmax_for_plot], label=r"%s $T_{\rm %s} \ x \ B_{\rm %s}$" % (release, s1, s2), color="red", fmt="-.", markevery=50) |
| 91 | + plt.errorbar(l[:lmax_for_plot], 100 * gamma_BT[:lmax_for_plot], label=r"%s $T_{\rm %s} \ x \ B_{\rm %s}$" % (release, s2, s1), color="orange", fmt="*", markevery=50) |
| 92 | + plt.errorbar(l[:lmax_for_plot], 100 * (gamma_TB[:lmax_for_plot] + gamma_BT[:lmax_for_plot]) / 2, label=r"%s $T \ x \ B$" % (release), color="gray", fmt="--", markevery=50) |
| 93 | + |
| 94 | + plt.ylim(-0.8, 0.8) |
| 95 | + plt.ylabel(r"$ \gamma_{\ell}$", fontsize=14) |
| 96 | + plt.legend() |
| 97 | + plt.xlabel(r"$\ell$", fontsize=14) |
| 98 | + plt.savefig(f"{beam_dir}/beam_leakage_{freq}.png") |
| 99 | + plt.clf() |
| 100 | + plt.close() |
| 101 | + |
| 102 | + zeros = np.zeros(len(l)) |
| 103 | + |
| 104 | + np.savetxt(f"{beam_dir}/gamma_{release}_{freq}{s2}_t2e.dat", np.transpose([l, gamma_TE, zeros, zeros, zeros])) |
| 105 | + np.savetxt(f"{beam_dir}/gamma_{release}_{freq}{s1}_t2e.dat", np.transpose([l, gamma_ET, zeros, zeros, zeros])) |
| 106 | + |
| 107 | + np.savetxt(f"{beam_dir}/gamma_{release}_{freq}{s2}_t2b.dat", np.transpose([l, gamma_TB, zeros, zeros, zeros])) |
| 108 | + np.savetxt(f"{beam_dir}/gamma_{release}_{freq}{s1}_t2b.dat", np.transpose([l, gamma_BT, zeros, zeros, zeros])) |
| 109 | + |
| 110 | + gamma_mean_TE = (gamma_TE + gamma_ET) / 2 |
| 111 | + gamma_mean_TB = (gamma_TB + gamma_BT) / 2 |
| 112 | + |
| 113 | + np.savetxt(f"{beam_dir}/gamma_mean_{release}_{freq}{s1}{s2}_t2e.dat", np.transpose([l, gamma_mean_TE, zeros, zeros, zeros])) |
| 114 | + np.savetxt(f"{beam_dir}/gamma_mean_{release}_{freq}{s1}{s2}_t2b.dat", np.transpose([l, gamma_mean_TB, zeros, zeros, zeros])) |
| 115 | + |
| 116 | +# these beams will be used for source-sub, they have high ell max |
| 117 | + |
| 118 | +release = "npipe" |
| 119 | +beam_dir = beam_dir_d + f"/{release}" |
| 120 | +pspy_utils.create_directory(beam_dir) |
| 121 | + |
| 122 | + |
| 123 | +pl = hp.pixwin(2048) |
| 124 | + |
| 125 | +for freq in freqs: |
| 126 | + |
| 127 | + Wl_AA = fits.open(f"{planck_fits_beam_path}/quickpol/Wl_npipe6v20_{freq}Ax{freq}A.fits") |
| 128 | + Wl_BB = fits.open(f"{planck_fits_beam_path}/quickpol/Wl_npipe6v20_{freq}Bx{freq}B.fits") |
| 129 | + |
| 130 | + bl_T_A = np.sqrt(Wl_AA[1].data["TT_2_TT"][0, :]) |
| 131 | + bl_T_B = np.sqrt(Wl_BB[1].data["TT_2_TT"][0, :]) |
| 132 | + |
| 133 | + bl_T_coadd = (bl_T_A + bl_T_B) / 2 |
| 134 | + |
| 135 | + bl_T_coadd = bl_T_coadd[:len(pl)] |
| 136 | + bl_T_coadd_pixwin = bl_T_coadd * pl |
| 137 | + |
| 138 | + l = np.arange(len(bl_T_coadd)) |
| 139 | + |
| 140 | + |
| 141 | + np.savetxt(f"{beam_dir}/bl_T_{release}_{freq}_coadd.dat", np.transpose([l, bl_T_coadd])) |
| 142 | + np.savetxt(f"{beam_dir}/bl_T_{release}_{freq}_coadd_pixwin.dat", np.transpose([l, bl_T_coadd_pixwin])) |
| 143 | + |
| 144 | + |
0 commit comments